imageio-ffmpeg icon indicating copy to clipboard operation
imageio-ffmpeg copied to clipboard

Encoders are not always fully compatible with all image shapes

Open hmaarrfk opened this issue 3 years ago • 2 comments

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.

hmaarrfk avatar Jul 21 '22 00:07 hmaarrfk

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?

almarklein avatar Jul 26 '22 20:07 almarklein

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.

hmaarrfk avatar Jul 27 '22 01:07 hmaarrfk