Linux – How to create a video from images using FFmpeg

ffmpeglinux

Is it possible to use ffmpeg create a video from a set of sequences, where the number does not start from zero?

For example, I have some images [test_100.jpg, test_101.jpg, test_102.jpg, …, test_200.jpg], and I want to convert them to a video. I tried the following command, but it didn't work (it seems the number should start from zero):

ffmpeg -i test_%d.jpg -vcodec mpeg4 test.avi

Any advise?

Best Answer

There is no need to rename files if using the -start_number switch like so:

ffmpeg -start_number n -i test_%d.jpg -vcodec mpeg4 test.avi

where n is the start of the sequence of stills.

Note, this will work as long as the sequence is unbroken once it starts. If there are gaps and you want all of the stills included, then renumbering may be necessary to fill the gaps.

There are some other switches you might find useful.

I use the following one-liner to get a slower frame rate and to compress the images and have a smaller resulting video:

ffmpeg.exe -f image2 -framerate 25 -pattern_type sequence -start_number 1234 -r 3 -i Imgp%04d.jpg -s 720x480 test.avi

The -r 3 option sets the framerate of the resulting video to 3 frames per second so that I can see each still for a short period of time. The -s option rescales the pictures to the desired resolution to manage the size of the resulting video.

(In the Windows shell, replace -i Imgp%04d.jpg with -i "Imgp%%04d.jpg". Credit for this to Mike Fitzpatrick https://superuser.com/a/344178/153054)