Skip to content

Instantly share code, notes, and snippets.

Last active Jan 7, 2022
What would you like to do?
#!/usr/bin/env python3
# Bulk convert a folder of GIFs into MP4s
# Requirements:
# - Python 3.8+
# - pip install MoviePy
# Usage:
# python3 <path/to/gifs> [optional/path/to/output]
# Source:
import sys
from pathlib import Path
from moviepy.editor import VideoFileClip
in_dir_name = sys.argv[1]
in_dir_path = Path(in_dir_name).absolute()
out_dir_name = sys.argv[2] if len(sys.argv) > 2 else None
out_dir_path = Path(out_dir_name).absolute() if out_dir_name is not None else in_dir_path
print(f"Converting GIFs in: {in_dir_path}")
print(f" to MP4s in: {out_dir_path}")
for node in in_dir_path.glob('**/*.gif'):
if node.is_file():
print(f"Converting GIF: {node}")
node_out = (out_dir_path /".mp4")
print(f" to MP4: {node_out}")
with VideoFileClip(str(node)) as clip:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment