Downloads · 30 days
0
algorembrant/vid-to-gif
vid-to-gif is a machine learning model from algorembrant. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
0
Access
Public
Updated Mar 9, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py18.4 KB · 50%
From the Hugging Face model README
A fast, robust, command-line video-to-GIF converter built on a two-pass FFmpeg palette pipeline with optional gifsicle post-compression.
Supports single-file conversion, time-clipping, custom palettes, dithering algorithms, and fully parallelised batch processing.
| Tool | Purpose | Installation |
|---|---|---|
ffmpeg | Video decoding, palette generation, GIF rendering | See ffmpeg.org/download |
| Tool | Purpose | Installation |
|---|---|---|
gifsicle | Post-process GIF compression (level 3) | See lcdf.org/gifsicle |
| Package | Purpose |
|---|---|
tqdm | Progress bars in batch mode |
Pillow | Post-processing / thumbnail generation |
colorlog | Coloured log output |
Linux (Debian/Ubuntu)
sudo apt update && sudo apt install ffmpeg -y
Linux (Fedora/RHEL)
sudo dnf install ffmpeg -y
macOS (Homebrew)
brew install ffmpeg
Windows
C:\ffmpeg).C:\ffmpeg\bin to your system PATH environment variable.ffmpeg -version.Linux (Debian/Ubuntu)
sudo apt install gifsicle -y
macOS
brew install gifsicle
Windows
gifsicle.exe in a folder that is on your PATH.git clone https://github.com/algorembrant/vid2gif.git
cd vid2gif
python -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows
.venv\Scripts\activate
pip install -r requirements.txt
# Convert a video to GIF with default settings
python vid2gif.py input.mp4 output.gif
# Preview what the tool detects
python vid2gif.py --verbose input.mp4 output.gif
usage: vid2gif [-h] [--batch DIR] [--output-dir DIR] [--extensions EXT [EXT ...]]
[--start TIME] [--duration SECS]
[--fps N] [--width PX] [--height PX] [--max-colors N]
[--dither ALG] [--loop N] [--stats-mode {diff,full,single}]
[--quality 1-100] [--no-optimize] [--threads N] [--workers N]
[--verbose]
[input] [output]
| Argument | Description |
|---|---|
input | Path to the input video file |
output | Path for the output GIF (defaults to <input>.gif) |
| Flag | Default | Description |
|---|---|---|
--start TIME / -s TIME | (none) | Start time — HH:MM:SS or seconds (e.g. 5, 00:00:05) |
--duration SECS / -d SECS | (none) | Duration in seconds after the start point |
| Flag | Default | Description |
|---|---|---|
--fps N | 15 | Output frame rate |
--width PX | 640 | Output width in pixels |
--height PX | -1 | Output height (-1 = auto, preserves aspect ratio) |
--max-colors N | 256 | Maximum palette colours (2 - 256) |
--dither ALG | sierra2_4a | Dither algorithm (see table below) |
--loop N | 0 | Loop count (0 = infinite) |
--stats-mode | diff | Palette stats mode: diff, full, or single |
| Flag | Default | Description |
|---|---|---|
--quality 1-100 | 85 | Quality hint passed to the rendering stage |
--no-optimize | false | Disable gifsicle post-compression |
--threads N | 4 | ffmpeg thread count per conversion |
| Flag | Default | Description |
|---|---|---|
--batch DIR | (none) | Directory to scan for video files |
--output-dir DIR | ./gifs | Output directory for batch results |
--extensions EXT... | mp4 mkv mov avi webm flv wmv m4v | File extensions to match in batch mode |
--workers N | 4 | Parallel worker threads for batch conversion |
| Flag | Description |
|---|---|
--verbose / -v | Enable DEBUG-level logging |
--help / -h | Show help and exit |
Point --batch at any directory. vid2gif will discover all matching video files, convert them in parallel, and write results to --output-dir.
python vid2gif.py --batch ./videos/ --output-dir ./gifs/ --workers 8 --fps 12 --width 480
| Algorithm | Notes |
|---|---|
sierra2_4a | Default. Excellent balance of quality and file size |
floyd_steinberg | Classic error-diffusion. High quality, slightly larger |
sierra2 | Slightly smoother than sierra2_4a |
bayer | Ordered dither. Fast, lower quality |
bayer:bayer_scale=1..5 | Bayer with scale control (1 = fine, 5 = coarse) |
heckbert | Median-cut based, good for flat-colour content |
none | No dithering. Fastest, lowest quality |
# 1. Simple conversion (default settings)
python vid2gif.py clip.mp4 clip.gif
# 2. High frame rate, wide output
python vid2gif.py clip.mp4 clip.gif --fps 30 --width 1280
# 3. Extract a 10-second segment starting at 1 minute 30 seconds
python vid2gif.py clip.mp4 clip.gif --start 00:01:30 --duration 10
# 4. Extract using raw seconds
python vid2gif.py clip.mp4 clip.gif --start 90 --duration 10
# 5. Lower quality for small file size
python vid2gif.py clip.mp4 clip.gif --fps 10 --width 320 --max-colors 64 --dither none
# 6. Maximum quality
python vid2gif.py clip.mp4 clip.gif --fps 30 --width 1080 --max-colors 256 --dither floyd_steinberg --stats-mode full
# 7. Skip gifsicle optimization (faster, larger output)
python vid2gif.py clip.mp4 clip.gif --no-optimize
# 8. Square output (fixed height and width)
python vid2gif.py clip.mp4 clip.gif --width 480 --height 480
# 9. Play once, do not loop
python vid2gif.py clip.mp4 clip.gif --loop 1
# 10. Play three times then stop
python vid2gif.py clip.mp4 clip.gif --loop 3
# 11. Batch convert an entire folder
python vid2gif.py --batch ./raw/ --output-dir ./output/ --fps 15 --width 600
# 12. Batch with specific extensions only
python vid2gif.py --batch ./raw/ --output-dir ./output/ --extensions mp4 mov
# 13. Batch with maximum parallelism
python vid2gif.py --batch ./raw/ --output-dir ./output/ --workers 16
# 14. Verbose / debug mode
python vid2gif.py clip.mp4 clip.gif --verbose
# 15. Bayer dithering at scale 3
python vid2gif.py clip.mp4 clip.gif --dither "bayer:bayer_scale=3"
# 16. Convert MKV with 8 ffmpeg threads
python vid2gif.py movie.mkv movie.gif --threads 8
# 17. WebM source
python vid2gif.py screencast.webm screencast.gif --fps 20 --width 900
# 18. Auto-name output (same name, .gif extension)
python vid2gif.py clip.mp4
# 19. Use diff palette stats mode (default, great for motion)
python vid2gif.py clip.mp4 clip.gif --stats-mode diff
# 20. Use full palette stats mode (better for static scenes)
python vid2gif.py clip.mp4 clip.gif --stats-mode full
--threads matching your CPU core count for single conversions.--workers to the number of simultaneous conversions. Each worker itself uses --threads ffmpeg threads, so set workers * threads <= CPU_cores.--stats-mode diff (default) is faster and produces better results for animated content.--stats-mode full is slower but better for content with little motion.--no-optimize) cuts total time by 10-25% at the cost of larger output files.vid2gif/
vid2gif.py Core conversion engine + CLI
requirements.txt Python dependencies (all optional extras)
README.md This file
MIT License. Copyright 2024 algorembrant.