Skip to content

Instantly share code, notes, and snippets.

@tdhooper
Created April 11, 2019 22:50
Show Gist options
  • Save tdhooper/b083be9d024ab25c9a39a0a1c2cba69f to your computer and use it in GitHub Desktop.
Save tdhooper/b083be9d024ab25c9a39a0a1c2cba69f to your computer and use it in GitHub Desktop.
#!/bin/sh
# From http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# Usage:
# ./makegif.sh export01 output.gif
palette="/tmp/palette.png"
filters="scale=640:-1:flags=lanczos"
frames=`mktemp -d`
for i in 1; do
for file in $1/*.png; do
filename=$(basename "$file")
cp $file "$frames/$i-$filename"
done
done
ffmpeg -thread_queue_size 512 -v warning -pattern_type glob -i "$frames/*.png" -vf "$filters,palettegen=stats_mode=diff:max_colors=16" -y $palette
ffmpeg -thread_queue_size 512 -v warning -pattern_type glob -i "$frames/*.png" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse=dither=sierra2_4a" -y $2
rm -r $frames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment