MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / export_to_video

Function export_to_video

src/diffusers/utils/export_utils.py:118–140  ·  view source on GitHub ↗
(
    video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 8
)

Source from the content-addressed store, hash-verified

116
117
118def export_to_video(
119 video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 8
120) -> str:
121 if is_opencv_available():
122 import cv2
123 else:
124 raise ImportError(BACKENDS_MAPPING["opencv"][1].format("export_to_video"))
125 if output_video_path is None:
126 output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name
127
128 if isinstance(video_frames[0], np.ndarray):
129 video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames]
130
131 elif isinstance(video_frames[0], PIL.Image.Image):
132 video_frames = [np.array(frame) for frame in video_frames]
133
134 fourcc = cv2.VideoWriter_fourcc(*"mp4v")
135 h, w, c = video_frames[0].shape
136 video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=fps, frameSize=(w, h))
137 for i in range(len(video_frames)):
138 img = cv2.cvtColor(video_frames[i], cv2.COLOR_RGB2BGR)
139 video_writer.write(img)
140 return output_video_path

Callers

nothing calls this directly

Calls 1

is_opencv_availableFunction · 0.85

Tested by

no test coverage detected