Skip to content

Commit

Permalink
Update Sidedata Type Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 13, 2024
1 parent d9436b9 commit 9e58f75
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 53 deletions.
59 changes: 35 additions & 24 deletions av/sidedata/sidedata.pyi
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
from collections.abc import Mapping
from typing import Iterator, Sequence, overload
from enum import Enum
from typing import ClassVar, Iterator, Sequence, overload

from av.buffer import Buffer
from av.enum import EnumItem
from av.frame import Frame

class Type(EnumItem):
PANSCAN: int
A53_CC: int
STEREO3D: int
MATRIXENCODING: int
DOWNMIX_INFO: int
REPLAYGAIN: int
DISPLAYMATRIX: int
AFD: int
MOTION_VECTORS: int
SKIP_SAMPLES: int
AUDIO_SERVICE_TYPE: int
MASTERING_DISPLAY_METADATA: int
GOP_TIMECODE: int
SPHERICAL: int
CONTENT_LIGHT_LEVEL: int
ICC_PROFILE: int
SEI_UNREGISTERED: int
S12M_TIMECODE: int
class Type(Enum):
PANSCAN: ClassVar[Type]
A53_CC: ClassVar[Type]
STEREO3D: ClassVar[Type]
MATRIXENCODING: ClassVar[Type]
DOWNMIX_INFO: ClassVar[Type]
REPLAYGAIN: ClassVar[Type]
DISPLAYMATRIX: ClassVar[Type]
AFD: ClassVar[Type]
MOTION_VECTORS: ClassVar[Type]
SKIP_SAMPLES: ClassVar[Type]
AUDIO_SERVICE_TYPE: ClassVar[Type]
MASTERING_DISPLAY_METADATA: ClassVar[Type]
GOP_TIMECODE: ClassVar[Type]
SPHERICAL: ClassVar[Type]
CONTENT_LIGHT_LEVEL: ClassVar[Type]
ICC_PROFILE: ClassVar[Type]
S12M_TIMECODE: ClassVar[Type]
DYNAMIC_HDR_PLUS: ClassVar[Type]
REGIONS_OF_INTEREST: ClassVar[Type]
VIDEO_ENC_PARAMS: ClassVar[Type]
SEI_UNREGISTERED: ClassVar[Type]
FILM_GRAIN_PARAMS: ClassVar[Type]
DETECTION_BBOXES: ClassVar[Type]
DOVI_RPU_BUFFER: ClassVar[Type]
DOVI_METADATA: ClassVar[Type]
DYNAMIC_HDR_VIVID: ClassVar[Type]
AMBIENT_VIEWING_ENVIRONMENT: ClassVar[Type]
VIDEO_HINT: ClassVar[Type]

class SideData(Buffer):
type: Type
DISPLAYMATRIX: int

class SideDataContainer(Mapping):
frame: Frame
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[SideData]: ...
@overload
def __getitem__(self, key: int) -> SideData: ...
def __getitem__(self, key: str | int | Type) -> SideData: ...
@overload
def __getitem__(self, key: slice) -> Sequence[SideData]: ...
@overload
def __getitem__(self, key: int | slice) -> SideData | Sequence[SideData]: ...
def __getitem__(
self, key: str | int | Type | slice
) -> SideData | Sequence[SideData]: ...
66 changes: 40 additions & 26 deletions av/sidedata/sidedata.pyx
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
from av.enum cimport define_enum

from collections.abc import Mapping
from enum import Enum

from av.sidedata.motionvectors import MotionVectors


cdef object _cinit_bypass_sentinel = object()


Type = define_enum("Type", __name__, (
("PANSCAN", lib.AV_FRAME_DATA_PANSCAN),
("A53_CC", lib.AV_FRAME_DATA_A53_CC),
("STEREO3D", lib.AV_FRAME_DATA_STEREO3D),
("MATRIXENCODING", lib.AV_FRAME_DATA_MATRIXENCODING),
("DOWNMIX_INFO", lib.AV_FRAME_DATA_DOWNMIX_INFO),
("REPLAYGAIN", lib.AV_FRAME_DATA_REPLAYGAIN),
("DISPLAYMATRIX", lib.AV_FRAME_DATA_DISPLAYMATRIX),
("AFD", lib.AV_FRAME_DATA_AFD),
("MOTION_VECTORS", lib.AV_FRAME_DATA_MOTION_VECTORS),
("SKIP_SAMPLES", lib.AV_FRAME_DATA_SKIP_SAMPLES),
("AUDIO_SERVICE_TYPE", lib.AV_FRAME_DATA_AUDIO_SERVICE_TYPE),
("MASTERING_DISPLAY_METADATA", lib.AV_FRAME_DATA_MASTERING_DISPLAY_METADATA),
("GOP_TIMECODE", lib.AV_FRAME_DATA_GOP_TIMECODE),
("SPHERICAL", lib.AV_FRAME_DATA_SPHERICAL),
("CONTENT_LIGHT_LEVEL", lib.AV_FRAME_DATA_CONTENT_LIGHT_LEVEL),
("ICC_PROFILE", lib.AV_FRAME_DATA_ICC_PROFILE),
("SEI_UNREGISTERED", lib.AV_FRAME_DATA_SEI_UNREGISTERED),
("S12M_TIMECODE", lib.AV_FRAME_DATA_S12M_TIMECODE),
))
class Type(Enum):
"""
Enum class representing different types of frame data in audio/video processing.
Values are mapped to corresponding AV_FRAME_DATA constants from FFmpeg.
From: https://github.com/FFmpeg/FFmpeg/blob/master/libavutil/frame.h
"""
PANSCAN = lib.AV_FRAME_DATA_PANSCAN
A53_CC = lib.AV_FRAME_DATA_A53_CC
STEREO3D = lib.AV_FRAME_DATA_STEREO3D
MATRIXENCODING = lib.AV_FRAME_DATA_MATRIXENCODING
DOWNMIX_INFO = lib.AV_FRAME_DATA_DOWNMIX_INFO
REPLAYGAIN = lib.AV_FRAME_DATA_REPLAYGAIN
DISPLAYMATRIX = lib.AV_FRAME_DATA_DISPLAYMATRIX
AFD = lib.AV_FRAME_DATA_AFD
MOTION_VECTORS = lib.AV_FRAME_DATA_MOTION_VECTORS
SKIP_SAMPLES = lib.AV_FRAME_DATA_SKIP_SAMPLES
AUDIO_SERVICE_TYPE = lib.AV_FRAME_DATA_AUDIO_SERVICE_TYPE
MASTERING_DISPLAY_METADATA = lib.AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
GOP_TIMECODE = lib.AV_FRAME_DATA_GOP_TIMECODE
SPHERICAL = lib.AV_FRAME_DATA_SPHERICAL
CONTENT_LIGHT_LEVEL = lib.AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
ICC_PROFILE = lib.AV_FRAME_DATA_ICC_PROFILE
S12M_TIMECODE = lib.AV_FRAME_DATA_S12M_TIMECODE
DYNAMIC_HDR_PLUS = lib.AV_FRAME_DATA_DYNAMIC_HDR_PLUS
REGIONS_OF_INTEREST = lib.AV_FRAME_DATA_REGIONS_OF_INTEREST
VIDEO_ENC_PARAMS = lib.AV_FRAME_DATA_VIDEO_ENC_PARAMS
SEI_UNREGISTERED = lib.AV_FRAME_DATA_SEI_UNREGISTERED
FILM_GRAIN_PARAMS = lib.AV_FRAME_DATA_FILM_GRAIN_PARAMS
DETECTION_BBOXES = lib.AV_FRAME_DATA_DETECTION_BBOXES
DOVI_RPU_BUFFER = lib.AV_FRAME_DATA_DOVI_RPU_BUFFER
DOVI_METADATA = lib.AV_FRAME_DATA_DOVI_METADATA
DYNAMIC_HDR_VIVID = lib.AV_FRAME_DATA_DYNAMIC_HDR_VIVID
AMBIENT_VIEWING_ENVIRONMENT = lib.AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
VIDEO_HINT = lib.AV_FRAME_DATA_VIDEO_HINT


cdef SideData wrap_side_data(Frame frame, int index):
Expand Down Expand Up @@ -60,7 +74,7 @@ cdef class SideData(Buffer):

@property
def type(self):
return Type.get(self.ptr.type) or self.ptr.type
return Type(self.ptr.type)


cdef class _SideDataContainer:
Expand All @@ -85,9 +99,9 @@ cdef class _SideDataContainer:
def __getitem__(self, key):
if isinstance(key, int):
return self._by_index[key]

type_ = Type.get(key)
return self._by_type[type_]
if isinstance(key, str):
return self._by_type[Type[key]]
return self._by_type[key]


class SideDataContainer(_SideDataContainer, Mapping):
Expand Down
14 changes: 11 additions & 3 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,18 @@ cdef extern from "libavcodec/avcodec.h" nogil:
AV_FRAME_DATA_SPHERICAL
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
AV_FRAME_DATA_ICC_PROFILE
AV_FRAME_DATA_QP_TABLE_PROPERTIES
AV_FRAME_DATA_QP_TABLE_DATA
AV_FRAME_DATA_SEI_UNREGISTERED
AV_FRAME_DATA_S12M_TIMECODE
AV_FRAME_DATA_DYNAMIC_HDR_PLUS
AV_FRAME_DATA_REGIONS_OF_INTEREST
AV_FRAME_DATA_VIDEO_ENC_PARAMS
AV_FRAME_DATA_SEI_UNREGISTERED
AV_FRAME_DATA_FILM_GRAIN_PARAMS
AV_FRAME_DATA_DETECTION_BBOXES
AV_FRAME_DATA_DOVI_RPU_BUFFER
AV_FRAME_DATA_DOVI_METADATA
AV_FRAME_DATA_DYNAMIC_HDR_VIVID
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
AV_FRAME_DATA_VIDEO_HINT

cdef struct AVFrameSideData:
AVFrameSideDataType type
Expand Down

0 comments on commit 9e58f75

Please sign in to comment.