From 9c9eece453ed07d4b80addd7b0ca47993af91d94 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Sun, 24 Nov 2024 00:56:09 -0500 Subject: [PATCH] `skip_frame`: Use str literals instead of Enum --- av/codec/context.pyi | 13 +++-------- av/codec/context.pyx | 53 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/av/codec/context.pyi b/av/codec/context.pyi index 8b7458597..e58b0879d 100644 --- a/av/codec/context.pyi +++ b/av/codec/context.pyi @@ -15,15 +15,6 @@ class ThreadType(Flag): def __get__(self, i: object | None, owner: type | None = None) -> ThreadType: ... def __set__(self, instance: object, value: int | str | ThreadType) -> None: ... -class SkipType(Enum): - NONE: ClassVar[SkipType] - DEFAULT: ClassVar[SkipType] - NONREF: ClassVar[SkipType] - BIDIR: ClassVar[SkipType] - NONINTRA: ClassVar[SkipType] - NONKEY: ClassVar[SkipType] - ALL: ClassVar[SkipType] - class Flags(EnumFlag): NONE: int UNALIGNED: int @@ -71,7 +62,9 @@ class CodecContext: bit_rate_tolerance: int thread_count: int thread_type: ThreadType - skip_frame: SkipType + skip_frame: Literal[ + "NONE", "DEFAULT", "NONREF", "BIDIR", "NONINTRA", "NONKEY", "ALL" + ] # flags unaligned: bool diff --git a/av/codec/context.pyx b/av/codec/context.pyx index 6e039a4e1..f420b1157 100644 --- a/av/codec/context.pyx +++ b/av/codec/context.pyx @@ -47,14 +47,6 @@ class ThreadType(Flag): SLICE: "Decode more than one part of a single frame at once" = lib.FF_THREAD_SLICE AUTO: "Decode using both FRAME and SLICE methods." = lib.FF_THREAD_SLICE | lib.FF_THREAD_FRAME -class SkipType(Enum): - NONE: "Discard nothing" = lib.AVDISCARD_NONE - DEFAULT: "Discard useless packets like 0 size packets in AVI" = lib.AVDISCARD_DEFAULT - NONREF: "Discard all non reference" = lib.AVDISCARD_NONREF - BIDIR: "Discard all bidirectional frames" = lib.AVDISCARD_BIDIR - NONINTRA: "Discard all non intra frames" = lib.AVDISCARD_NONINTRA - NONKEY: "Discard all frames except keyframes" = lib.AVDISCARD_NONKEY - ALL: "Discard all" = lib.AVDISCARD_ALL Flags = define_enum("Flags", __name__, ( ("NONE", 0), @@ -630,16 +622,53 @@ cdef class CodecContext: @property def skip_frame(self): - """One of :class:`.SkipType`. + """Returns one of the following str literals: - Wraps :ffmpeg:`AVCodecContext.skip_frame`. + "NONE" Discard nothing + "DEFAULT" Discard useless packets like 0 size packets in AVI + "NONREF" Discard all non reference + "BIDIR" Discard all bidirectional frames + "NONINTRA" Discard all non intra frames + "NONKEY Discard all frames except keyframes + "ALL" Discard all + Wraps :ffmpeg:`AVCodecContext.skip_frame`. """ - return SkipType(self.ptr.skip_frame) + value = self.ptr.skip_frame + if value == lib.AVDISCARD_NONE: + return "NONE" + if value == lib.AVDISCARD_DEFAULT: + return "DEFAULT" + if value == lib.AVDISCARD_NONREF: + return "NONREF" + if value == lib.AVDISCARD_BIDIR: + return "BIDIR" + if value == lib.AVDISCARD_NONINTRA: + return "NONINTRA" + if value == lib.AVDISCARD_NONKEY: + return "NONKEY" + if value == lib.AVDISCARD_ALL: + return "ALL" + return f"{value}" @skip_frame.setter def skip_frame(self, value): - self.ptr.skip_frame = value.value + if value == "NONE": + self.ptr.skip_frame = lib.AVDISCARD_NONE + elif value == "DEFAULT": + self.ptr.skip_frame = lib.AVDISCARD_DEFAULT + elif value == "NONREF": + self.ptr.skip_frame = lib.AVDISCARD_NONREF + elif value == "BIDIR": + self.ptr.skip_frame = lib.AVDISCARD_BIDIR + elif value == "NONINTRA": + self.ptr.skip_frame = lib.AVDISCARD_NONINTRA + elif value == "NONKEY": + self.ptr.skip_frame = lib.AVDISCARD_NONKEY + elif value == "ALL": + self.ptr.skip_frame = lib.AVDISCARD_ALL + else: + raise ValueError("Invalid skip_frame type") @property def delay(self):