Created
February 22, 2020 20:22
-
-
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
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
Example of the result: https://user-images.githubusercontent.com/2134486/75098264-b52c1880-55bc-11ea-89ec-c4176a828c26.gif