Skip to content

Instantly share code, notes, and snippets.

@claudiodekker
Last active December 3, 2020 17:39
Show Gist options
  • Save claudiodekker/df511a98ae7a8bfe7990a84a437cbd85 to your computer and use it in GitHub Desktop.
Save claudiodekker/df511a98ae7a8bfe7990a84a437cbd85 to your computer and use it in GitHub Desktop.
Simple command to turn videos into GIFs
#!/bin/bash
v2gif() {
# Based on https://engineering.giphy.com/how-to-make-gifs-with-ffmpeg/
ffmpeg=""
filter=""
palettegen="palettegen"
paletteuse="paletteuse"
while getopts "w:f:is:t:" opt; do
case ${opt} in
# Start offset (seconds)
s) ffmpeg="${ffmpeg} -ss ${OPTARG}";;
# Duration (seconds)
t) ffmpeg="${ffmpeg} -t ${OPTARG}";;
# Width (height: -1 = keep exact aspect ratio, -2 = round to even number (important for many video codecs))
w) filter="scale=w=${OPTARG}:h=-2,$filter";;
# FPS
f) filter="fps=${OPTARG},$filter";;
# Insane mode (256-colors per frame)
i)
palettegen="${palettegen}=stats_mode=single"
paletteuse="${paletteuse}=new=1"
;;
esac;
done
shift $(($OPTIND - 1));
ffmpeg ${ffmpeg} -i "$1" -filter_complex "[0:v] ${filter}split [a][b];[a] ${palettegen} [p];[b][p] ${paletteuse}" "$1.gif"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment