Search code examples
ffmpegmovie

ffmpeg from pngs... Error with subset of PNGS?


I have about 1200 pngs that I'm converting into a movie. Some of them are missing: i.e. - _00003.png, _00005.png exist, but 1, 2, and 4 do not.

The following command works for other datasets, but not my current set of pngs:

ffmpeg -i pngs/_*.png -y -vcodec mpeg4 -pix_fmt yuv420p -r 25 -filter:v 'setpts=1.2*PTS' p3SN.mp4

I get this error:

Output #61, image2, to 'pngs/_00096.png':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #61:0: Video: png, rgba, 3240x2160 [SAR 3937:3937 DAR 3:2], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.107.100 png
Output #62, image2, to 'pngs/_00097.png':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #62:0: Video: png, rgba, 3240x2160 [SAR 3937:3937 DAR 3:2], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.107.100 png
[png @ 0x7fae93170e00] ff_frame_thread_encoder_init failed
Error initializing output stream 63:0 -- Error while opening encoder for output stream #63:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

at image _00097.png. If I remove it, it just happens a little later (105).

I've checked the images by looking at their dimensions, etc. and all of them in this range look the same (I checked all those with _0009?.png).

Any idea why this is happening?

Here's the offending file (middle) and the one before/after:

96

97 - the 'error picture'

98


Solution

  • Your command will overwrite all of the input files with the first input. This is an example of why to use caution when using -y which will automatically overwrite files without asking you.

    You need to tell ffmpeg to use the glob pattern:

    ffmpeg -y -pattern_type glob -framerate 25/1.2 -i "pngs/_*.png" -vcodec mpeg4 -pix_fmt yuv420p -r 25 p3SN.mp4
    
    • I believe the glob pattern option does not work on Windows, but if it has an equivalent to the Linux cat command you can pipe the output: cat *.png | ffmpeg -i - output.mp4
    • You can use -framerate and -r instead of setpts if desired.