MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / export_to_video

Function export_to_video

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

Source from the content-addressed store, hash-verified

139
140
141def export_to_video(
142 video_frames: Union[List[np.ndarray], List[PIL.Image.Image]], output_video_path: str = None, fps: int = 10
143) -> str:
144 # TODO: Dhruv. Remove by Diffusers release 0.33.0
145 # Added to prevent breaking existing code
146 if not is_imageio_available():
147 logger.warning(
148 (
149 "It is recommended to use `export_to_video` with `imageio` and `imageio-ffmpeg` as a backend. \n"
150 "These libraries are not present in your environment. Attempting to use legacy OpenCV backend to export video. \n"
151 "Support for the OpenCV backend will be deprecated in a future Diffusers version"
152 )
153 )
154 return _legacy_export_to_video(video_frames, output_video_path, fps)
155
156 if is_imageio_available():
157 import imageio
158 else:
159 raise ImportError(BACKENDS_MAPPING["imageio"][1].format("export_to_video"))
160
161 try:
162 imageio.plugins.ffmpeg.get_exe()
163 except AttributeError:
164 raise AttributeError(
165 (
166 "Found an existing imageio backend in your environment. Attempting to export video with imageio. \n"
167 "Unable to find a compatible ffmpeg installation in your environment to use with imageio. Please install via `pip install imageio-ffmpeg"
168 )
169 )
170
171 if output_video_path is None:
172 output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name
173
174 if isinstance(video_frames[0], np.ndarray):
175 video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames]
176
177 elif isinstance(video_frames[0], PIL.Image.Image):
178 video_frames = [np.array(frame) for frame in video_frames]
179
180 with imageio.get_writer(output_video_path, fps=fps) as writer:
181 for frame in video_frames:
182 writer.append_data(frame)
183
184 return output_video_path

Callers 2

save_model_cardFunction · 0.90
log_validationFunction · 0.90

Calls 2

is_imageio_availableFunction · 0.85
_legacy_export_to_videoFunction · 0.85

Tested by

no test coverage detected