Skip to content

Instantly share code, notes, and snippets.

@mxbees
Created October 10, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxbees/789154b661d1525f840ce043b665a398 to your computer and use it in GitHub Desktop.
Save mxbees/789154b661d1525f840ce043b665a398 to your computer and use it in GitHub Desktop.
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