Skip to content

Commit

Permalink
Add container.supported_codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jul 20, 2024
1 parent 68ac522 commit 873b3d4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions av/container/output.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ class OutputContainer(Container):
def default_audio_codec(self) -> str: ...
@property
def default_subtitle_codec(self) -> str: ...
@property
def supported_codecs(self) -> set[str]: ...
20 changes: 20 additions & 0 deletions av/container/output.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ cdef class OutputContainer(Container):

self._started = True

@property
def supported_codecs(self):
"""
List of supported codecs.
"""
result = set()
cdef const lib.AVCodec *codec = NULL
cdef void *opaque = NULL

while True:
codec = lib.av_codec_iterate(&opaque)
if codec == NULL:
break

if lib.avformat_query_codec(self.ptr.oformat, codec.id, lib.FF_COMPLIANCE_NORMAL) == 1:
result.add(codec.name)

return result


@property
def default_video_codec(self):
"""
Expand Down
15 changes: 7 additions & 8 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from libc.stdint cimport int8_t, int64_t, uint16_t, uint32_t

cdef extern from "libavcodec/codec.h":
struct AVCodecTag:
pass

cdef extern from "libavcodec/codec_id.h":
AVCodecID av_codec_get_id(const AVCodecTag *const *tags, uint32_t tag)


cdef extern from "libavcodec/avcodec.h" nogil:
"""
// AV_FRAME_DATA_SEI_UNREGISTERED available since version 56.54.100 of libavutil (FFmpeg >= 4.4)
#define HAS_AV_FRAME_DATA_SEI_UNREGISTERED (LIBAVUTIL_VERSION_INT >= 3683940)
#if !HAS_AV_FRAME_DATA_SEI_UNREGISTERED
#define AV_FRAME_DATA_SEI_UNREGISTERED -1
#endif
"""
cdef set pyav_get_available_codecs()

cdef int avcodec_version()
Expand Down
2 changes: 2 additions & 0 deletions include/libavformat/avformat.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ cdef extern from "libavformat/avformat.h" nogil:
# const AVCodecTag* const *codec_tag
const AVClass *priv_class

int avformat_query_codec(const AVOutputFormat *oformat, AVCodecID codec_id, int std_compliance)

# AVInputFormat.flags and AVOutputFormat.flags
cdef enum:
AVFMT_NOFILE
Expand Down
3 changes: 3 additions & 0 deletions tests/test_containerformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_matroska(self) -> None:
self.assertNotEqual(container.default_video_codec, "none")
self.assertNotEqual(container.default_audio_codec, "none")
self.assertEqual(container.default_subtitle_codec, "ass")
self.assertIn("ass", container.supported_codecs)

fmt = ContainerFormat("matroska")
self.assertTrue(fmt.is_input)
Expand All @@ -23,6 +24,7 @@ def test_mov(self) -> None:
self.assertNotEqual(container.default_video_codec, "none")
self.assertNotEqual(container.default_audio_codec, "none")
self.assertEqual(container.default_subtitle_codec, "none")
self.assertIn("h264", container.supported_codecs)

fmt = ContainerFormat("mov")
self.assertTrue(fmt.is_input)
Expand All @@ -37,6 +39,7 @@ def test_gif(self) -> None:
self.assertEqual(container.default_video_codec, "gif")
self.assertEqual(container.default_audio_codec, "none")
self.assertEqual(container.default_subtitle_codec, "none")
self.assertIn("gif", container.supported_codecs)

def test_stream_segment(self) -> None:
# This format goes by two names, check both.
Expand Down

0 comments on commit 873b3d4

Please sign in to comment.