Skip to content

Instantly share code, notes, and snippets.

@chrissnell
Created February 19, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissnell/f8e74579df4fde8fc955e36015c9aa6a to your computer and use it in GitHub Desktop.
Save chrissnell/f8e74579df4fde8fc955e36015c9aa6a to your computer and use it in GitHub Desktop.
mp4-to-gif.sh
#!/bin/bash
#
# Credit to @raydog for this script
#
if [ -z "$1" ] ; then
echo "Usage: $0 <mp4_file>"
exit 1
fi
MOVFILE="$1"
GIFFILE="$(basename "$MOVFILE" .mp4).gif"
TEMPDIR="$(mktemp -d)"
echo "============================"
echo "INPUT: $MOVFILE"
echo "OUTPUT: $GIFFILE"
echo "TEMP: $TEMPDIR"
echo "============================"
LOGLVL="-v warning"
PALETTE="$TEMPDIR/palette.png"
FILTERS="fps=10,scale=640:-1:flags=lanczos"
echo "[ Creating palette ]"
ffmpeg $LOGLVL -i "$MOVFILE" -vf $FILTERS,palettegen -y "$PALETTE"
echo "[ Compiling video ]"
ffmpeg $LOGLVL -i "$MOVFILE" -i "$PALETTE" -lavfi "$FILTERS [out]; [out][1:v] paletteuse" -y "./$GIFFILE"
ls -lh "./$GIFFILE"
rm -rf "$TEMPDIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment