tags:

views:

248

answers:

3

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?

+5  A: 

As far as I know, you cannot start the sequence in random numbers (I don't remember if you should start it at 0 or 1), plus, it cannot have gaps, if it does, ffmpeg will assume the sequence is over and stop adding more images.

Also, as stated in the comments to my answer, remember you need to specify the width of your index. Like:

image%03d.jpg

And if you use a %03d index type, you need to pad your filenames with 0, like :

image001.jpg image002.jpg image003.jpg

etc.

Francisco Soto
If the image file names have leading zeros then the format string must also specify the width like "%03d".
Hudson
If that's the only obstacle, you could just write a script to either rename or symlink your images to a properly reindexed set.
Jefromi
Yes, I've worked with this before, I wrote a wrapper in Ruby a while ago where you called instance.addImage(), then instance.processVideo() and it would create a temporal directory, copy/rename the images with proper indices and create the video. It is quite easy.
Francisco Soto
+2  A: 

I agree with Francisco, but as a workaround you could just write a quick script to move or create symbolic links to the files with the sequence numbers that ffmpeg needs. The script could then call ffmpeg and then remove the links or move the files back to their original locations.

Jason
A: 

You can find an example script in the ffmpeg documentation:

3.2 How do I encode single pictures into movies?

If you have large number of pictures to rename, you can use the following command to ease the burden. The command, using the bourne shell syntax, symbolically links all files in the current directory that match *jpg to the /tmp' directory in the sequence ofimg001.jpg', `img002.jpg' and so on.

x=1; for i in *jpg; do counter=$(printf %03d $x); ln "$i" /tmp/img"$counter".jpg; x=$(($x+1)); done

Then run:

ffmpeg -f image2 -i /tmp/img%03d.jpg /tmp/a.mpg
gaizka