Skip to content

Instantly share code, notes, and snippets.

@michaelkirk
Last active September 24, 2020 01:58
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 michaelkirk/924ef48d53e8ebca42d05b12ab16dba3 to your computer and use it in GitHub Desktop.
Save michaelkirk/924ef48d53e8ebca42d05b12ab16dba3 to your computer and use it in GitHub Desktop.
# default output resolution
WIDTH_SCALE=480
set -x
set -e
BIN_NAME=$0
function usage {
cat <<EOS
Usage:
$BIN_NAME <video file> <optional width px>
Example:
$BIN_NAME foo.mov 200
# uses default width scale: ${WIDTH_SCALE}
$BIN_NAME foo.mov
EOS
}
INPUT_FILE=$1
if [ -z "${INPUT_FILE}" ]
then
usage
exit 1
fi
if [ ! -z "$2" ]
then
WIDTH_SCALE=$2
fi
palette="/tmp/palette.png"
filters="fps=15,scale=${WIDTH_SCALE}:-1:flags=lanczos"
OUTPUT_FILE="${INPUT_FILE}.gif"
ffmpeg -i "${INPUT_FILE}" -vf "$filters,palettegen" -y $palette
ffmpeg -i "${INPUT_FILE}" -i $palette -filter_complex "
[0:v]
${filters},
paletteuse,
reverse,
tpad='start_duration=1.6',
drawtext='enable=between(t\,0\,1.0):font=serif:fontcolor=white:fontsize=100:x=(w-text_w)/2:y=(h-text_h)/2:text=Fin.',
reverse
" -y "${OUTPUT_FILE}"
gifsicle -O3 --batch "${OUTPUT_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment