From 773243c60f2d5b9ac7acf5641adedcbeb8c0d358 Mon Sep 17 00:00:00 2001 From: Dave Johansen Date: Mon, 21 Jul 2025 18:25:09 -0600 Subject: [PATCH] Add set_image for updating the image content of an existing frame --- av/video/frame.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/av/video/frame.py b/av/video/frame.py index 970ecc4b8..0d60fd8e9 100644 --- a/av/video/frame.py +++ b/av/video/frame.py @@ -610,16 +610,22 @@ def to_ndarray(self, channel_last=False, **kwargs): f"Conversion to numpy array with format `{frame.format.name}` is not yet supported" ) - @staticmethod - def from_image(img): + def set_image(self, img): """ - Construct a frame from a ``PIL.Image``. + Update content from a ``PIL.Image``. """ if img.mode != "RGB": img = img.convert("RGB") + copy_array_to_plane(img, self.planes[0], 3) + + @staticmethod + def from_image(img): + """ + Construct a frame from a ``PIL.Image``. + """ frame: VideoFrame = VideoFrame(img.size[0], img.size[1], "rgb24") - copy_array_to_plane(img, frame.planes[0], 3) + frame.set_image(img) return frame