Export a list of frames to a GIF. Args: - frames (list): List of frames (as numpy arrays or PIL Image objects). - output_gif_path (str): Path to save the output GIF. - duration_ms (int): Duration of each frame in milliseconds.
(frames, output_gif_path, fps)
| 348 | |
| 349 | |
| 350 | def export_to_gif(frames, output_gif_path, fps): |
| 351 | """ |
| 352 | Export a list of frames to a GIF. |
| 353 | |
| 354 | Args: |
| 355 | - frames (list): List of frames (as numpy arrays or PIL Image objects). |
| 356 | - output_gif_path (str): Path to save the output GIF. |
| 357 | - duration_ms (int): Duration of each frame in milliseconds. |
| 358 | |
| 359 | """ |
| 360 | # Convert numpy arrays to PIL Images if needed |
| 361 | pil_frames = [Image.fromarray(frame) if isinstance( |
| 362 | frame, np.ndarray) else frame for frame in frames] |
| 363 | |
| 364 | pil_frames[0].save(output_gif_path.replace('.mp4', '.gif'), |
| 365 | format='GIF', |
| 366 | append_images=pil_frames[1:], |
| 367 | save_all=True, |
| 368 | duration=125, |
| 369 | loop=0) |
| 370 | |
| 371 | |
| 372 | def tensor_to_vae_latent(t, vae, scale=True): |