Skip to content

Instantly share code, notes, and snippets.

@ruofeidu
Last active May 25, 2021 03:57
Show Gist options
  • Save ruofeidu/4b2b7592d7357e1e0f0faeac34a4cd07 to your computer and use it in GitHub Desktop.
Save ruofeidu/4b2b7592d7357e1e0f0faeac34a4cd07 to your computer and use it in GitHub Desktop.
gifit.sh
start_time=0:0
duration=10
# Windows Bash
palette="/c/python3/scripts/palette.png"
# Linux / Mac Bash
# palette="/tmp/palette.png"
filters="fps=15,scale=320:-1:flags=lanczos"
if (( $# == 0 )); then
echo "Usage: gifit <file-name> [optional duration] [optional start_time]"
elif (( $# == 2 )); then
duration=$2
elif (( $# == 3 )); then
duration=$2
start_time=$3
fi
# Get base filename
filename="$1"
filename=${filename%%.*}
ffmpeg -v warning -ss $start_time -t $duration -i $filename.mp4 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -ss $start_time -t $duration -i $filename.mp4 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $filename.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment