diff --git a/demos/video-capture-simple.py b/demos/video-capture-simple.py index 086dbaa..298e628 100755 --- a/demos/video-capture-simple.py +++ b/demos/video-capture-simple.py @@ -76,8 +76,10 @@ def main() -> None: # the video, as well as possibly audio and more. These are each called "streams". We only create one # stream here, since we're just recording video. video_stream = avmux.add_stream(CODEC, rate=FPS, options=CODEC_OPTIONS) - video_stream.width = monitor["width"] - video_stream.height = monitor["height"] + # Width and height must be divisible by 2, otherwise the encoder will fail. + # Round down to the nearest even number. + video_stream.width = monitor["width"] // 2 * 2 + video_stream.height = monitor["height"] // 2 * 2 # There are more options you can set on the video stream; the full demo uses some of those. # Count how many frames we're capturing, so we can log the FPS later. diff --git a/demos/video-capture.py b/demos/video-capture.py index 18ff9f0..03c0210 100755 --- a/demos/video-capture.py +++ b/demos/video-capture.py @@ -476,8 +476,10 @@ def main() -> None: # so some video encoders will tag it as AVCOL_TRC_BT709 (1) instead. video_stream.color_trc = 13 - video_stream.width = monitor["width"] - video_stream.height = monitor["height"] + # Width and height must be divisible by 2, otherwise the encoder will fail. + # Round down to the nearest even number. + video_stream.width = monitor["width"] // 2 * 2 + video_stream.height = monitor["height"] // 2 * 2 # There are multiple time bases in play (stream, codec context, per-frame). Depending on the container # and codec, some of these might be ignored or overridden. We set the desired time base consistently # everywhere, so that the saved timestamps are correct regardless of what format we're saving to.