Last active
August 8, 2023 13:04
-
-
Save tdhooper/ca37d14edc5f1ee8a98fe20f3b64827f to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# From http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html | |
# Usage: | |
# ./makegif.sh inputframes output.gif | |
# where inputframes is a directory containing .png frames | |
# Change size here | |
filters="scale=640:-1:flags=lanczos" | |
# Generate palette, you can change max_colors | |
palette="palette.png" | |
ffmpeg -thread_queue_size 512 -v warning -pattern_type glob -i "$1/*.png" -vf "$filters,palettegen=stats_mode=diff:max_colors=256:reserve_transparent=false" -y $palette | |
# Create gif | |
ffmpeg -thread_queue_size 512 -v warning -pattern_type glob -i "$1/*.png" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse=dither=sierra2_4a" -y $2 | |
# Optimise and adjust | |
# * Delay between frames is 100ths of a second, for example 4 is 25fps | |
# * To repeat twice do "#0-" "#0-" | |
gifsicle --batch --optimize=03 --delay=4 $2 "#0-" | |
# Display final file size | |
stat --format=%s $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment