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)
| 56 | |
| 57 | |
| 58 | def export_to_gif(frames, output_gif_path, fps): |
| 59 | """ |
| 60 | Export a list of frames to a GIF. |
| 61 | |
| 62 | Args: |
| 63 | - frames (list): List of frames (as numpy arrays or PIL Image objects). |
| 64 | - output_gif_path (str): Path to save the output GIF. |
| 65 | - duration_ms (int): Duration of each frame in milliseconds. |
| 66 | |
| 67 | """ |
| 68 | # Convert numpy arrays to PIL Images if needed |
| 69 | pil_frames = [Image.fromarray(frame) if isinstance( |
| 70 | frame, np.ndarray) else frame for frame in frames] |
| 71 | |
| 72 | pil_frames[0].save(output_gif_path.replace('.mp4', '.gif'), |
| 73 | format='GIF', |
| 74 | append_images=pil_frames[1:], |
| 75 | save_all=True, |
| 76 | duration=125, |
| 77 | loop=0) |
| 78 | |
| 79 | def parse_args(): |
| 80 | parser = argparse.ArgumentParser( |