Skip to content

Instantly share code, notes, and snippets.

@berikv
Last active December 21, 2021 16:51
Show Gist options
  • Save berikv/98e07aa2ef07d9677a190ebc84532859 to your computer and use it in GitHub Desktop.
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.
#!/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
@berikv
Copy link
Author

berikv commented Oct 5, 2016

Install instructions:

  • Download into ~/bin
  • Run in terminal: chmod +x ~/bin/gifify
  • There is no step 3!

Run in terminal: gifify SomeVideo.mov
Result will be SomeVideo.mov.gif

@rvandijke-uber
Copy link

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

@berikv
Copy link
Author

berikv commented Sep 8, 2017

Thanks Robin! Updated

@berikv
Copy link
Author

berikv commented Jul 2, 2019

Fixed several issues with help of the amazing https://www.shellcheck.net

@berikv
Copy link
Author

berikv commented Dec 21, 2021

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