diff --git a/av/about.py b/av/about.py index 805c1fe62..147085852 100644 --- a/av/about.py +++ b/av/about.py @@ -1 +1 @@ -__version__ = "12.0.1" +__version__ = "12.0.2" diff --git a/av/video/frame.pyi b/av/video/frame.pyi index 3de6b454e..1127f86d4 100644 --- a/av/video/frame.pyi +++ b/av/video/frame.pyi @@ -32,11 +32,14 @@ class VideoFrame(Frame): def from_image(img: Image.Image) -> VideoFrame: ... @staticmethod def from_ndarray(array: np.ndarray, format: str = "rgb24") -> VideoFrame: ... + @staticmethod + def from_numpy_buffer(array: np.ndarray, format: str = "rgb24"): ... + def __init__( self, name: str, width: int = 0, height: int = 0, format: str = "yuv420p" ): ... def to_image(self, **kwargs) -> Image.Image: ... - def to_ndarray(self, **kwargs) -> np.ndarray: ... + def to_ndarray(self, enable_fast_path: bool = False, **kwargs) -> np.ndarray: ... def reformat( self, width: int | None = None, diff --git a/av/video/frame.pyx b/av/video/frame.pyx index e13b49807..cb20defa4 100644 --- a/av/video/frame.pyx +++ b/av/video/frame.pyx @@ -241,7 +241,7 @@ cdef class VideoFrame(Frame): return Image.frombytes("RGB", (plane.width, plane.height), bytes(o_buf), "raw", "RGB", 0, 1) - def to_ndarray(self, **kwargs): + def to_ndarray(self, enable_fast_path=False, **kwargs): """Get a numpy array of this frame. Any ``**kwargs`` are passed to :meth:`.VideoReformatter.reformat`. @@ -264,6 +264,7 @@ cdef class VideoFrame(Frame): assert frame.height % 2 == 0 # Fast path for the case that the entire YUV data is contiguous if ( + enable_fast_path and frame.planes[0].line_size == frame.planes[0].width and frame.planes[1].line_size == frame.planes[1].width and frame.planes[2].line_size == frame.planes[2].width