Skip to content

Instantly share code, notes, and snippets.

@higsch
Forked from dergachev/GIF-Screencast-OSX.md
Created June 8, 2021 06:58
Show Gist options
  • Save higsch/36727532e79318c39d007dc242bff4c2 to your computer and use it in GitHub Desktop.
Save higsch/36727532e79318c39d007dc242bff4c2 to your computer and use it in GitHub Desktop.
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

  • Open "Quicktime Player",
  • Go to File -> New Screen Recording
  • Selected screen portion by dragging a rectangle, recorded 13 second video.
  • Go to File -> Export -> As Movie
    • Saved the video in full quality with the filename in.mov

To convert in.mov into out.gif (filesize: 48KB), open Terminal to the folder with in.mov and run the following command:

ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

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
  • --delay=3 tells gifsicle to delay 30ms between each gif
  • --optimize=3 requests that gifsicle use the slowest/most file-size optimization

To share the new GIF using Dropbox and Copy Public URL, run the following:

cp out.gif ~/Dropbox/Public/screenshots/Screencast-`date +"%Y.%m.%d-%H.%M"`.gif

Installation

The conversion process requires the following command-line tools:

  • ffmpeg to process the video file
  • gifsicle to create and optimize the an animated gif

If you use homebrew and homebrew-cask software packages, just type this in:

brew install ffmpeg 
brew cask install x-quartz #dependency for gifsicle, only required for mountain-lion and above
open /usr/local/Cellar/x-quartz/2.7.4/XQuartz.pkg # runs the XQuartz installer
brew install gifsicle

Resources

Related Ideas

  • Extend https://github.com/dergachev/copy-public-url folder action for this use case
    • it would automate the conversion before copying Dropbox public URL
    • assign the folder action to ~/Dropbox/Public/Screenshots/gif
    • consider finding a way to simplify the dependency installation

GIF-Screencast-OSX performance testing

I was disappointed with the color and quality that ffmpeg's GIF conversion gives. Imagemagick's convert can also be used to do the conversion, though this has serious performance penalties.

The following is the detailed findings, based on trying to convert a 3.8 second movie to a GIF.

FFMPEG to PNG -> CONVERT to GIF individually

  • 42 seconds in CONVERT, did not determine file size

    ffmpeg -i in-trimmed.mov -r 10 -vcodec png out-static-%02d.png time for img in out-static*.png; do convert -verbose +dither -layers Optimize "$img" "$img.gif" ; done

3.8 second movie -> FFMPEG to PNG -> CONVERT TO GIF BULK

ffmpeg -i in-trimmed.mov -r 10 -vcodec png out-static-%02d.png time convert -verbose +dither -layers Optimize -resize 600x600> out-static*.png GIF:- > out13.gif

FFMPEG to PNG -> CONVERT to GIF in bulk -> gifsicle

  • 56KB size; 7 seconds in CONVERT

    ffmpeg -i in-trimmed.mov -r 10 -vcodec png out-static-%02d.png time convert -verbose +dither -layers Optimize -resize 600x600> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > out13.gif

FFMPEG to PPM -> CONVERT to GIF in bulk

FFMPEG to PPM -> CONVERT to GIF in bulk -> gifsicle

FFMPEG to GIF -> gifsicle

Notes

  • Note that omitting resizing before converting to GIF dramatically slows down CONVERT.
  • imagemagick convert is much slower, but ffmpeg's GIF encoding is borked and produces really bad quality.

Resources

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