Skip to content

Commit

Permalink
Make PictureType an IntEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 13, 2024
1 parent 16c2517 commit d9436b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
18 changes: 11 additions & 7 deletions av/video/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Union
from enum import IntEnum
from typing import Any, ClassVar, Union

import numpy as np
from PIL import Image

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

from .format import VideoFormat
Expand All @@ -15,7 +15,7 @@ _SupportedNDarray = Union[
np.ndarray[Any, np.dtype[np.float32]],
]

class PictureType(EnumItem):
class PictureType(IntEnum):
NONE: int
I: int
P: int
Expand All @@ -28,15 +28,19 @@ class PictureType(EnumItem):
class VideoFrame(Frame):
format: VideoFormat
pts: int
time: float
planes: tuple[VideoPlane, ...]
width: int
height: int
interlaced_frame: bool
pict_type: int
colorspace: int
color_range: int

@property
def time(self) -> float: ...
@property
def width(self) -> int: ...
@property
def height(self) -> int: ...
@property
def interlaced_frame(self) -> bool: ...
def __init__(
self, width: int = 0, height: int = 0, format: str = "yuv420p"
) -> None: ...
Expand Down
32 changes: 15 additions & 17 deletions av/video/frame.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
from enum import IntEnum

from libc.stdint cimport uint8_t

from av.enum cimport define_enum
from av.error cimport err_check
from av.utils cimport check_ndarray
from av.video.format cimport get_pix_fmt, get_video_format
Expand All @@ -20,18 +20,15 @@ cdef VideoFrame alloc_video_frame():
"""
return VideoFrame.__new__(VideoFrame, _cinit_bypass_sentinel)


PictureType = define_enum("PictureType", __name__, (
("NONE", lib.AV_PICTURE_TYPE_NONE, "Undefined"),
("I", lib.AV_PICTURE_TYPE_I, "Intra"),
("P", lib.AV_PICTURE_TYPE_P, "Predicted"),
("B", lib.AV_PICTURE_TYPE_B, "Bi-directional predicted"),
("S", lib.AV_PICTURE_TYPE_S, "S(GMC)-VOP MPEG-4"),
("SI", lib.AV_PICTURE_TYPE_SI, "Switching intra"),
("SP", lib.AV_PICTURE_TYPE_SP, "Switching predicted"),
("BI", lib.AV_PICTURE_TYPE_BI, "BI type"),
))

class PictureType(IntEnum):
NONE = lib.AV_PICTURE_TYPE_NONE # Undefined
I = lib.AV_PICTURE_TYPE_I # Intra
P = lib.AV_PICTURE_TYPE_P # Predicted
B = lib.AV_PICTURE_TYPE_B # Bi-directional predicted
S = lib.AV_PICTURE_TYPE_S # S(GMC)-VOP MPEG-4
SI = lib.AV_PICTURE_TYPE_SI # Switching intra
SP = lib.AV_PICTURE_TYPE_SP # Switching predicted
BI = lib.AV_PICTURE_TYPE_BI # BI type

cdef byteswap_array(array, bint big_endian):
if (sys.byteorder == "big") != big_endian:
Expand Down Expand Up @@ -183,16 +180,17 @@ cdef class VideoFrame(Frame):

@property
def pict_type(self):
"""One of :class:`.PictureType`.
"""Returns an integer that corresponds to the PictureType enum.
Wraps :ffmpeg:`AVFrame.pict_type`.
Wraps :ffmpeg:`AVFrame.pict_type`
:type: int
"""
return PictureType.get(self.ptr.pict_type, create=True)
return self.ptr.pict_type

@pict_type.setter
def pict_type(self, value):
self.ptr.pict_type = PictureType[value].value
self.ptr.pict_type = value

@property
def colorspace(self):
Expand Down

0 comments on commit d9436b9

Please sign in to comment.