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