Skip to content

Instantly share code, notes, and snippets.

@shandanjay
Forked from bodqhrohro/vidqgif.sh
Created January 31, 2024 17:01
Show Gist options
  • Save shandanjay/eb49286f26db36fa0ca544b63b462631 to your computer and use it in GitHub Desktop.
Save shandanjay/eb49286f26db36fa0ca544b63b462631 to your computer and use it in GitHub Desktop.
Compress a video to a tiny GIF with a very strong quantization and no dithering
#!/bin/sh
# parameters: input, output
# make a 256-colors palette first
palettefull=$( mktemp --suffix=.png )
ffmpeg -i "$1" -vf 'palettegen' -y "$palettefull"
# quantize the palette (palettegen's builting limiter
# tries to preserve too much similar shades)
palettequant=$( mktemp --suffix=.png )
convert "$palettefull" -posterize 6 "$palettequant"
# initial compression
rawgif=$( mktemp --suffix=.gif )
ffmpeg -i "$1" -i "$palettequant" -lavfi "paletteuse=dither=0" -y "$rawgif"
# gifsicle optimization (the slowest stage)
gifsicle -O3 --lossy=80 "$rawgif" -o "$2"
# cleanup
rm "$palettefull" "$palettequant" "$rawgif"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment