39

I have a bunch of images, that follow this pattern.

0001.png
0004.png
0007.png
0010.png
0013.png
0016.png
0019.png
...

They're in the correct order, but FFMPEG ignores anything after the first file, because it can't find a 0002.png. How can I get it to join these files?

I tried

ffmpeg -i %04d.png out.avi
1
  • 2
    How about temporarily renaming them, making the AVI and then renaming them back to the (3x-2).png scheme? Bulk Rename Utility @ bulkrenameutility.co.uk/Main_Intro.php is a free, umm, bulk renamer.
    – Gyan
    Commented Mar 4, 2013 at 15:25

6 Answers 6

30

For recent versions of ffmpeg, see Gyan's answer instead

Original answer:


with ffmpeg 0.11.1 it's as easy as:

ffmpeg -f image2 -i %*.png out.avi

From the man page, in an example under "Video and Audio file format conversion":

When importing an image sequence, -i also supports expanding shell-like wildcard patterns (globbing) internally. To lower the chance of interfering with your actual file names and the shell's glob expansion, you are required to activate glob meta characters by prefixing them with a single % character, like in foo-%*.jpeg, foo-%?%?%?.jpeg or foo-00%[234%]%*.jpeg.

Update per comments: on recent versions you should now use -i '*.png' syntax.

7
  • 3
    This hasn't been working for me using ffmpeg or avconv in Ubuntu 13.04 Commented Sep 12, 2013 at 19:24
  • 2
    This appears to not be an option any more.
    – Timmmm
    Commented Jan 27, 2015 at 12:59
  • 2
    The glob_sequence pattern type is deprecated, but the glob pattern type is not. The answer by Mulvya and Peter Cordes works.
    – dr. Sybren
    Commented Sep 7, 2015 at 22:03
  • 1
    Pattern type 'glob_sequence' is deprecated: use pattern_type 'glob' instead Commented Feb 7, 2017 at 16:17
  • 1
    Just as clarification, since this page is currently the top result in Google for that warning message (Pattern type 'glob_sequence' is deprecated...): the command given by rymo above (specifically, -i %*.png) will cause the warning. To eliminate it, use the slightly-different syntax in Peter Cordes answer (-i '*.png').
    – James
    Commented Dec 18, 2017 at 5:38
25

Besides the workaround in my comment, you should be able to use this syntax from the ffmpeg documentation:

ffmpeg -f image2 -pattern_type glob -i '*.png' out.avi

The quotes are important, you need ffmpeg to see the *, not have the shell expand it.

10
  • Doesn't work for me, but it's probably because I have an older build. I'm accepting this one because it's most likely to help future users.
    – Brigand
    Commented Mar 5, 2013 at 20:14
  • According to the ffmpeg documentation you should use '*.png' instead of %04d.png with the glob pattern type. Commented Mar 5, 2013 at 22:06
  • 2
    I'm pretty sure that you need to put *.png in single-quotes (so '*.png') to avoid it being expanded by Unix-style shells (so, OSX and linux etc).
    – evilsoup
    Commented Apr 5, 2013 at 9:03
  • 3
    Sadly the ffmpeg developers make file globbing support an option! The standard windows builds don't include it.
    – Timmmm
    Commented Jan 27, 2015 at 13:01
  • 1
    Globbing is not supported on Windows.
    – Gyan
    Commented Oct 29, 2021 at 11:54
9

From http://www.ffmpeg.org/faq.html: 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 of ‘img001.jpg’, ‘img002.jpg’ and so on.

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

2
  • I used this to combine multiple sequences seqA-[0001-n].png, seqB-[0001-n].png, etc. Much easier than messing around with image2 globbing and the concat filter.
    – z0r
    Commented Mar 3, 2014 at 3:45
  • For me this didn't work until I replaced for i in *jpg with for i in /full/path/*jpg, because all the symlinks were broken
    – Jezzamon
    Commented Apr 23, 2018 at 6:37
6

I would actually suggest the same thing Mulvya suggested. Whenever I've needed to do stuff like this when dealing with 3D animation renderings, I've renamed the files to make them sequential. It's just easier to work with that way in a lot of different software unless you need to preserve the file names for some reason. Total Commander is also a great tool for multi-renaming.

1
  • I ended up doing something similar (a Python renaming script).
    – Brigand
    Commented Mar 5, 2013 at 20:16
5

For the missing sequence part, I used 2 liner

CONCAT=$(echo $(ls *.png | sort -n -t _ -k 2) | sed -e "s/ /|/g")
ffmpeg -framerate 25 -i "concat:$CONCAT" -c:v libx264 -profile:v high -pix_fmt yuv420p output.mp4

Hope this will help someone in future

0

If the images are dated, exiftool can be used to rename the source files to yyyy-mm-dd_hhmm pattern. Then a bash script can create an input file for ffmpeg.

Here is a script that shows the idea: https://github.com/leobard/timelapse-prepare-and-run-ffmpeg.sh/blob/main/timelapse-prepare-and-run-ffmpeg.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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