Skip to content

Instantly share code, notes, and snippets.

@AviDuda
Last active December 13, 2016 12:41
Show Gist options
  • Save AviDuda/47be71b1f46acf99a4eb810b76ef2b30 to your computer and use it in GitHub Desktop.
Save AviDuda/47be71b1f46acf99a4eb810b76ef2b30 to your computer and use it in GitHub Desktop.
High quality gif
#!/bin/bash
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# gif-create.sh video.mp4 output.gif start_time duration <fps> <width>
# default is 30 FPS, width 340
# Twitter limits: max 40 FPS and max 15 MB
start_time=$3
duration=$4
fps=${5:-30}
width=${6:-340}
palette="/tmp/palette.png"
filters="fps=$fps,scale=$width:-1:flags=lanczos"
palettegenfilters="=stats_mode=diff"
palettefilters="=dither=bayer:bayer_scale=3" # try sierra2
ffmpeg -v warning -ss $start_time -t $duration -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -ss $start_time -t $duration -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse$palettefilters" -y $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment