From 4bd7983164e4350361d82264217d6e4629aa6b6c Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Sun, 22 Mar 2026 01:28:09 -0400 Subject: [PATCH] Make VideoFormat.components lazy --- av/video/format.pxd | 1 - av/video/format.py | 9 ++++++--- av/video/format.pyi | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/av/video/format.pxd b/av/video/format.pxd index 2c6323294..679525a2a 100644 --- a/av/video/format.pxd +++ b/av/video/format.pxd @@ -5,7 +5,6 @@ cdef class VideoFormat: cdef lib.AVPixelFormat pix_fmt cdef const lib.AVPixFmtDescriptor *ptr cdef readonly unsigned int width, height - cdef readonly tuple components cdef _init(self, lib.AVPixelFormat pix_fmt, unsigned int width, unsigned int height) cpdef chroma_width(self, int luma_width=?) cpdef chroma_height(self, int luma_height=?) diff --git a/av/video/format.py b/av/video/format.py index dbc37ed64..4b6291e71 100644 --- a/av/video/format.py +++ b/av/video/format.py @@ -55,9 +55,6 @@ def _init(self, pix_fmt: lib.AVPixelFormat, width: cuint, height: cuint): self.ptr = lib.av_pix_fmt_desc_get(pix_fmt) self.width = width self.height = height - self.components = tuple( - VideoFormatComponent(self, i) for i in range(self.ptr.nb_components) - ) def __repr__(self): if self.width or self.height: @@ -73,6 +70,12 @@ def name(self): """Canonical name of the pixel format.""" return cython.cast(str, self.ptr.name) + @property + def components(self): + return tuple( + VideoFormatComponent(self, i) for i in range(self.ptr.nb_components) + ) + @property def bits_per_pixel(self): return lib.av_get_bits_per_pixel(self.ptr) diff --git a/av/video/format.pyi b/av/video/format.pyi index e102ef4c0..1ee0bc7a7 100644 --- a/av/video/format.pyi +++ b/av/video/format.pyi @@ -6,14 +6,14 @@ class VideoFormat: has_palette: bool is_bit_stream: bool is_planar: bool + width: int + height: int + @property + def components(self) -> tuple[VideoFormatComponent, ...]: ... @property def is_rgb(self) -> bool: ... @property def is_bayer(self) -> bool: ... - width: int - height: int - components: tuple[VideoFormatComponent, ...] - def __init__(self, name: str, width: int = 0, height: int = 0) -> None: ... def chroma_width(self, luma_width: int = 0) -> int: ... def chroma_height(self, luma_height: int = 0) -> int: ...