Skip to content

Instantly share code, notes, and snippets.

@binaryfunt
Created February 25, 2022 12:30
Show Gist options
  • Save binaryfunt/a45dc0fda73bc50b45c186c64e9d4328 to your computer and use it in GitHub Desktop.
Save binaryfunt/a45dc0fda73bc50b45c186c64e9d4328 to your computer and use it in GitHub Desktop.
Convert video to .gif using ffmpeg. Optionally speed up the footage.
#!/usr/bin/env bash
set -eo pipefail
USAGE='
Usage:
$ convert2gif <input_video_file> <output_gif_file> [<speedup_factor>]
Convert video to .gif using ffmpeg. Optionally speed up the footage.
'
if [[ -z "$2" ]]; then
echo "$USAGE"
exit 1
fi
palette="/tmp/palette.png"
filter="paletteuse"
input_file="$1"
output_file="$2"
speedup_factor="$3"
if [[ ! -z "$3" ]]; then
filter="${filter}, setpts=PTS/${speedup_factor}"
fi
ffmpeg -i "$input_file" -vf palettegen -y "$palette"
ffmpeg -i "$input_file" -i "$palette" -filter_complex "$filter" "$output_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment