Skip to content

Instantly share code, notes, and snippets.

@egoens
Last active March 6, 2020 20:01
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 egoens/3e5c87ae4602af6db52cd333048b26c7 to your computer and use it in GitHub Desktop.
Save egoens/3e5c87ae4602af6db52cd333048b26c7 to your computer and use it in GitHub Desktop.
Gifme your videos
#!/usr/bin/env bash
# save this file on your local machine as 'gifme.sh' (or file name of your choice)
# run the following command wherever you saved this file:
# bash gifme.sh
# Check for Homebrew, install if we don't have it
echo "Installing Homebrew........"
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
echo "Updating Homebrew........"
# Update homebrew recipes
brew update
brew install gifsicle
if test ! $(which ffmpeg); then
echo "Installing ffmpeg........"
# install ffmpeg
brew install ffmpeg
else
echo "ffmpeg already installed........"
fi
if ! type gifme &>/dev/null; then
# set env file to use to insert function
if test -e ~/.bash_profile
then
ENVFILETYPE=~/.bash_profile
elif test -e ~/.bashrc
then
ENVFILETYPE=~/.bashrc
elif test -e ~/.zshrc
then
ENVFILETYPE=~/.zshrc
else
echo 'no profile found'
fi
echo "adding gifme to your env file........"
echo '
# define gifme
# make gif file out of .mov file
# Notes on the arguments:
# -r 10 tells ffmpeg to reduce the frame rate from 25 fps to 10
# -s 600x400 tells ffmpeg the max-width and max-height
# -vf scale=640:-1 scales image at defined sizes; setting -1 to either size preserves ratio based on other max-width definition
# --delay=3 tells gifsicle to delay 30ms between each gif
# --optimize=3 requests that gifsicle use the slowest/most file-size optimization
# usage: gifme filename.mov
# this should generate "filename.gif"
function gifme {
ffmpeg -i $1 -vf scale=640:-1 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=10 > "$1.gif"
}' >> ${ENVFILETYPE}
else
echo "gifme function already exists........"
fi
echo "Done!"
echo "Open a new tab and run 'gifme videofilename.mov' to create your .gif!"

Installation

install homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

install ffmpeg

brew install ffmpeg

add function to your environment file (.bashrc, .zshrc)

# make gif file out of .mov file
# Notes on the arguments:
# -r 10 tells ffmpeg to reduce the frame rate from 25 fps to 10
# -s 600x400 tells ffmpeg the max-width and max-height
# -vf scale=640:-1 scales image at defined sizes; setting -1 to either size preserves ratio based on other max-width definition
# --delay=3 tells gifsicle to delay 30ms between each gif
# --optimize=3 requests that gifsicle use the slowest/most file-size optimization
# usage: gifme filename.mov
# this should generate `filename.gif`
gifme () {
	ffmpeg -i $1 -vf scale=640:-1 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=10 > "$1.gif"
}

Usage Instructions

  1. Use QuickTime to do a screen capture
  2. Save screen capture
  3. Open Terminal application
  4. cd to saved screen caputure
  5. Run gifme screencapturefile.mov

General info

gifme should generate a new compressed screencapturefile.mov.gif file in the same location as the saved .mov file.

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