From 6e7c68395f944afe0c857d756846564a0b4dcd82 Mon Sep 17 00:00:00 2001 From: Sjoerd Smink Date: Fri, 6 Feb 2026 21:35:14 +0100 Subject: [PATCH 1/3] Update video-capture.py Width and height must be divisible by 2, otherwise the encoder will fail. Round down to the nearest even number. --- demos/video-capture.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demos/video-capture.py b/demos/video-capture.py index 18ff9f0..a1b2983 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"] & ~1 + video_stream.height = monitor["height"] & ~1 # 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. From eafa018940dd89a24cf056ae1c38caf834f0028d Mon Sep 17 00:00:00 2001 From: Sjoerd Smink Date: Fri, 6 Feb 2026 21:43:42 +0100 Subject: [PATCH 2/3] Update video-capture-simple.py Width and height must be divisible by 2, otherwise the encoder will fail. Round down to the nearest even number. --- demos/video-capture-simple.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demos/video-capture-simple.py b/demos/video-capture-simple.py index 086dbaa..2f1acf3 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"] & ~1 + video_stream.height = monitor["height"] & ~1 # 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. From d064dc972220f399495906c730f697acd2b1ed78 Mon Sep 17 00:00:00 2001 From: Sjoerd Smink Date: Fri, 6 Feb 2026 22:04:43 +0100 Subject: [PATCH 3/3] More common syntax --- demos/video-capture-simple.py | 4 ++-- demos/video-capture.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demos/video-capture-simple.py b/demos/video-capture-simple.py index 2f1acf3..298e628 100755 --- a/demos/video-capture-simple.py +++ b/demos/video-capture-simple.py @@ -78,8 +78,8 @@ def main() -> None: video_stream = avmux.add_stream(CODEC, rate=FPS, options=CODEC_OPTIONS) # 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"] & ~1 - video_stream.height = monitor["height"] & ~1 + 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 a1b2983..03c0210 100755 --- a/demos/video-capture.py +++ b/demos/video-capture.py @@ -478,8 +478,8 @@ def main() -> None: # 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"] & ~1 - video_stream.height = monitor["height"] & ~1 + 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.