Skip to content

Instantly share code, notes, and snippets.

@reidbaker
Created August 13, 2015 16:08
Show Gist options
  • Save reidbaker/ae8e10ae8291f134f2ac to your computer and use it in GitHub Desktop.
Save reidbaker/ae8e10ae8291f134f2ac to your computer and use it in GitHub Desktop.
function mp4togif() {
FILTERS="fps=30,scale=w='if(gt(iw,ih),-1,480)':h='if(gt(iw,ih),480,-1)':flags=lanczos"
TEMP="$(mktemp -t mp4togif).png"
echo "Creating palette..."
ffmpeg -v warning -i $1 -vf "$FILTERS,palettegen" -y "$TEMP"
echo "Encoding GIF..."
ffmpeg -v warning -i $1 -i "$TEMP" -lavfi "$FILTERS[x];[x][1:v]paletteuse=dither=floyd_steinberg" -y -f gif "$1.gif"
echo "Done!"
}
#Credit @jakewharton ASG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment