Skip to content

Commit caaddbf

Browse files
committed
Make PictureType an IntEnum
1 parent 16c2517 commit caaddbf

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

av/video/frame.pyi

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Any, Union
1+
from enum import IntEnum
2+
from typing import Any, ClassVar, Union
23

34
import numpy as np
45
from PIL import Image
56

6-
from av.enum import EnumItem
77
from av.frame import Frame
88

99
from .format import VideoFormat
@@ -15,7 +15,7 @@ _SupportedNDarray = Union[
1515
np.ndarray[Any, np.dtype[np.float32]],
1616
]
1717

18-
class PictureType(EnumItem):
18+
class PictureType(IntEnum):
1919
NONE: int
2020
I: int
2121
P: int
@@ -28,15 +28,19 @@ class PictureType(EnumItem):
2828
class VideoFrame(Frame):
2929
format: VideoFormat
3030
pts: int
31-
time: float
3231
planes: tuple[VideoPlane, ...]
33-
width: int
34-
height: int
35-
interlaced_frame: bool
3632
pict_type: int
3733
colorspace: int
3834
color_range: int
3935

36+
@property
37+
def time(self) -> float: ...
38+
@property
39+
def width(self) -> int: ...
40+
@property
41+
def height(self) -> int: ...
42+
@property
43+
def interlaced_frame(self) -> bool: ...
4044
def __init__(
4145
self, width: int = 0, height: int = 0, format: str = "yuv420p"
4246
) -> None: ...

av/video/frame.pyx

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
2+
from enum import IntEnum
23

34
from libc.stdint cimport uint8_t
45

5-
from av.enum cimport define_enum
66
from av.error cimport err_check
77
from av.utils cimport check_ndarray
88
from av.video.format cimport get_pix_fmt, get_video_format
@@ -20,18 +20,15 @@ cdef VideoFrame alloc_video_frame():
2020
"""
2121
return VideoFrame.__new__(VideoFrame, _cinit_bypass_sentinel)
2222

23-
24-
PictureType = define_enum("PictureType", __name__, (
25-
("NONE", lib.AV_PICTURE_TYPE_NONE, "Undefined"),
26-
("I", lib.AV_PICTURE_TYPE_I, "Intra"),
27-
("P", lib.AV_PICTURE_TYPE_P, "Predicted"),
28-
("B", lib.AV_PICTURE_TYPE_B, "Bi-directional predicted"),
29-
("S", lib.AV_PICTURE_TYPE_S, "S(GMC)-VOP MPEG-4"),
30-
("SI", lib.AV_PICTURE_TYPE_SI, "Switching intra"),
31-
("SP", lib.AV_PICTURE_TYPE_SP, "Switching predicted"),
32-
("BI", lib.AV_PICTURE_TYPE_BI, "BI type"),
33-
))
34-
23+
class PictureType(IntEnum):
24+
NONE = lib.AV_PICTURE_TYPE_NONE # Undefined
25+
I = lib.AV_PICTURE_TYPE_I # Intra
26+
P = lib.AV_PICTURE_TYPE_P # Predicted
27+
B = lib.AV_PICTURE_TYPE_B # Bi-directional predicted
28+
S = lib.AV_PICTURE_TYPE_S # S(GMC)-VOP MPEG-4
29+
SI = lib.AV_PICTURE_TYPE_SI # Switching intra
30+
SP = lib.AV_PICTURE_TYPE_SP # Switching predicted
31+
BI = lib.AV_PICTURE_TYPE_BI # BI type
3532

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

184181
@property
185182
def pict_type(self):
186-
"""One of :class:`.PictureType`.
183+
"""Returns an integer that corresponds to the PictureType enum.
187184
188-
Wraps :ffmpeg:`AVFrame.pict_type`.
185+
Wraps :ffmpeg:`AVFrame.pict_type`
189186
187+
:type: int
190188
"""
191-
return PictureType.get(self.ptr.pict_type, create=True)
189+
return self.ptr.pict_type
192190

193191
@pict_type.setter
194192
def pict_type(self, value):
195-
self.ptr.pict_type = PictureType[value].value
193+
self.ptr.pict_type = value
196194

197195
@property
198196
def colorspace(self):

0 commit comments

Comments
 (0)