diff --git a/av/video/codeccontext.py b/av/video/codeccontext.py index f213b9860..d3f36514c 100644 --- a/av/video/codeccontext.py +++ b/av/video/codeccontext.py @@ -245,6 +245,8 @@ def pix_fmt(self): desc: cython.pointer[cython.const[lib.AVPixFmtDescriptor]] = ( lib.av_pix_fmt_desc_get(cython.cast(lib.AVPixelFormat, self.ptr.pix_fmt)) ) + if desc == cython.NULL: + return None return cython.cast(str, desc.name) @pix_fmt.setter diff --git a/tests/test_codec_context.py b/tests/test_codec_context.py index 164ce73fb..730b50bbe 100644 --- a/tests/test_codec_context.py +++ b/tests/test_codec_context.py @@ -150,6 +150,8 @@ def test_encoder_extradata(self) -> None: def test_encoder_pix_fmt(self) -> None: ctx = av.codec.Codec("h264", "w").create("video") + assert ctx.pix_fmt is None + # valid format ctx.pix_fmt = "yuv420p" assert ctx.pix_fmt == "yuv420p"