Clarification for ffmpeg input option with image files as input

Without any further options, ffmpeg's image2 demuxer will look for a sequence starting with 0. It'll also check around this index, with a default range of 5 (that's why it'll complain about no index in the range 0–4). Per the documentation, you have to set the start number if you want to start at an arbitrary index, like 837.

ffmpeg -start_number 837 -i '%3d_1.png' -c:v libx264 out.mp4

Color space in PNG to H.264 conversion

Since PNG files use the RGB color space to represent pixels, the conversion to H.264 would end up being YUV 4:4:4 (non-subsampled). The resulting video may not be playable on all players, notably anything non-FFmpeg-based. Your player would show only black frames, or possibly crash. To fix that, change the pixel format to YUV 4:2:0:

ffmpeg -start_number 837 -i '%3d_1.png' -c:v libx264 -pix_fmt yuv420p out.mp4

In order to control the quality, use the -crf option. See the x264 encoding guide for more info.

Why the * glob does not work

Don't use the * as an input option. The shell will expand it to all files in the current directory before ffmpeg sees it, so the command would expand to ffmpeg -i file1 file2 … filen. Since all input files in ffmpeg need the -i option, it'll take file2 … filen as output files instead and overwrite them. Not good.


Globbing can be enabled by specifying -pattern_type glob option:

ffmpeg -pattern_type glob -i '*.png' -vcodec libx264 out.mp4

Note: Pattern globbing does not work under Windows (and may never due to lack of support for globbing in libavfilter under Windows.) So, if your doing this under Windows, you'll have to rename the files so that they're numbered sequentially and without gaps.

You can rename them with a simple Powershell command line:

dir *.jpg | %{$x=0} {Rename-Item $_ -NewName “Base$x”; $x++ }

Tags:

Ffmpeg