Skip to content

Commit 8e973ab

Browse files
daveisferaWyattBlue
authored andcommitted
Add set_image for updating the image content of an existing frame
1 parent 93a1005 commit 8e973ab

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

av/video/frame.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,22 @@ def to_ndarray(self, channel_last=False, **kwargs):
610610
f"Conversion to numpy array with format `{frame.format.name}` is not yet supported"
611611
)
612612

613-
@staticmethod
614-
def from_image(img):
613+
def set_image(self, img):
615614
"""
616-
Construct a frame from a ``PIL.Image``.
615+
Update content from a ``PIL.Image``.
617616
"""
618617
if img.mode != "RGB":
619618
img = img.convert("RGB")
620619

620+
copy_array_to_plane(img, self.planes[0], 3)
621+
622+
@staticmethod
623+
def from_image(img):
624+
"""
625+
Construct a frame from a ``PIL.Image``.
626+
"""
621627
frame: VideoFrame = VideoFrame(img.size[0], img.size[1], "rgb24")
622-
copy_array_to_plane(img, frame.planes[0], 3)
628+
frame.set_image(img)
623629

624630
return frame
625631

0 commit comments

Comments
 (0)