Search code examples
animationffmpegpngdimension

FFMPEG error when making animations with certain frame dimensions


I have been using ffmpeg to successfully generate animations of png images with a size of 7205x4308 with the following command:

-framerate 25 -f image2 -start_number 1 -i fig%4d.png -f mp4 -vf scale=-2:ih -vcodec libx264 -pix_fmt yuv420p 2015-2018.mp4

When I try to run the same command for a group of images with a different size, e.g., 6404x5575, I get the following error:

Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

I have concluded that the reason it is failing has something to do with the frame size because that is the only thing that is different between the first successful animation and the one that is failing. But, my intuition could be wrong(?). I have tried to remove the scaling parameter in the command but I get the same error.

I am using ffmpeg version 3.4.2 on Mac OSX 10.13 via python.

Any help would be much appreciated. Thanks!


Solution

  • Both dimensions have to be even when encoding to 4:2:0.

    So,

    scale=-2:ih-mod(ih,2)