quality: Video output quality. Default is 5. Uses variable bit rate. Highest quality is 10, lowest is 0. Set to None to prevent variable bitrate flags to FFMPEG so you can manually specify them using output_params instead. Specifying a fixed bitrate using `bitrate` disab
(
video_frames: list[np.ndarray] | list[PIL.Image.Image],
output_video_path: str = None,
fps: int = 10,
quality: float = 5.0,
bitrate: int | None = None,
macro_block_size: int | None = 16,
)
| 138 | |
| 139 | |
| 140 | def export_to_video( |
| 141 | video_frames: list[np.ndarray] | list[PIL.Image.Image], |
| 142 | output_video_path: str = None, |
| 143 | fps: int = 10, |
| 144 | quality: float = 5.0, |
| 145 | bitrate: int | None = None, |
| 146 | macro_block_size: int | None = 16, |
| 147 | ) -> str: |
| 148 | """ |
| 149 | quality: |
| 150 | Video output quality. Default is 5. Uses variable bit rate. Highest quality is 10, lowest is 0. Set to None to |
| 151 | prevent variable bitrate flags to FFMPEG so you can manually specify them using output_params instead. |
| 152 | Specifying a fixed bitrate using `bitrate` disables this parameter. |
| 153 | |
| 154 | bitrate: |
| 155 | Set a constant bitrate for the video encoding. Default is None causing `quality` parameter to be used instead. |
| 156 | Better quality videos with smaller file sizes will result from using the `quality` variable bitrate parameter |
| 157 | rather than specifying a fixed bitrate with this parameter. |
| 158 | |
| 159 | macro_block_size: |
| 160 | Size constraint for video. Width and height, must be divisible by this number. If not divisible by this number |
| 161 | imageio will tell ffmpeg to scale the image up to the next closest size divisible by this number. Most codecs |
| 162 | are compatible with a macroblock size of 16 (default), some can go smaller (4, 8). To disable this automatic |
| 163 | feature set it to None or 1, however be warned many players can't decode videos that are odd in size and some |
| 164 | codecs will produce poor results or fail. See https://en.wikipedia.org/wiki/Macroblock. |
| 165 | """ |
| 166 | # TODO: Dhruv. Remove by Diffusers release 0.33.0 |
| 167 | # Added to prevent breaking existing code |
| 168 | if not is_imageio_available(): |
| 169 | logger.warning( |
| 170 | ( |
| 171 | "It is recommended to use `export_to_video` with `imageio` and `imageio-ffmpeg` as a backend. \n" |
| 172 | "These libraries are not present in your environment. Attempting to use legacy OpenCV backend to export video. \n" |
| 173 | "Support for the OpenCV backend will be deprecated in a future Diffusers version" |
| 174 | ) |
| 175 | ) |
| 176 | return _legacy_export_to_video(video_frames, output_video_path, fps) |
| 177 | |
| 178 | if is_imageio_available(): |
| 179 | import imageio |
| 180 | else: |
| 181 | raise ImportError(BACKENDS_MAPPING["imageio"][1].format("export_to_video")) |
| 182 | |
| 183 | try: |
| 184 | imageio.plugins.ffmpeg.get_exe() |
| 185 | except AttributeError: |
| 186 | raise AttributeError( |
| 187 | ( |
| 188 | "Found an existing imageio backend in your environment. Attempting to export video with imageio. \n" |
| 189 | "Unable to find a compatible ffmpeg installation in your environment to use with imageio. Please install via `pip install imageio-ffmpeg" |
| 190 | ) |
| 191 | ) |
| 192 | |
| 193 | if output_video_path is None: |
| 194 | output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name |
| 195 | |
| 196 | if isinstance(video_frames[0], np.ndarray): |
| 197 | video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames] |
nothing calls this directly
no test coverage detected
searching dependent graphs…