Last active
December 21, 2021 16:51
-
-
Save berikv/98e07aa2ef07d9677a190ebc84532859 to your computer and use it in GitHub Desktop.
Transform a movie file to a gif. Specialised for demo's of Mobile app screen recordings.
This file contains 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 | |
FFMPEG=$(command -v ffmpeg) | |
INFILE=$1 | |
OUTFILE="${INFILE}.gif" | |
TMPFILE="${INFILE}_gifify_palette.png" | |
if ! $FFMPEG -L > /dev/null 2>&1; then | |
echo "Run: brew install ffmpeg" | |
exit 1 | |
fi | |
if [ -e "$TMPFILE" ]; then | |
echo "Error: tmpfile $TMPFILE already exists" | |
exit 1 | |
fi | |
FILTER="fps=10,scale=320:-1:flags=lanczos" | |
$FFMPEG -i "$INFILE" -vf "$FILTER,palettegen" -y "$TMPFILE" | |
$FFMPEG -i "$INFILE" -i "$TMPFILE" -lavfi "$FILTER [x]; [x][1:v] paletteuse" -y "$OUTFILE" | |
if [ -e "$TMPFILE" ]; then | |
rm "$TMPFILE" | |
fi |
Adding some quotes to support spaces in filenames
#!/bin/bash
FFMPEG=`which ffmpeg`
INFILE=${1}
OUTFILE="${INFILE}.gif"
TMPFILE="${INFILE}_gifify_palette.png"
if ! $FFMPEG -L > /dev/null 2>&1; then
echo "Run: brew install ffmpeg"
exit -1
fi
if [ -e "$TMPFILE" ]; then
echo "Error: tmpfile "$TMPFILE" already exists"
exit -1
fi
FILTER="fps=10,scale=320:-1:flags=lanczos"
$FFMPEG -i "$INFILE" -vf "$FILTER,palettegen" -y "$TMPFILE"
$FFMPEG -i "$INFILE" -i "$TMPFILE" -lavfi "$FILTER [x]; [x][1:v] paletteuse" -y "$OUTFILE"
if [ -e "$TMPFILE" ]; then
rm "$TMPFILE"
fi
Thanks Robin! Updated
Fixed several issues with help of the amazing https://www.shellcheck.net
This is now DEPRECATED, use https://github.com/berikv/gifify instead!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install instructions:
Run in terminal: gifify SomeVideo.mov
Result will be SomeVideo.mov.gif