From 16b065d7d4ad9e96855f00edaba67bb184b10714 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 19 Feb 2025 03:31:21 -0500 Subject: [PATCH] Add Codec.canonical_name --- CHANGELOG.rst | 1 + av/codec/codec.pyi | 2 ++ av/codec/codec.pyx | 9 +++++++++ tests/test_codec.py | 1 + 4 files changed, 13 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 79cca4c55..dc57483c0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -26,6 +26,7 @@ Features: - Add Bayer pixel formats by :gh-user:`z-khan` in (:pr:`1755`). - Add support for yuv422p10le pix_fmt by :gh-user:`WyattBlue` in (:pr:`1767`). - Add ``supported_np_pix_fmts`` by :gh-user:`WyattBlue` in (:pr:`1766`). +- Add ``Codec.canonical_name`` by :gh-user:`WyattBlue`. Misc. - Drop support for MacOS 11 by :gh-user:`WyattBlue` in (:pr:`1764`). diff --git a/av/codec/codec.pyi b/av/codec/codec.pyi index 9f80a4909..4270c641f 100644 --- a/av/codec/codec.pyi +++ b/av/codec/codec.pyi @@ -57,6 +57,8 @@ class Codec: @property def name(self) -> str: ... @property + def canonical_name(self) -> str: ... + @property def long_name(self) -> str: ... @property def type(self) -> Literal["video", "audio", "data", "subtitle", "attachment"]: ... diff --git a/av/codec/codec.pyx b/av/codec/codec.pyx index 3e9e028f8..a28db758e 100644 --- a/av/codec/codec.pyx +++ b/av/codec/codec.pyx @@ -1,3 +1,5 @@ +cimport libav as lib + from av.audio.format cimport get_audio_format from av.codec.hwaccel cimport wrap_hwconfig from av.descriptor cimport wrap_avclass @@ -144,6 +146,13 @@ cdef class Codec: @property def name(self): return self.ptr.name or "" + @property + def canonical_name(self): + """ + Returns the name of the codec, not a specific encoder. + """ + return lib.avcodec_get_name(self.ptr.id) + @property def long_name(self): return self.ptr.long_name or "" diff --git a/tests/test_codec.py b/tests/test_codec.py index 70e688435..9d72a243c 100644 --- a/tests/test_codec.py +++ b/tests/test_codec.py @@ -68,6 +68,7 @@ def test_codec_opus_decoder() -> None: def test_codec_opus_encoder() -> None: c = Codec("opus", "w") assert c.name in ("opus", "libopus") + assert c.canonical_name == "opus" assert c.long_name in ("Opus", "libopus Opus") assert c.type == "audio" assert c.is_encoder