Skip to content

Instantly share code, notes, and snippets.

@onebytegone
Created June 8, 2018 15:01
Show Gist options
  • Save onebytegone/c63f48ecd5c0ecf80d07198649149601 to your computer and use it in GitHub Desktop.
Save onebytegone/c63f48ecd5c0ecf80d07198649149601 to your computer and use it in GitHub Desktop.
Screen capture video to GIF converter
#!/bin/bash
# usage: ./gifize.sh -x left -y top image.gif
X_POS_LEFT='10'
X_POS_RIGHT='(w-text_w-10)'
Y_POS_TOP='10'
Y_POS_BOTTOM='(h-text_h-10)'
X_POS=$X_POS_LEFT
Y_POS=$Y_POS_TOP
INPUT=${@: -1}
OUTPUT="${INPUT%.*}.gif"
while getopts "x:y:" OPTION
do
echo $OPTION'-'$OPTARG
case $OPTION in
x)
if [ "${OPTARG}" = "left" ]; then
X_POS=$X_POS_LEFT
elif [ "${OPTARG}" = "right" ]; then
X_POS=$X_POS_RIGHT
fi
;;
y)
if [ "${OPTARG}" = "top" ]; then
Y_POS=Y$_POS_TOP
elif [ "${OPTARG}" = "bottom" ]; then
Y_POS=$Y_POS_BOTTOM
fi
;;
esac
done
echo "Creating gif from ${INPUT}"
echo 'x:' $X_POS
echo 'y:' $Y_POS
ffmpeg -i "${INPUT}" \
-r 12 \
-vf scale=540:540:force_original_aspect_ratio=decrease,drawtext="timecode='00\:00\:00\:00':fontfile=/Library/Fonts/Courier New.ttf:fontsize=40:rate=60:fontcolor='white':boxcolor=0x000000AA:box=1:x=${X_POS}:y=${Y_POS}" \
"${OUTPUT}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment