Skip to content

Instantly share code, notes, and snippets.

@berikv

berikv/gifify

Last active Jul 2, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@berikv 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

This comment has been minimized.

Copy link

@rvandijke-uber rvandijke-uber commented Sep 6, 2017

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

This comment has been minimized.

Copy link
Owner Author

@berikv berikv commented Sep 8, 2017

Thanks Robin! Updated

@berikv

This comment has been minimized.

Copy link
Owner Author

@berikv berikv commented Jul 2, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment