Skip to content

Instantly share code, notes, and snippets.

@fiorix
Created September 25, 2017 08:40
Show Gist options
  • Save fiorix/fe327a78ad7273270e19246b819609f4 to your computer and use it in GitHub Desktop.
Save fiorix/fe327a78ad7273270e19246b819609f4 to your computer and use it in GitHub Desktop.
#!/bin/bash
FRAMES_DIR=frames.$$
trap "rm -rf ${FRAMES_DIR}" EXIT
FPS=10
WIDTH=480
FONT_COLOR=white
INPUT="$1"
OUTPUT="$2"
TEXT="$3"
if [ "x${INPUT}" = "x" -o "x${OUTPUT}" = "x" ]; then
echo "use: $0 input.mp4 output.gif [text]"
exit 1
fi
mkdir frames.$$
ffmpeg -i "${INPUT}" -vf scale=${WIDTH}:-1:flags=lanczos,fps=${FPS} ${FRAMES_DIR}/ffout%03d.png
rm -f "${OUTPUT}"
if [ "x${TEXT}" = "x" ]; then
convert -loop 0 ${FRAMES_DIR}/ffout*.png ${FRAMES_DIR}/"${OUTPUT}"
else
TEXT_OPTS="-font Arial -fill white -pointsize 29 -stroke ${FONT_COLOR} -strokewidth 2 -gravity south -annotate +0+0"
convert -loop 0 $TEXT_OPTS "${TEXT}" ${FRAMES_DIR}/ffout*.png ${FRAMES_DIR}/"${OUTPUT}"
fi
convert ${FRAMES_DIR}/"${OUTPUT}" -fuzz 5.5% -layers Optimize "${OUTPUT}"
@fiorix
Copy link
Author

fiorix commented Sep 28, 2017

brew install ffmpeg imagemagick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment