Created
February 25, 2022 12:30
-
-
Save binaryfunt/a45dc0fda73bc50b45c186c64e9d4328 to your computer and use it in GitHub Desktop.
Convert video to .gif using ffmpeg. Optionally speed up the footage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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