Skip to content

Instantly share code, notes, and snippets.

@mxbees
Created Oct 10, 2017
Embed
What would you like to do?
A little script I use for making gifs.
#!/bin/bash
for i in "$@"
do
case $i in
-f=*)
frames=$(echo "${i#*=}")
shift
;;
-w=*)
width=$(echo "${i#*=}")
shift
;;
-b=*)
start=$(echo "${i#*=}")
shift
;;
-d=*)
duration=$(echo "${i#*=}")
shift
;;
-h)
echo "
use -f=* for number of frames
-w=* for the width
-b=* for the starting timestamp (00:00:00)
-d=* for number of seconds
-h for this menu
"
shift
;;
?)
echo "hit -h for help"
shift
;;
esac
done
video=$1
gif=$2
extract () {
ffmpeg -i $video -r $frames/1 -ss $start -t $duration -vf scale=$width:-1 %03d.png
echo "$video $frames $start $duration $width"
}
mk_gif () {
convert -ordered-dither o8x8,16 -delay 12 *.png -coalesce -layers OptimizeTransparency +map $gif.gif
}
for i in "$@"
do
case $i in
gif)
extract $video $frames $start $duration $width
mk_gif $gif
shift
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment