Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active January 14, 2023 04:21
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save mbostock/4b88b250bc4439289d94 to your computer and use it in GitHub Desktop.
Save mbostock/4b88b250bc4439289d94 to your computer and use it in GitHub Desktop.
Screen Recording to GIF
license: gpl-3.0

If you haven’t already:

brew install ffmpeg gifsicle

Open QuickTime Player. File > New Screen Recording. Record. Trim as needed. Save as foo.mov.

First compute a good color palette:

ffmpeg -i foo.mov -vf 'scale=-1:-1:flags=lanczos,palettegen' foo-palette.png

Then make your GIF:

ffmpeg -i foo.mov -i foo-palette.png -filter_complex 'scale=-1:-1:flags=lanczos[x];[x][1:v]paletteuse' foo.gif

To drop frames, add fps=10, to the -filter_complex argument.

To crop, add crop=width:height:x:y, to the -filter_complex argument.

See also https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality.

@maelp
Copy link

maelp commented Dec 21, 2014

Great! Also on osX you can use http://www.cockos.com/licecap although it is perhaps not scriptable from the command line :)

@davo
Copy link

davo commented Jan 29, 2015

Sorry, Mike, line 7 should not be like this?

ffmpeg -i recording.mov -r 24 frames/recording-%03d.png

Anyway, great workflow... works like magic.

@mbostock
Copy link
Author

@davo Yeah. I deleted the mkdir frames step to fix.

@paulklemm
Copy link

I really like the 5€ GIFBrewery tool for creating a gif from a movie file, because it has a bunch of handy functions build in, such as captions and conversion properties. I'm sure you can do all this with free tools, but this one is designed well and works.

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