Version 9 (modified by burek, 6 years ago) (diff)

-shortest:a alone does not work if a video is shorter than audio

This will create a video slideshow (using video codec libx264) from series of PNG images, named named img001.png, img002.png, img003.png, …

Here, each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). By telling FFmpeg to set the input file's FPS option (frames per second) to some very low value, we made FFmpeg duplicate frames at the output and thus we achieved to display each image for some time on screen:

ffmpeg -f image2 -r 1/5 -i img%03d.png -c:v libx264 -r 30 out.mp4

This will create a slideshow in which each image has a duration of 15 seconds:

ffmpeg -f image2 -r 1/15 -i img%03d.png -c:v libx264 -r 30 out.mp4

If you don't have images numbered and ordered in series (img001.jpg, img002.jpg, img003.jpg) but rather random bunch of images, ffmpeg also supports bash-style globbing (* represents any number of any characters):

ffmpeg -f image2 -r 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4

or for png images:

ffmpeg -f image2 -r 1 -pattern_type glob -i '*.png' -c:v libx264 out.mp4

Important: All images in a series need to be of the same size and format.

If you want to create a video out of just one image, this will do (output video duration is set to 30 seconds with -t 30):

ffmpeg -loop 1 -f image2 -i img.png -c:v libx264 -t 30 out.mp4

If you want to add audio (e.g. audio.wav) to one "poster" image, you need -shortest to tell it to stop after the audio stream is finished. We use the internal AAC encoder, but you can use any other AAC encoder as well:

ffmpeg -loop 1 -f image2 -i img.png -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest out.mp4

See also: Create a thumbnail image every X seconds of the video