(
video_frames: list[np.ndarray] | list[PIL.Image.Image], output_video_path: str = None, fps: int = 10
)
| 112 | |
| 113 | |
| 114 | def _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 | |
| 140 | def export_to_video( |
no test coverage detected
searching dependent graphs…