Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 31 lines (25 sloc) 705 Bytes
#!/bin/bash
# ref: <http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality>
# usage: vid2gif [-f fps] [-w width] <input> <output>
FPS=10
TMP=/tmp/tmp.gif
PAL=/tmp/palette.png
MODE=full
DITHER=sierra2_4a
while getopts "f:w:" opt; do
case "$opt" in
f)
FPS=$OPTARG
;;
w)
SCALE=",scale=$OPTARG:-1:flags=lanczos"
;;
esac
done
shift "$((OPTIND-1))"
INP=$1
OUT=$2
FILTERS="fps=$FPS$SCALE"
ffmpeg -y -i "$INP" -vf "$FILTERS,palettegen=stats_mode=$MODE" "$PAL"
ffmpeg -y -i "$INP" -i "$PAL" -lavfi "$FILTERS [x]; [x][1:v] paletteuse=dither=$DITHER" "$TMP"
gifsicle -O3 "$TMP" > "$OUT"