To create a video from multiple images, each appearing for a certain duration, and add a background audio file that repeats or loops, you can use the following ffmpeg command:
ffmpeg -framerate 1/5 -i input/image%d.jpg -vf scale=960:540 -c:v libx264 -pix_fmt yuv420p -r 30 output.mp4
You can use the
ffmpeg command to create a video from images with each image appearing for a specified number of seconds using the
Here is an example command that will create a video from images in the
input/ directory with each image appearing for 5 seconds:
This command specifies the following:
-f image2: use the
image2demuxer to read in the images.
-framerate 1/5: set the input framerate to 1/5, which means each image will be displayed for 5 seconds.
-i input/image%d.jpg: specify the input images, with
%dindicating the image number.
-c:v libx264: encode the video using the H.264 codec.
-pix_fmt yuv420p: set the pixel format to YUV 4:2:0, which is a widely supported format.
-r 30: set the output framerate to 30 fps.
output.mp4: specify the output file name and format.
-framerate option to control the duration of each image. For example, if you want each image to appear for 3 seconds, you can set
Here’s an example directory structure for the images you want to use in the
In this structure, all the input images are stored in the
input/ directory. The image files should be named in sequential order, such as
image3.jpg, and so on.
Note that you can use other image file formats supported by
ffmpeg, such as PNG or BMP. Just make sure that the file extensions match the actual file formats of your images.
Also, make sure that you run the
ffmpeg command from the same directory where the input images are located, or use a relative or absolute path to specify the input image directory.
In this example, the
scale filter is used to resize the input images to a width of 960 pixels and a proportional height of 540 pixels. Note that 960 is an even number, so the resulting video should not trigger the “width not divisible by 2” error.
960 value to match the desired even width for your video. Also, note that resizing the images may affect the overall quality of the video, so it’s best to use the original input images whenever possible.