MCPcopy Index your code
hub / github.com/huggingface/diffusers / _legacy_export_to_video

Function _legacy_export_to_video

src/diffusers/utils/export_utils.py:114–137  ·  view source on GitHub ↗
(
    video_frames: list[np.ndarray] | list[PIL.Image.Image], output_video_path: str = None, fps: int = 10
)

Source from the content-addressed store, hash-verified

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

Callers 1

export_to_videoFunction · 0.85

Calls 1

is_opencv_availableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…