Skip to content

Instantly share code, notes, and snippets.

@marciopuga
Last active January 13, 2022 11:37
Show Gist options
  • Save marciopuga/51a14e048958abc581665e4e22655776 to your computer and use it in GitHub Desktop.
Save marciopuga/51a14e048958abc581665e4e22655776 to your computer and use it in GitHub Desktop.
video to gif using ffmpeg with superior quality
#!/bin/sh
# run docker version instead of local installation
alias ffmpeg='docker run -v=`pwd`:/tmp/ffmpeg opencoconut/ffmpeg'
palette="palette.png"
# adjust fps here if you need to
filters="fps=10,scale=$1:-1:flags=lanczos"
# create a palette with the colors beforehand for superior results
ffmpeg -v warning -i $2 -vf "$filters,palettegen" -y $palette
# convert video to gif using the palette
ffmpeg -v warning -i $2 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $3
# remove the palette
rm palette.png
@marciopuga
Copy link
Author

./gif.sh 480 example.mov example.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment