How to get FFMPEG to join non-sequential image files? (skip by 3s)

15

6

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

FakeRainBrigand

Posted 2013-03-04T15:04:57.527

Reputation: 197

2

How about temporarily renaming them, making the AVI and then renaming them back to the (3x-2).png scheme? Bulk Rename Utility @ http://www.bulkrenameutility.co.uk/Main_Intro.php is a free, umm, bulk renamer.

Mulvya 2013-03-04T15:25:36.740

Answers

9

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.

rymo

Posted 2013-03-04T15:04:57.527

Reputation: 206

3This hasn't been working for me using ffmpeg or avconv in Ubuntu 13.04hellocatfood 2013-09-12T19:24:32.817

2This appears to not be an option any more.Timmmm 2015-01-27T12:59:52.287

It seems they deprecated this syntax at some point. The updated documentation was committed 8-Aug-2012 but I can't tell what version that equates to across the multiple branches. See http://git.videolan.org/?p=ffmpeg.git;a=commit;h=7794ddeae3edba09fbf3e5badfedf5ea20a9a1f6

rymo 2015-01-27T18:01:50.283

1The glob_sequence pattern type is deprecated, but the glob pattern type is not. The answer by Mulvya and Peter Cordes works.dr. Sybren 2015-09-07T22:03:27.790

1Pattern type 'glob_sequence' is deprecated: use pattern_type 'glob' insteadSerge Stroobandt 2017-02-07T16:17:51.263

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 2017-12-18T05:38:18.713

10

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.

Mulvya

Posted 2013-03-04T15:04:57.527

Reputation: 15 258

And probably by whatever portability layer ffmpeg on windows is compiled with. The ffmpeg docs example has it quoted.Peter Cordes 2015-01-15T10:12:57.643

1Sadly the ffmpeg developers make file globbing support an option! The standard windows builds don't include it.Timmmm 2015-01-27T13:01:00.910

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.FakeRainBrigand 2013-03-05T20:14:52.263

According to the ffmpeg documentation you should use '*.png' instead of %04d.png with the glob pattern type.

Friend Of George 2013-03-05T22:06:44.067

That would then select all the pngs present in the folder, besides 00xx.png, whereas the OP wants to queue only the %04d pngs without worrying about numbering continuity.Mulvya 2013-03-06T07:09:49.533

Did you actually test this command? I don't think -pattern_type glob works with %04d.png and will probably result in Could not open file : %04d.png.LordNeckbeard 2013-03-06T20:15:51.380

I haven't tested it. I just checked the syntax for glob @ http://www.jedit.org/users-guide/globs.html and it seems that %04d won't work. However, %?%?%?%?.png should work.

Mulvya 2013-03-07T05:26:26.340

2I'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 2013-04-05T09:03:42.250

6

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

Nikhil

Posted 2013-03-04T15:04:57.527

Reputation: 61

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 2014-03-03T03:45:09.887

4

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.

AJ Henderson

Posted 2013-03-04T15:04:57.527

Reputation: 17 944

I ended up doing something similar (a Python renaming script).FakeRainBrigand 2013-03-05T20:16:28.720