-
-
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
This file contains hidden or 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
#!/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