Last active
June 22, 2024 20:19
-
-
Save Arcensoth/a6051dbab173fda208c3eae226a62b3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# gif2mp4.py | |
# Bulk convert a folder of GIFs into MP4s | |
# | |
# Requirements: | |
# - Python 3.8+ | |
# - pip install MoviePy | |
# | |
# Usage: | |
# python3 gif2mp4.py <path/to/gifs> [optional/path/to/output] | |
# | |
# Source: | |
# https://gist.github.com/Arcensoth/a6051dbab173fda208c3eae226a62b3f | |
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 / node.name).with_suffix(".mp4") | |
print(f" to MP4: {node_out}") | |
with VideoFileClip(str(node)) as clip: | |
clip.write_videofile(str(node_out)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment