Skip to content

Commit c2a197f

Browse files
committed
Make VideoFormat.components lazy
1 parent 900e39b commit c2a197f

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

av/video/format.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cdef class VideoFormat:
55
cdef lib.AVPixelFormat pix_fmt
66
cdef const lib.AVPixFmtDescriptor *ptr
77
cdef readonly unsigned int width, height
8-
cdef readonly tuple components
98
cdef _init(self, lib.AVPixelFormat pix_fmt, unsigned int width, unsigned int height)
109
cpdef chroma_width(self, int luma_width=?)
1110
cpdef chroma_height(self, int luma_height=?)

av/video/format.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ def _init(self, pix_fmt: lib.AVPixelFormat, width: cuint, height: cuint):
5555
self.ptr = lib.av_pix_fmt_desc_get(pix_fmt)
5656
self.width = width
5757
self.height = height
58-
self.components = tuple(
59-
VideoFormatComponent(self, i) for i in range(self.ptr.nb_components)
60-
)
6158

6259
def __repr__(self):
6360
if self.width or self.height:
@@ -73,6 +70,12 @@ def name(self):
7370
"""Canonical name of the pixel format."""
7471
return cython.cast(str, self.ptr.name)
7572

73+
@property
74+
def components(self):
75+
return tuple(
76+
VideoFormatComponent(self, i) for i in range(self.ptr.nb_components)
77+
)
78+
7679
@property
7780
def bits_per_pixel(self):
7881
return lib.av_get_bits_per_pixel(self.ptr)

av/video/format.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ class VideoFormat:
66
has_palette: bool
77
is_bit_stream: bool
88
is_planar: bool
9+
width: int
10+
height: int
11+
@property
12+
def components(self) -> tuple[VideoFormatComponent, ...]: ...
913
@property
1014
def is_rgb(self) -> bool: ...
1115
@property
1216
def is_bayer(self) -> bool: ...
13-
width: int
14-
height: int
15-
components: tuple[VideoFormatComponent, ...]
16-
1717
def __init__(self, name: str, width: int = 0, height: int = 0) -> None: ...
1818
def chroma_width(self, luma_width: int = 0) -> int: ...
1919
def chroma_height(self, luma_height: int = 0) -> int: ...

0 commit comments

Comments
 (0)