Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container.supported_codecs #1465

Merged
merged 3 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Features:
- Support libav's `av_log_set_level` by @materight in (:issue:`1448`).
- Add Graph.link_nodes by @WyattBlue in (:issue:`1449`).
- Add default codec properties by @WyattBlue in (:issue:`1450`).
- Use ffmpeg 6.1.1-5 by @WyattBlue in (:issue:`1462`).
- Remove the xvid and ass packages in ffmpeg binaries because they were unused by @WyattBlue in (:issue:`1462`).
- Add supported_codecs property to OutputContainer by @WyattBlue in (:issue:`1465`).
- Add text and dialogue property to AssSubtitle, remove TextSubtitle by @WyattBlue in (:issue:`1456`).

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion av/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "12.3.0rc1"
__version__ = "12.3.0"
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):
"""
Returns a set of all codecs this format supports.
"""
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
Loading