From 0e5ba64b6b7c6c28cf3de526c833e196c24926fa Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 24 Jun 2026 21:17:23 -0400 Subject: [PATCH] Expose sw_format on VideoCodecContext --- av/video/codeccontext.py | 16 ++++++++++++++++ av/video/codeccontext.pyi | 1 + 2 files changed, 17 insertions(+) diff --git a/av/video/codeccontext.py b/av/video/codeccontext.py index 457ef43e9..ef39c0870 100644 --- a/av/video/codeccontext.py +++ b/av/video/codeccontext.py @@ -251,6 +251,22 @@ def pix_fmt(self): def pix_fmt(self, value): self.ptr.pix_fmt = get_pix_fmt(value) + @property + def sw_format(self): + """ + For a hardware context (e.g. ``format.name == "cuda"``), the underlying + software pixel format (``nv12``, ``p010le``, ...). ``None`` for a regular + software context. + + :type: VideoFormat | None + """ + if not self.ptr.hw_frames_ctx: + return None + frames_ctx: cython.pointer[lib.AVHWFramesContext] = cython.cast( + cython.pointer[lib.AVHWFramesContext], self.ptr.hw_frames_ctx.data + ) + return get_video_format(frames_ctx.sw_format, self.ptr.width, self.ptr.height) + @property def framerate(self): """ diff --git a/av/video/codeccontext.pyi b/av/video/codeccontext.pyi index 280f5cdc0..6b5e27d59 100644 --- a/av/video/codeccontext.pyi +++ b/av/video/codeccontext.pyi @@ -14,6 +14,7 @@ class VideoCodecContext(CodecContext): height: int bits_per_coded_sample: int pix_fmt: str | None + sw_format: VideoFormat | None framerate: Fraction rate: Fraction gop_size: int