Skip to content

Instantly share code, notes, and snippets.

@bodqhrohro
Created February 22, 2020 20:22
Show Gist options
  • Save bodqhrohro/d71900f9d00f2acd5933abe8998bdfde to your computer and use it in GitHub Desktop.
Save bodqhrohro/d71900f9d00f2acd5933abe8998bdfde 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"
@bodqhrohro
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment