Skip to content

Instantly share code, notes, and snippets.

@knokmki612
Created March 28, 2018 09:26
Show Gist options
  • Save knokmki612/c7e035bab50806cf8a04819793eb279a to your computer and use it in GitHub Desktop.
Save knokmki612/c7e035bab50806cf8a04819793eb279a to your computer and use it in GitHub Desktop.
#!/bin/sh
TMP_DIR="$HOME/${0##*/}.$(openssl rand -base64 12 | tr +/ -_)"
mkdir "$TMP_DIR"
do_exit() {
rm -r "$TMP_DIR"
exit
}
trap 'do_exit' 1 2 3 15
[ ! -f "$1" ] && do_exit
SRC="${1##*/}"
SRC_NAME="${SRC%.*}"
ffmpeg -i "$1" -vf \
fps=10,scale=iw:-1:flags=lanczos,palettegen "${TMP_DIR}/palette.png"
ffmpeg -i "$1" -i "${TMP_DIR}/palette.png" -filter_complex \
fps=10,scale=iw:-1:flags=lanczos[x]\;[x][1:v]paletteuse "${SRC_NAME}.gif"
do_exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment