Skip to content

Instantly share code, notes, and snippets.

@andyinabox
Forked from timyates/README.md
Last active November 9, 2015 19:15
Show Gist options
  • Save andyinabox/aa8d2584f9700a6183b6 to your computer and use it in GitHub Desktop.
Save andyinabox/aa8d2584f9700a6183b6 to your computer and use it in GitHub Desktop.
Generating terminal gifs on OS X the free way

Didn't work any of this out, I just stuck things together that I found on the web

First, install the things:

brew install imagemagick
brew install ffmpeg

Then, I have a small (600px wide) iTerm window with a big font. Load Quicktime, and record screen (just the area of the terminal)

Trim and save the mov somewhere (lets say ~/Documents/term.mov)

Then, do:

cd ~/Documents
mkdir movanim
cd movanim

# This will render the mov to individual pngs (at 10fps) at a
# width of 500px (which is approximately the size twitter shows them as)
ffmpeg -i ../term.mov -vf scale=500:-1 -r 10 ./ffout%4d.png

# Then this will convert the pngs to a gif (8ms delay between frames loop forever)
# and optimise it as best as it can (the -layers flag)
convert -delay 8 -loop 0 -layers Optimize ffout*.png animation.gif
#!/bin/bash
if [ $# -eq 1 ]
then
WORKING_DIR="$1-stills"
echo "-------------------"
echo "mov2gif here we go!"
echo "-------------------"
echo "Creating temporary files"
mkdir $WORKING_DIR
touch $LOG
echo "Outputting video stills"
ffmpeg -i $1 -vf scale=500:-1 -r 10 "$WORKING_DIR/%4d.png"
echo "Gluing stills back together"
convert -delay 8 -loop 0 -layers Optimize "$WORKING_DIR/*.png" "$1.gif"
echo "Cleaning up"
rm -r $WORKING_DIR
echo "--> $.gif"
else
echo "Usage: ./mov2gif.sh <video file path>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment