imageio / imageio-ffmpeg

FFMPEG wrapper for Python
BSD 2-Clause "Simplified" License
237 stars 52 forks source link

Encoders are not always fully compatible with all image shapes #73

Open hmaarrfk opened 2 years ago

hmaarrfk commented 2 years ago

So we ran into this, and I figured I would share back some findings since I did contribute the code in question:

In recent version of imageio-ffmpeg, an attempt is made to find the "best" encoder.

https://github.com/imageio/imageio-ffmpeg/blob/7bfe71d4a23fa881c792d23e0cf67ef4fc446dd8/imageio_ffmpeg/_io.py#L16

However, the choice of encoder also needs to be conditioned, among other things, on the encoder capabilities.

Different things, like the pixel type, but most critically, the image shape, can affect the best choice for the given encoder. See for example the bug report: https://trac.ffmpeg.org/ticket/9251

I've added a shape parameter to the test to ensure that the choice of encoder matches the shape of the video.

You probably also want to test with the compatibility of the filters. Though for me, this is outside the scope of my immediate needs.

almarklein commented 2 years ago

Thanks for reporting this. From what I understand some encoders may not support videos with a with/height smaller than 145 pixels. Do you know whether the limitations only relate to a minimum size or also e.g. factor of 2 constraints?

hmaarrfk commented 2 years ago

I figured that the cost of the test is small compared to the encoding time.

With users likely to encode under the same settings many times, the test, in conjunction with the shape as a tuple and lru cache, should amortize to 0 over the long run.

There i just test every time.