Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using ffmpeg to convert a number of jpgs into an mp4 file and it seems to be working great, video.mp4 is created. this is the command I'm using:

ffmpeg -r 0.1 -i uploads/image%d.jpg uploads/video.mp4

I have these files inside my uploads directory

image1.jpg
image2.jpg
image3.jpg
image4.jpg

I found this example in a quick google search. I've changed it a little bit but the image%d.jpg remains the same. It's supposed to loop each image and put it into the mp4. However I've found that it isn't including the last file here.

How is the %d incrementing by one and subsequently grabbing each file here? Why isn't it grabbing the last file? When I remove the 4th image, then it only loads the first two images, so the last image just isn't being included for some reason.

Any comments on how this works would really be helpful, Thanks!

share|improve this question

closed as off topic by Ward, Iain, pauska, Scott Pack, Shane Madden Sep 22 '11 at 15:25

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Where did you find the example. Did that command line happen to be inside a printf statement or something? –  Zoredache Sep 22 '11 at 5:59
add comment

3 Answers

up vote 3 down vote accepted

ffmpeg knows that the %d means a single numeric character and so increments through the list of files. So it is ffmpeg doing this rather than the shell - this is important to make sure the images are in sequence.

Note that if your numeric suffixes are more than single digit - like image001.jpg up to image110.jpg then you need to let it know:

ffmpeg -r 0.1 -i uploads/image%03d.jpg uploads/video.mp4

The "%03d" means 3 digit numbers, left padded with zeros (eg 005). "%05d" would mean 5 digit numbers left padded with zeros (eg 00044)

Also note that you cannot have gaps in the numbers, so rename if you do.

More details on the formatting of the number here: http://www.pixelbeat.org/programming/gcc/format_specs.html

share|improve this answer
    
This is great, thanks for the explanation! –  Doug Molineux Sep 23 '11 at 16:03
add comment

AFAIK, %d belongs to ffmpeg, not bash. I've tested your command and it works fine. Make sure that the third image doesn't has spaces at the beginning of file name.

share|improve this answer
add comment

if you know the range you can do something like

 ffmpeg -r 0.1 -i uploads/image{1..4}.jpg uploads/video.mp4
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.