-
-
Save tigefa4u/7d6be7fc828580cd26210206e3811dc8 to your computer and use it in GitHub Desktop.
Gif gen
This file contains 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
#!/usr/bin/env nix-shell | |
#!nix-shell -i bash -p ffmpeg pngquant gifski gifsicle | |
# shellcheck shell=bash | |
set -euo pipefail | |
if [[ "$#" -ne 3 ]]; then | |
echo "Usage: gif.sh <name> <scale> <fps>" | |
exit 1 | |
fi | |
name=$1 | |
scale=$2 | |
fps=$3 | |
name_root="${name%.*}" | |
# https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/ | |
#ffmpeg -i $name -filter_complex "[0:v] fps=$fps,scale=$scale:-2,split [a][b];[a] palettegen [p];[b][p] paletteuse" -y frames/frame%04d.png | |
mkdir frames | |
# https://cassidy.codes/blog/2017/04/25/ffmpeg-frames-to-gif-optimization/ | |
ffmpeg -i $name -vf palettegen -y palette.png | |
ffmpeg -i $name -v warning -vf "fps=$fps,scale=$scale:-1:flags=lanczos,palettegen=stats_mode=diff" -y palette.png | |
ffmpeg -i $name -i palette.png -lavfi "fps=$fps,scale=$scale:-1:flags=lanczos,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y frames/frame%04d.png | |
pngquant --strip --ext=.png --force frames/*.png | |
gifski -W $scale frames/*.png -o tmp.gif | |
gifsicle --colors 256 -O3 tmp.gif -o $name_root-$scale-$fps.gif | |
rm -rf frames palette.png tmp.gif | |
# https://github.com/phw/peek |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment