roninpawn / ffmpeg_videostream

FFmpeg-enabled Python Video
9 stars 1 forks source link

_even_test() returns True when .shape() is a tuple. #1

Closed roninpawn closed 2 years ago

roninpawn commented 2 years ago

@bml1g12 reports:

In _even_test(), the variable out is formed as a list from the values of self._shape, then tested for its equality against self._shape.

# ...
w, h = self._shape
if w % 2 > 0: w -= 1
if h % 2 > 0: h -= 1
out = [w, h]
if out != self._shape:
# ...

Because the user can pass a new self._shape in through .config(output_resolution=) , if that value is of the type tuple() it will not be equal to the list() type out.

(1920, 1080) != [1920, 1080]
# True

The simple solution is to just force the type of self._shape during _even_test()'s comparison. So let's not do that!

Instead, the unnecessarily comprehensive solution I'm going to push eliminates lists in the VideoStream object entirely. Having been forced to consider it in this issue, there's just no reason to invoke the read-write list() type in these variables when the read-only tuple() type will do. (and is theoretically faster and smaller)

So in the coming commit, self._shape and self._crop initialize as tuples; The .config() method forces the pertinent arguments into tuple types; And _even_test() now reads out = (w, h) before comparison.