Created
February 19, 2019 16:09
-
-
Save chrissnell/f8e74579df4fde8fc955e36015c9aa6a to your computer and use it in GitHub Desktop.
mp4-to-gif.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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