From 41af8d12fe6d01f59017f74e4e8a90adb46f47a6 Mon Sep 17 00:00:00 2001 From: katrina Date: Tue, 30 May 2023 10:55:42 -0400 Subject: [PATCH] add image to video script --- README.md | 50 ++++++++++++++++++++++++++------------- library/image-to-video.sh | 25 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 library/image-to-video.sh diff --git a/README.md b/README.md index 9ec2a27..7e90102 100644 --- a/README.md +++ b/README.md @@ -54,19 +54,42 @@ To get started, check out the table of contents below and follow these steps: 1. Check the `assets` directory for the created file +---------------- + ## Table of Contents +- [Convert image to video](#convert-image-to-video) +- [Convert image to WebP](#convert-image-to-webp) - [Convert PDF to video](#convert-pdf-to-mp4) -- [Convert video to GIF](#convert-to-gif) -- [Convert video to MP4](#convert-to-mp4) -- [Convert video or audio to OGG](#convert-to-ogg) -- [Convert video to WebM](#convert-to-webm) -- [Convert image to WebP](#convert-to-webp) +- [Convert video to GIF](#convert-video-to-gif) +- [Convert video to MP4](#convert-video-to-mp4) +- [Convert video or audio to OGG](#convert-video-to-ogg) +- [Convert video to WebM](#convert-video-to-webm) - [Edit two images and/or videos to display next to each other, horizontally](#create-a-horizontal-stack) - [Resize an image](#resize-an-image) - [Extract frames from a video](#extract-frames-from-a-video) - [Modify video speed](#modify-video-speed) +### Convert Image to Video + +This command can encode an image file into an MP4 video file. Pass in the desired frame rate and duration. Frame rate will default to 24 frames per second and duration will default to 10 seconds. + +Usage: + +```bash +sh index.sh image-to-video assets/image.png 24 10 +``` + +### Convert Image to WebP + +This command can encode image files into a WebP file format. + +Usage: + +```bash +sh index.sh webp assets/image.png +``` + ### Convert PDF to MP4 This command allows you to turn a PDF with multiple pages into a slideshow video with an audio track. @@ -77,7 +100,7 @@ Usage: sh index.sh pdf-to-mp4 assets/document.pd4 audio.mp3 ``` -### Convert to GIF +### Convert Video to GIF This command will convert a video file into a GIF file format. @@ -87,7 +110,7 @@ Usage: sh index.sh gif assets/video.mp4 ``` -### Convert to MP4 +### Convert Video to MP4 This command can encode GIF or other video files into an MP4 file format. @@ -97,7 +120,7 @@ Usage: sh index.sh mp4 assets/example.gif ``` -### Convert to OGG +### Convert Video to OGG This command can encode GIF or other video files into an OGG file format. @@ -107,7 +130,7 @@ Usage: sh index.sh ogg assets/example.gif ``` -### Convert to WebM +### Convert Video to WebM This command can encode GIF or other video files into a WebM file format. @@ -117,15 +140,7 @@ Usage: sh index.sh webm assets/example.gif ``` -### Convert to WebP -This command can encode image files into a WebP file format. - -Usage: - -```bash -sh index.sh webp assets/image.png -``` ### Create a Horizontal Stack @@ -174,4 +189,5 @@ sh index.sh modify-video-speed assets/video.mp4 0.5 Feel free to explore these scripts and open any issues if there's something you'd like to see added, or open a pull request to add new scripts. ### Thank you to ⭐star gazers⭐ supporting the project + [![Stargazers repo roster for @golivecosmos/pluto](https://reporoster.com/stars/golivecosmos/pluto)](https://github.com/golivecosmos/pluto/stargazers) diff --git a/library/image-to-video.sh b/library/image-to-video.sh new file mode 100644 index 0000000..9b24f79 --- /dev/null +++ b/library/image-to-video.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Check if the script is called with the correct number of arguments +if [ "$#" -eq 0 ]; then + echo "Error: No filenames provided." + echo "Usage: ./script.sh " + exit 1 +fi + +if [ "$#" -lt 1 ]; then + echo "Error: Insufficient number of arguments for filenames. Need at least one file." + echo "Usage: ./script.sh " + exit 1 +fi + +# Store the filenames +arguments=("$@") + +# Extract filenames +image_file="${arguments[0]}" +fps="${arguments[1]:-24}" +duration="${arguments[2]:-10}" + +ffmpeg -loop 1 -framerate "$fps" -i "$image_file" -c:v libx264 -pix_fmt yuv420p -t "$duration" "${image_file%.*}".mp4 +