Skip to content

Instantly share code, notes, and snippets.

@alecjacobson
Created October 4, 2018 15:49
Show Gist options
  • Save alecjacobson/d718b268029ec654a574d275df780e9d to your computer and use it in GitHub Desktop.
Save alecjacobson/d718b268029ec654a574d275df780e9d to your computer and use it in GitHub Desktop.
.mov to .gif converter
#!/bin/sh
# sh gifenc.sh input.mp4 output.gif [width] [height]
# Optionally accepts width / height (one or both).
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
if [ -z "$1" ];then
echo "gifenc input.mov output.gif [width] [height] [fps] [slowdown]"
exit 0
fi
palette="/tmp/palette.png"
filters="pad=0:0:0:00:white"
if [ ! -z $3 ]; then
if [ ! -z $4 ]; then
filters="$filters,scale=$3:$4"
else
filters="$filters,scale=$3:-1"
fi
filters="$filters:flags=lanczos"
fi
if [ ! -z $5 ]; then
filters="$filters,fps=$5"
fi
if [ ! -z $6 ]; then
filters="$filters,setpts=$6*PTS"
fi
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment