2

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!

Paweł Brodacki
  • 6,511
  • 20
  • 23
Doug Molineux
  • 423
  • 3
  • 7
  • 17
  • Where did you find the example. Did that command line happen to be inside a printf statement or something? – Zoredache Sep 22 '11 at 05:59

3 Answers3

3

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

Paul
  • 1,288
  • 13
  • 25
1

if you know the range you can do something like

 ffmpeg -r 0.1 -i uploads/image{1..4}.jpg uploads/video.mp4
Mike
  • 22,310
  • 7
  • 56
  • 79
0

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.

quanta
  • 51,413
  • 19
  • 159
  • 217