Convert MP4 videos to high-quality GIFs using ffmpeg's two-pass palette method. The two-pass approach produces significantly better color quality than direct conversion.
Two-pass palette-based conversion (always use this over single-pass):
text
# Pass 1: Generate optimized palette
ffmpeg -y -i <input> -vf "fps=15,scale=480:-1:flags=lanczos,palettegen=stats_mode=diff" /tmp/palette.png
# Pass 2: Convert using palette
ffmpeg -y -i <input> -i /tmp/palette.png -lavfi "fps=15,scale=480:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" <output>
ParameterDefaultEffectfps15Frame rate — lower = smaller file, choppier motionscale width480Output width in px — height auto-calculated ( -1)lanczos—High-quality downscaling filterstats_mode=diff—Palette optimized for frame differences (better for motion)dither=bayer—Ordered dithering, good balance of quality/sizebayer_scale5Dither strength (0-5), higher = more ditheringdiff_mode=rectangle—Only update changed regions (smaller file)
GoalAdjustSmaller fileLower fps (10), smaller width (320), or trim durationSmoother motionHigher fps (24-30), but file size increases significantlyBetter colorsUse stats_mode=full for static/slow contentSharperIncrease width (640-800), costs more file size
Two scripts are bundled alongside this SKILL.md. Use the one matching the current platform.
Windows (PowerShell) — mp4_to_gif.ps1:
powershell
& "<this-skill-dir>/mp4_to_gif.ps1" -InputFile <input> # Defaults: 480px, 15fps
& "<this-skill-dir>/mp4_to_gif.ps1" -InputFile <input> -Width 640 -Fps 20 # Custom settings
& "<this-skill-dir>/mp4_to_gif.ps1" -InputFile <input> -OutputFile <output> # Custom output name
Linux / macOS (Bash) — mp4_to_gif.sh:
bash
bash "<this-skill-dir>/mp4_to_gif.sh" -i <input> # Defaults: 480px, 15fps
bash "<this-skill-dir>/mp4_to_gif.sh" -i <input> -w 640 -f 20 # Custom settings
bash "<this-skill-dir>/mp4_to_gif.sh" -i <input> -o <output> # Custom output name
When Claude invokes this skill, resolve <this-skill-dir> to the absolute path of the directory containing this SKILL.md.
ffmpeg -i in.mp4 out.gif) — produces terrible banding and color artifacts. Always use the two-pass palette method.