Skip to content

Instantly share code, notes, and snippets.

@mfehr
Last active March 2, 2023 09:48
Show Gist options
  • Save mfehr/7b7a3a5410359566418e7ea62bc11be2 to your computer and use it in GitHub Desktop.
Save mfehr/7b7a3a5410359566418e7ea62bc11be2 to your computer and use it in GitHub Desktop.
gifify.sh
#!/usr/bin/env bash
# USAGE: gifify.sh <video> <start time in s> <duration in s> <desired FPS> <scale in px>
#
# Example: ./gifify yourvideo.mp4 3 [start time in seconds] 10 [duration in seconds] 15 [desired FPS] 600 [gif scale, expressed as desired width in pixel]
#
palette="/tmp/palette_$2_$3_$4_$5.png"
filters="fps=$4,scale=$5:-1:flags=lanczos"
ffmpeg -ss $2 -t $3 -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -ss $2 -t $3 -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "output_$2_$3_$4_$5.gif"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment