From 48f9eb3ec772e01a2a04e077ebac2e0ea424d9d1 Mon Sep 17 00:00:00 2001 From: Jacob Segal Date: Sun, 27 Apr 2025 21:56:43 -0700 Subject: [PATCH] Make sure bytesIO objects can be read many times --- comfy/comfy_types/input_types.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/comfy/comfy_types/input_types.py b/comfy/comfy_types/input_types.py index 31c7e83a0..47be005b9 100644 --- a/comfy/comfy_types/input_types.py +++ b/comfy/comfy_types/input_types.py @@ -132,6 +132,8 @@ class VideoFromFile(VideoInput): Returns: Tuple of (width, height) """ + if isinstance(self.file, io.BytesIO): + self.file.seek(0) # Reset the BytesIO object to the beginning with av.open(self.file, mode='r') as container: for stream in container.streams: if stream.type == 'video': @@ -180,6 +182,8 @@ class VideoFromFile(VideoInput): return VideoComponents(images=images, audio=audio, frame_rate=frame_rate, metadata=metadata) def get_components(self) -> VideoComponents: + if isinstance(self.file, io.BytesIO): + self.file.seek(0) # Reset the BytesIO object to the beginning with av.open(self.file, mode='r') as container: return self.get_components_internal(container) raise ValueError(f"No video stream found in file '{self.file}'") @@ -191,6 +195,8 @@ class VideoFromFile(VideoInput): codec: VideoCodec = VideoCodec.AUTO, metadata: Optional[dict] = None ): + if isinstance(self.file, io.BytesIO): + self.file.seek(0) # Reset the BytesIO object to the beginning with av.open(self.file, mode='r') as container: container_format = container.format.name video_encoding = container.streams.video[0].codec.name if len(container.streams.video) > 0 else None