Created
July 18, 2022 20:37
-
-
Save ianfoo/1258f7e5fca7276dce0f83ef16207f4f to your computer and use it in GitHub Desktop.
Make a reasonable-quality GIF from a video clip
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 -Eeuo pipefail | |
if [[ $# == 0 ]]; then | |
echo >&2 "movie filename and output filename is required" | |
exit 1 | |
fi | |
input_file="$1" | |
output_file="$2" | |
start_and_duration="" | |
if [[ $# == 4 ]]; then | |
start_time=$3 | |
duration=$4 | |
start_and_duration="-ss $start_time -t $duration" | |
fi | |
palette="/tmp/palette.png" | |
filters="fps=15,scale=480:-1:flags=lanczos" | |
ffmpeg -v warning $start_and_duration -i "$input_file" -vf "$filters,palettegen" -y $palette | |
ffmpeg -v warning $start_and_duration -i "$input_file" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$output_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment