From 80ca00af3f84c0a9731611a25af855907b30391b Mon Sep 17 00:00:00 2001 From: z-khan Date: Mon, 28 Oct 2024 14:00:21 +1100 Subject: [PATCH 1/8] add acodec to format enable use of non-default audio codec to open an audio device with a certain host API. e.g. use av.open(file="device_id",format="ALSA:pcm_s32le) to open with 32bit PCM in ffmpeg (default is pcm_s16le if not provided). Some audio devices fail to open with the default codec, hence this is a useful addition. --- av/container/core.pyx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/av/container/core.pyx b/av/container/core.pyx index dab7c865e..48a49b2d2 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -162,6 +162,43 @@ Flags = define_enum("Flags", __name__, ( "Add bitstream filters as requested by the muxer."), ), is_flags=True) +AudioCodec = define_enum("AudioCodec", __name__, ( + ("NONE", lib.AV_CODEC_ID_NONE), + ("PCM_ALAW", lib.AV_CODEC_ID_PCM_ALAW), + ("PCM_BLURAY", lib.AV_CODEC_ID_PCM_BLURAY), + ("PCM_DVD", lib.AV_CODEC_ID_PCM_DVD), + ("PCM_F16LE", lib.AV_CODEC_ID_PCM_F16LE), + ("PCM_F24LE", lib.AV_CODEC_ID_PCM_F24LE), + ("PCM_F32BE", lib.AV_CODEC_ID_PCM_F32BE), + ("PCM_F32LE", lib.AV_CODEC_ID_PCM_F32LE), + ("PCM_F64BE", lib.AV_CODEC_ID_PCM_F64BE), + ("PCM_F64LE", lib.AV_CODEC_ID_PCM_F64LE), + ("PCM_LXF", lib.AV_CODEC_ID_PCM_LXF), + ("PCM_MULAW", lib.AV_CODEC_ID_PCM_MULAW), + ("PCM_S16BE", lib.AV_CODEC_ID_PCM_S16BE), + ("PCM_S16BE_PLANAR", lib.AV_CODEC_ID_PCM_S16BE_PLANAR), + ("PCM_S16LE", lib.AV_CODEC_ID_PCM_S16LE), + ("PCM_S16LE_PLANAR", lib.AV_CODEC_ID_PCM_S16LE_PLANAR), + ("PCM_S24BE", lib.AV_CODEC_ID_PCM_S24BE), + ("PCM_S24DAUD", lib.AV_CODEC_ID_PCM_S24DAUD), + ("PCM_S24LE", lib.AV_CODEC_ID_PCM_S24LE), + ("PCM_S24LE_PLANAR", lib.AV_CODEC_ID_PCM_S24LE_PLANAR), + ("PCM_S32BE", lib.AV_CODEC_ID_PCM_S32BE), + ("PCM_S32LE", lib.AV_CODEC_ID_PCM_S32LE), + ("PCM_S32LE_PLANAR", lib.AV_CODEC_ID_PCM_S32LE_PLANAR), + ("PCM_S64BE", lib.AV_CODEC_ID_PCM_S64BE), + ("PCM_S64LE", lib.AV_CODEC_ID_PCM_S64LE), + ("PCM_S8", lib.AV_CODEC_ID_PCM_S8), + ("PCM_S8_PLANAR", lib.AV_CODEC_ID_PCM_S8_PLANAR), + ("PCM_U16BE", lib.AV_CODEC_ID_PCM_U16BE), + ("PCM_U16LE", lib.AV_CODEC_ID_PCM_U16LE), + ("PCM_U24BE", lib.AV_CODEC_ID_PCM_U24BE), + ("PCM_U24LE", lib.AV_CODEC_ID_PCM_U24LE), + ("PCM_U32BE", lib.AV_CODEC_ID_PCM_U32BE), + ("PCM_U32LE", lib.AV_CODEC_ID_PCM_U32LE), + ("PCM_U8", lib.AV_CODEC_ID_PCM_U8), + ("PCM_VIDC", lib.AV_CODEC_ID_PCM_VIDC) +)) cdef class Container: @@ -196,7 +233,10 @@ cdef class Container: self.buffer_size = buffer_size self.io_open = io_open + acodec = None # no audio codec specified if format_name is not None: + if ":" in format_name: + format_name, acodec = format_name.split(":") self.format = ContainerFormat(format_name) self.input_was_opened = False @@ -231,6 +271,9 @@ cdef class Container: self.ptr.interrupt_callback.callback = interrupt_cb self.ptr.interrupt_callback.opaque = &self.interrupt_callback_info + if acodec is not None: + self.ptr.audio_codec_id = AudioCodec[acodec.upper()] + self.ptr.flags |= lib.AVFMT_FLAG_GENPTS self.ptr.opaque = self From b2713fd90e53b191fabe5ed8d992d44544bf0e2a Mon Sep 17 00:00:00 2001 From: z-khan Date: Mon, 28 Oct 2024 14:15:33 +1100 Subject: [PATCH 2/8] add AVCodecIDs for PCM audio formats add PCM audio codec IDs --- include/libavcodec/avcodec.pxd | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/libavcodec/avcodec.pxd b/include/libavcodec/avcodec.pxd index 71121e976..4076c6ed4 100644 --- a/include/libavcodec/avcodec.pxd +++ b/include/libavcodec/avcodec.pxd @@ -147,6 +147,40 @@ cdef extern from "libavcodec/avcodec.h" nogil: AV_CODEC_ID_NONE AV_CODEC_ID_MPEG2VIDEO AV_CODEC_ID_MPEG1VIDEO + AV_CODEC_ID_PCM_ALAW + AV_CODEC_ID_PCM_BLURAY + AV_CODEC_ID_PCM_DVD + AV_CODEC_ID_PCM_F16LE + AV_CODEC_ID_PCM_F24LE + AV_CODEC_ID_PCM_F32BE + AV_CODEC_ID_PCM_F32LE + AV_CODEC_ID_PCM_F64BE + AV_CODEC_ID_PCM_F64LE + AV_CODEC_ID_PCM_LXF + AV_CODEC_ID_PCM_MULAW + AV_CODEC_ID_PCM_S16BE + AV_CODEC_ID_PCM_S16BE_PLANAR + AV_CODEC_ID_PCM_S16LE + AV_CODEC_ID_PCM_S16LE_PLANAR + AV_CODEC_ID_PCM_S24BE + AV_CODEC_ID_PCM_S24DAUD + AV_CODEC_ID_PCM_S24LE + AV_CODEC_ID_PCM_S24LE_PLANAR + AV_CODEC_ID_PCM_S32BE + AV_CODEC_ID_PCM_S32LE + AV_CODEC_ID_PCM_S32LE_PLANAR + AV_CODEC_ID_PCM_S64BE + AV_CODEC_ID_PCM_S64LE + AV_CODEC_ID_PCM_S8 + AV_CODEC_ID_PCM_S8_PLANAR + AV_CODEC_ID_PCM_U16BE + AV_CODEC_ID_PCM_U16LE + AV_CODEC_ID_PCM_U24BE + AV_CODEC_ID_PCM_U24LE + AV_CODEC_ID_PCM_U32BE + AV_CODEC_ID_PCM_U32LE + AV_CODEC_ID_PCM_U8 + AV_CODEC_ID_PCM_VIDC cdef enum AVDiscard: AVDISCARD_NONE From 2ee97fc2ffcafe2912b239ffe24b8178ac10a389 Mon Sep 17 00:00:00 2001 From: z-khan Date: Mon, 28 Oct 2024 14:20:43 +1100 Subject: [PATCH 3/8] add AVCodecID to format context --- include/libavformat/avformat.pxd | 1 + 1 file changed, 1 insertion(+) diff --git a/include/libavformat/avformat.pxd b/include/libavformat/avformat.pxd index 5fa25043a..aa1ab2831 100644 --- a/include/libavformat/avformat.pxd +++ b/include/libavformat/avformat.pxd @@ -193,6 +193,7 @@ cdef extern from "libavformat/avformat.h" nogil: int flags int64_t max_analyze_duration + AVCodecID audio_codec_id void *opaque int (*io_open)( From 3355581f632647f5b6e70ef50b1470f9cd873617 Mon Sep 17 00:00:00 2001 From: z-khan Date: Tue, 28 Jan 2025 19:01:37 +1100 Subject: [PATCH 4/8] Update core.pyx with new Enum --- av/container/core.pyx | 74 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/av/container/core.pyx b/av/container/core.pyx index 48a49b2d2..512ee460f 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -162,43 +162,43 @@ Flags = define_enum("Flags", __name__, ( "Add bitstream filters as requested by the muxer."), ), is_flags=True) -AudioCodec = define_enum("AudioCodec", __name__, ( - ("NONE", lib.AV_CODEC_ID_NONE), - ("PCM_ALAW", lib.AV_CODEC_ID_PCM_ALAW), - ("PCM_BLURAY", lib.AV_CODEC_ID_PCM_BLURAY), - ("PCM_DVD", lib.AV_CODEC_ID_PCM_DVD), - ("PCM_F16LE", lib.AV_CODEC_ID_PCM_F16LE), - ("PCM_F24LE", lib.AV_CODEC_ID_PCM_F24LE), - ("PCM_F32BE", lib.AV_CODEC_ID_PCM_F32BE), - ("PCM_F32LE", lib.AV_CODEC_ID_PCM_F32LE), - ("PCM_F64BE", lib.AV_CODEC_ID_PCM_F64BE), - ("PCM_F64LE", lib.AV_CODEC_ID_PCM_F64LE), - ("PCM_LXF", lib.AV_CODEC_ID_PCM_LXF), - ("PCM_MULAW", lib.AV_CODEC_ID_PCM_MULAW), - ("PCM_S16BE", lib.AV_CODEC_ID_PCM_S16BE), - ("PCM_S16BE_PLANAR", lib.AV_CODEC_ID_PCM_S16BE_PLANAR), - ("PCM_S16LE", lib.AV_CODEC_ID_PCM_S16LE), - ("PCM_S16LE_PLANAR", lib.AV_CODEC_ID_PCM_S16LE_PLANAR), - ("PCM_S24BE", lib.AV_CODEC_ID_PCM_S24BE), - ("PCM_S24DAUD", lib.AV_CODEC_ID_PCM_S24DAUD), - ("PCM_S24LE", lib.AV_CODEC_ID_PCM_S24LE), - ("PCM_S24LE_PLANAR", lib.AV_CODEC_ID_PCM_S24LE_PLANAR), - ("PCM_S32BE", lib.AV_CODEC_ID_PCM_S32BE), - ("PCM_S32LE", lib.AV_CODEC_ID_PCM_S32LE), - ("PCM_S32LE_PLANAR", lib.AV_CODEC_ID_PCM_S32LE_PLANAR), - ("PCM_S64BE", lib.AV_CODEC_ID_PCM_S64BE), - ("PCM_S64LE", lib.AV_CODEC_ID_PCM_S64LE), - ("PCM_S8", lib.AV_CODEC_ID_PCM_S8), - ("PCM_S8_PLANAR", lib.AV_CODEC_ID_PCM_S8_PLANAR), - ("PCM_U16BE", lib.AV_CODEC_ID_PCM_U16BE), - ("PCM_U16LE", lib.AV_CODEC_ID_PCM_U16LE), - ("PCM_U24BE", lib.AV_CODEC_ID_PCM_U24BE), - ("PCM_U24LE", lib.AV_CODEC_ID_PCM_U24LE), - ("PCM_U32BE", lib.AV_CODEC_ID_PCM_U32BE), - ("PCM_U32LE", lib.AV_CODEC_ID_PCM_U32LE), - ("PCM_U8", lib.AV_CODEC_ID_PCM_U8), - ("PCM_VIDC", lib.AV_CODEC_ID_PCM_VIDC) -)) +class AudioCodec(Enum): + none: "No codec." = lib.AV_CODEC_ID_NONE + pcm_alaw: "PCM A-law." = lib.AV_CODEC_ID_PCM_ALAW + pcm_bluray: "PCM Blu-ray." = lib.AV_CODEC_ID_PCM_BLURAY + pcm_dvd: "PCM DVD." = lib.AV_CODEC_ID_PCM_DVD + pcm_f16le: "PCM F16 little-endian." = lib.AV_CODEC_ID_PCM_F16LE + pcm_f24le: "PCM F24 little-endian." = lib.AV_CODEC_ID_PCM_F24LE + pcm_f32be: "PCM F32 big-endian." = lib.AV_CODEC_ID_PCM_F32BE + pcm_f32le: "PCM F32 little-endian." = lib.AV_CODEC_ID_PCM_F32LE + pcm_f64be: "PCM F64 big-endian." = lib.AV_CODEC_ID_PCM_F64BE + pcm_f64le: "PCM F64 little-endian." = lib.AV_CODEC_ID_PCM_F64LE + pcm_lxf: "PCM LXF." = lib.AV_CODEC_ID_PCM_LXF + pcm_mulaw: "PCM μ-law." = lib.AV_CODEC_ID_PCM_MULAW + pcm_s16be: "PCM signed 16-bit big-endian." = lib.AV_CODEC_ID_PCM_S16BE + pcm_s16be_planar: "PCM signed 16-bit big-endian planar." = lib.AV_CODEC_ID_PCM_S16BE_PLANAR + pcm_s16le: "PCM signed 16-bit little-endian." = lib.AV_CODEC_ID_PCM_S16LE + pcm_s16le_planar: "PCM signed 16-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S16LE_PLANAR + pcm_s24be: "PCM signed 24-bit big-endian." = lib.AV_CODEC_ID_PCM_S24BE + pcm_s24daud: "PCM signed 24-bit D-Cinema audio." = lib.AV_CODEC_ID_PCM_S24DAUD + pcm_s24le: "PCM signed 24-bit little-endian." = lib.AV_CODEC_ID_PCM_S24LE + pcm_s24le_planar: "PCM signed 24-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S24LE_PLANAR + pcm_s32be: "PCM signed 32-bit big-endian." = lib.AV_CODEC_ID_PCM_S32BE + pcm_s32le: "PCM signed 32-bit little-endian." = lib.AV_CODEC_ID_PCM_S32LE + pcm_s32le_planar: "PCM signed 32-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S32LE_PLANAR + pcm_s64be: "PCM signed 64-bit big-endian." = lib.AV_CODEC_ID_PCM_S64BE + pcm_s64le: "PCM signed 64-bit little-endian." = lib.AV_CODEC_ID_PCM_S64LE + pcm_s8: "PCM signed 8-bit." = lib.AV_CODEC_ID_PCM_S8 + pcm_s8_planar: "PCM signed 8-bit planar." = lib.AV_CODEC_ID_PCM_S8_PLANAR + pcm_u16be: "PCM unsigned 16-bit big-endian." = lib.AV_CODEC_ID_PCM_U16BE + pcm_u16le: "PCM unsigned 16-bit little-endian." = lib.AV_CODEC_ID_PCM_U16LE + pcm_u24be: "PCM unsigned 24-bit big-endian." = lib.AV_CODEC_ID_PCM_U24BE + pcm_u24le: "PCM unsigned 24-bit little-endian." = lib.AV_CODEC_ID_PCM_U24LE + pcm_u32be: "PCM unsigned 32-bit big-endian." = lib.AV_CODEC_ID_PCM_U32BE + pcm_u32le: "PCM unsigned 32-bit little-endian." = lib.AV_CODEC_ID_PCM_U32LE + pcm_u8: "PCM unsigned 8-bit." = lib.AV_CODEC_ID_PCM_U8 + pcm_vidc: "PCM VIDC." = lib.AV_CODEC_ID_PCM_VIDC + cdef class Container: From 4073079328b8d5f410d8817d487dc3ec0f3fd167 Mon Sep 17 00:00:00 2001 From: z-khan Date: Tue, 28 Jan 2025 19:24:05 +1100 Subject: [PATCH 5/8] Update core.pyx move to usage of IntEnum --- av/container/core.pyx | 75 ++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/av/container/core.pyx b/av/container/core.pyx index 3fc4d242c..52f8ceefe 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -3,7 +3,7 @@ from libc.stdint cimport int64_t import os import time -from enum import Flag +from enum import Flag, IntEnum from pathlib import Path cimport libav as lib @@ -141,42 +141,43 @@ class Flags(Flag): shortest: "Stop muxing when the shortest stream stops." = lib.AVFMT_FLAG_SHORTEST auto_bsf: "Add bitstream filters as requested by the muxer." = lib.AVFMT_FLAG_AUTO_BSF -class AudioCodec(Enum): - none: "No codec." = lib.AV_CODEC_ID_NONE - pcm_alaw: "PCM A-law." = lib.AV_CODEC_ID_PCM_ALAW - pcm_bluray: "PCM Blu-ray." = lib.AV_CODEC_ID_PCM_BLURAY - pcm_dvd: "PCM DVD." = lib.AV_CODEC_ID_PCM_DVD - pcm_f16le: "PCM F16 little-endian." = lib.AV_CODEC_ID_PCM_F16LE - pcm_f24le: "PCM F24 little-endian." = lib.AV_CODEC_ID_PCM_F24LE - pcm_f32be: "PCM F32 big-endian." = lib.AV_CODEC_ID_PCM_F32BE - pcm_f32le: "PCM F32 little-endian." = lib.AV_CODEC_ID_PCM_F32LE - pcm_f64be: "PCM F64 big-endian." = lib.AV_CODEC_ID_PCM_F64BE - pcm_f64le: "PCM F64 little-endian." = lib.AV_CODEC_ID_PCM_F64LE - pcm_lxf: "PCM LXF." = lib.AV_CODEC_ID_PCM_LXF - pcm_mulaw: "PCM μ-law." = lib.AV_CODEC_ID_PCM_MULAW - pcm_s16be: "PCM signed 16-bit big-endian." = lib.AV_CODEC_ID_PCM_S16BE - pcm_s16be_planar: "PCM signed 16-bit big-endian planar." = lib.AV_CODEC_ID_PCM_S16BE_PLANAR - pcm_s16le: "PCM signed 16-bit little-endian." = lib.AV_CODEC_ID_PCM_S16LE - pcm_s16le_planar: "PCM signed 16-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S16LE_PLANAR - pcm_s24be: "PCM signed 24-bit big-endian." = lib.AV_CODEC_ID_PCM_S24BE - pcm_s24daud: "PCM signed 24-bit D-Cinema audio." = lib.AV_CODEC_ID_PCM_S24DAUD - pcm_s24le: "PCM signed 24-bit little-endian." = lib.AV_CODEC_ID_PCM_S24LE - pcm_s24le_planar: "PCM signed 24-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S24LE_PLANAR - pcm_s32be: "PCM signed 32-bit big-endian." = lib.AV_CODEC_ID_PCM_S32BE - pcm_s32le: "PCM signed 32-bit little-endian." = lib.AV_CODEC_ID_PCM_S32LE - pcm_s32le_planar: "PCM signed 32-bit little-endian planar." = lib.AV_CODEC_ID_PCM_S32LE_PLANAR - pcm_s64be: "PCM signed 64-bit big-endian." = lib.AV_CODEC_ID_PCM_S64BE - pcm_s64le: "PCM signed 64-bit little-endian." = lib.AV_CODEC_ID_PCM_S64LE - pcm_s8: "PCM signed 8-bit." = lib.AV_CODEC_ID_PCM_S8 - pcm_s8_planar: "PCM signed 8-bit planar." = lib.AV_CODEC_ID_PCM_S8_PLANAR - pcm_u16be: "PCM unsigned 16-bit big-endian." = lib.AV_CODEC_ID_PCM_U16BE - pcm_u16le: "PCM unsigned 16-bit little-endian." = lib.AV_CODEC_ID_PCM_U16LE - pcm_u24be: "PCM unsigned 24-bit big-endian." = lib.AV_CODEC_ID_PCM_U24BE - pcm_u24le: "PCM unsigned 24-bit little-endian." = lib.AV_CODEC_ID_PCM_U24LE - pcm_u32be: "PCM unsigned 32-bit big-endian." = lib.AV_CODEC_ID_PCM_U32BE - pcm_u32le: "PCM unsigned 32-bit little-endian." = lib.AV_CODEC_ID_PCM_U32LE - pcm_u8: "PCM unsigned 8-bit." = lib.AV_CODEC_ID_PCM_U8 - pcm_vidc: "PCM VIDC." = lib.AV_CODEC_ID_PCM_VIDC +class AudioCodec(IntEnum): + """Enumeration for audio codec IDs.""" + none = lib.AV_CODEC_ID_NONE # No codec. + pcm_alaw = lib.AV_CODEC_ID_PCM_ALAW # PCM A-law. + pcm_bluray = lib.AV_CODEC_ID_PCM_BLURAY # PCM Blu-ray. + pcm_dvd = lib.AV_CODEC_ID_PCM_DVD # PCM DVD. + pcm_f16le = lib.AV_CODEC_ID_PCM_F16LE # PCM F16 little-endian. + pcm_f24le = lib.AV_CODEC_ID_PCM_F24LE # PCM F24 little-endian. + pcm_f32be = lib.AV_CODEC_ID_PCM_F32BE # PCM F32 big-endian. + pcm_f32le = lib.AV_CODEC_ID_PCM_F32LE # PCM F32 little-endian. + pcm_f64be = lib.AV_CODEC_ID_PCM_F64BE # PCM F64 big-endian. + pcm_f64le = lib.AV_CODEC_ID_PCM_F64LE # PCM F64 little-endian. + pcm_lxf = lib.AV_CODEC_ID_PCM_LXF # PCM LXF. + pcm_mulaw = lib.AV_CODEC_ID_PCM_MULAW # PCM μ-law. + pcm_s16be = lib.AV_CODEC_ID_PCM_S16BE # PCM signed 16-bit big-endian. + pcm_s16be_planar = lib.AV_CODEC_ID_PCM_S16BE_PLANAR # PCM signed 16-bit big-endian planar. + pcm_s16le = lib.AV_CODEC_ID_PCM_S16LE # PCM signed 16-bit little-endian. + pcm_s16le_planar = lib.AV_CODEC_ID_PCM_S16LE_PLANAR # PCM signed 16-bit little-endian planar. + pcm_s24be = lib.AV_CODEC_ID_PCM_S24BE # PCM signed 24-bit big-endian. + pcm_s24daud = lib.AV_CODEC_ID_PCM_S24DAUD # PCM signed 24-bit D-Cinema audio. + pcm_s24le = lib.AV_CODEC_ID_PCM_S24LE # PCM signed 24-bit little-endian. + pcm_s24le_planar = lib.AV_CODEC_ID_PCM_S24LE_PLANAR # PCM signed 24-bit little-endian planar. + pcm_s32be = lib.AV_CODEC_ID_PCM_S32BE # PCM signed 32-bit big-endian. + pcm_s32le = lib.AV_CODEC_ID_PCM_S32LE # PCM signed 32-bit little-endian. + pcm_s32le_planar = lib.AV_CODEC_ID_PCM_S32LE_PLANAR # PCM signed 32-bit little-endian planar. + pcm_s64be = lib.AV_CODEC_ID_PCM_S64BE # PCM signed 64-bit big-endian. + pcm_s64le = lib.AV_CODEC_ID_PCM_S64LE # PCM signed 64-bit little-endian. + pcm_s8 = lib.AV_CODEC_ID_PCM_S8 # PCM signed 8-bit. + pcm_s8_planar = lib.AV_CODEC_ID_PCM_S8_PLANAR # PCM signed 8-bit planar. + pcm_u16be = lib.AV_CODEC_ID_PCM_U16BE # PCM unsigned 16-bit big-endian. + pcm_u16le = lib.AV_CODEC_ID_PCM_U16LE # PCM unsigned 16-bit little-endian. + pcm_u24be = lib.AV_CODEC_ID_PCM_U24BE # PCM unsigned 24-bit big-endian. + pcm_u24le = lib.AV_CODEC_ID_PCM_U24LE # PCM unsigned 24-bit little-endian. + pcm_u32be = lib.AV_CODEC_ID_PCM_U32BE # PCM unsigned 32-bit big-endian. + pcm_u32le = lib.AV_CODEC_ID_PCM_U32LE # PCM unsigned 32-bit little-endian. + pcm_u8 = lib.AV_CODEC_ID_PCM_U8 # PCM unsigned 8-bit. + pcm_vidc = lib.AV_CODEC_ID_PCM_VIDC # PCM VIDC. cdef class Container: From ca1d478378cee54a792d8b196140d1cfb476960d Mon Sep 17 00:00:00 2001 From: z-khan Date: Wed, 29 Jan 2025 02:49:11 +1100 Subject: [PATCH 6/8] Update core.pyx change Enum access syntax --- av/container/core.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av/container/core.pyx b/av/container/core.pyx index 52f8ceefe..e2693f573 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -253,7 +253,7 @@ cdef class Container: self.ptr.interrupt_callback.opaque = &self.interrupt_callback_info if acodec is not None: - self.ptr.audio_codec_id = AudioCodec[acodec.upper()] + self.ptr.audio_codec_id = AudioCodec.acodec.name.upper() self.ptr.flags |= lib.AVFMT_FLAG_GENPTS self.ptr.opaque = self From a0ac8b0920a8b335c7c9b09bea8c8fc866a958cb Mon Sep 17 00:00:00 2001 From: z-khan Date: Wed, 29 Jan 2025 04:01:49 +1100 Subject: [PATCH 7/8] Update core.pyi with Enum definition --- av/container/core.pyi | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/av/container/core.pyi b/av/container/core.pyi index 7c681b18b..7ba2511cf 100644 --- a/av/container/core.pyi +++ b/av/container/core.pyi @@ -1,4 +1,4 @@ -from enum import Flag +from enum import Flag, IntEnum from fractions import Fraction from pathlib import Path from types import TracebackType @@ -30,6 +30,43 @@ class Flags(Flag): shortest: ClassVar[Flags] auto_bsf: ClassVar[Flags] +class AudioCodec(IntEnum): + none: int + pcm_alaw: int + pcm_bluray: int + pcm_dvd: int + pcm_f16le: int + pcm_f24le: int + pcm_f32be: int + pcm_f32le: int + pcm_f64be: int + pcm_f64le: int + pcm_lxf: int + pcm_mulaw: int + pcm_s16be: int + pcm_s16be_planar: int + pcm_s16le: int + pcm_s16le_planar: int + pcm_s24be: int + pcm_s24daud: int + pcm_s24le: int + pcm_s24le_planar: int + pcm_s32be: int + pcm_s32le: int + pcm_s32le_planar: int + pcm_s64be: int + pcm_s64le: int + pcm_s8: int + pcm_s8_planar: int + pcm_u16be: int + pcm_u16le: int + pcm_u24be: int + pcm_u24le: int + pcm_u32be: int + pcm_u32le: int + pcm_u8: int + pcm_vidc: int + class Container: writeable: bool name: str From 2d5a3cadf7dd0bff2bfc1ef46e1fce67388bd60f Mon Sep 17 00:00:00 2001 From: z-khan Date: Wed, 29 Jan 2025 04:06:59 +1100 Subject: [PATCH 8/8] call reference to Enum with string --- av/container/core.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/av/container/core.pyx b/av/container/core.pyx index e2693f573..3da402f2f 100755 --- a/av/container/core.pyx +++ b/av/container/core.pyx @@ -253,7 +253,7 @@ cdef class Container: self.ptr.interrupt_callback.opaque = &self.interrupt_callback_info if acodec is not None: - self.ptr.audio_codec_id = AudioCodec.acodec.name.upper() + self.ptr.audio_codec_id = getattr(AudioCodec, acodec) self.ptr.flags |= lib.AVFMT_FLAG_GENPTS self.ptr.opaque = self