Skip to content

Instantly share code, notes, and snippets.

@axynos
Created August 6, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axynos/1bdae00a586a84bf2802d37576c66946 to your computer and use it in GitHub Desktop.
Save axynos/1bdae00a586a84bf2802d37576c66946 to your computer and use it in GitHub Desktop.
Generates gif palettes dynamically to increase quality. Nicked (and modified a bit) from http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# !/bin/sh
# original script from http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
palette="/tmp/palette.png"
# the scale here refers to the horizontal size which then gets used to scale the output
# variables:
# fps: Frames Per Second
# scale: horizontal width in pixels
filters="fps=30,scale=728:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
# Usage: ./palettemagic.sh inputvideo.extension outputfile.gif
# Example: ./palettemagic.sh final.mp4 output.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment