Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To take a static screenshot of a selected part of my screen, I often use scrot with -s shot.png. This is great for adding illustrations to StackExchange posts. I even found this script to automatically upload such a screenshot to Imgur.com and put a link in my X clipboard!

Let's turn this up to twelve: How do I similarly create a GIF screencast?

There are programs like recordmydesktop, byzanz & co as discussed on Ask Ubuntu that aim to be "user friendly", but in my experience are buggy, inefficient, mostly unscriptable and unsuited for little one-off things like this.

I just want to select an area and record a GIF, with a console command I can understand, not some arcane unscriptable GUI monstrosity.

How can I do this?

share|improve this question
Related: How to create animated GIF images of a screencast? from Ask Ubuntu. – Cristian Ciupitu Oct 20 '14 at 12:36
up vote 46 down vote accepted

OK then

GIF vimcast!

I started ffcast, did vim, quit ffcast, then converted .avi.gif.

I ran the recording commands in another terminal. Polished script for your $PATH at the end of this answer.

What happened?


FFcast helps the user interactively select a screen region and hands over the geometry to an external command, such as FFmpeg, for screen recording.

ffcast is the glorious product of some hacking at the Arch Linux community (mainly lolilolicon). You can find it on github (or in the AUR for Archers). Its dependency list is just bash and ffmpeg, though you'll want xrectsel (AUR link) for interactive rectangle selection.

You can also append ffmpeg flags right after the command. I set -r 15 to capture at 15 frames per second and -codec:v huffyuv for lossless recording. (Play with these to tweak the size/quality tradeoff.)


ImageMagick can read .avi videos and has some GIF optimisation tricks that drastically reduce file size while preserving quality: The -layers Optimize to convert invokes the general-purpose optimiser. The ImageMagick manual has a page on advanced optimisations too.

Final script

This is what I have in my $PATH. It records into a temporary file before converting.

TMP_AVI=$(mktemp /tmp/outXXXXXXXXXX.avi)
ffcast -s % ffmpeg -y -f x11grab -show_region 1 -framerate 15 \
    -video_size %s -i %D+%c -codec:v huffyuv                  \
    -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" $TMP_AVI         \
&& convert -set delay 10 -layers Optimize $TMP_AVI out.gif

Thanks to BenC for detective work in figuring out the correct flags after the recent ffcast update.

If you'd like to install the dependencies on a Debian-based distro, Louis has written helpful installation notes.


share|improve this answer
I've created a version who doesn't require bash, but who works on any POSIX compliant shell github.com/chilicuil/ffcast – chilicuil Mar 22 '14 at 4:31
Looks like the command line syntax of ffcast has changed: github.com/lolilolicon/FFcast/issues/8 – Jack O'Connor Sep 30 '14 at 20:25
The simplest way to do it is now ffcast -s rec [filename], though that doesn't give the exact settings you're using in your example. Unfortunately, to give exact settings, you now have to give the entire ffmpeg command. Your call about the best way to update this answer :) – Jack O'Connor Oct 1 '14 at 1:47
Based on the comments on GH, ffcast -s % ffmpeg -f x11grab -show_region 1 -framerate 20 -video_size %s -i %D+%c -codec:v huffyuv -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" $TMP_AVI seems to do the trick. – BenC Oct 1 '14 at 10:35
Some notes on installation of some of these things for anyone else without these already on their system – Louis Maddox Mar 24 '15 at 22:21

I had the same question and I couldn't find anything so I wrote this app myself:



share|improve this answer
It seems closed-source, shareware, and unscriptable, though much cleaner than any GUI alternative I've seen! Does it work on distros other than Debian? (I only see .deb packages mentioned in the purchase popup.) Can it capture fullscreen on small screens despite the capture window's border? – Anko Jun 22 '15 at 17:09
@Anko yea, it's closed since I've planned to use it only for myself but some people might find it useful too. I have plans to add rpm packages and tar.gz for distros like Arch in a week or so. It uses byzanz under the hood, to capture full screen you can install it and simply run: byzanz-record -w 1920 -h 1080 --duration 10 ~/recorded.gif – Constantine Jun 22 '15 at 20:30
@Constantine thanks, finally a gif recorded that works! Worth the $3. – Fabio Gomes Sep 25 '15 at 16:38
How can I test this before buying ? – Michal Przybylowicz Feb 2 at 14:33
Worked great and was super easy to install an use, unlike the arcane byzanz itself. Any chance to add an option to record click locations? TechSmith Camtasia shows ripples where the click took place, for example. – Dan Dascalescu Mar 7 at 23:24

For me, the answer was to use ffcast with ffmpeg like so:

ffcast -w % ffmpeg -f x11grab -show_region 1 -framerate 20 -video_size %s -i %D+%c -codec:v huffyuv -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" out.avi

I then used ffmpeg to do the conversion from avi to gif - it's very fast and it keeps the framerate intact:

ffmpeg -i out.avi -pix_fmt rgb24 out.gif

Lastly I used convert in the same way as @anko's answer to optimise the gif, but I set a limit on resource usage to stop convert exiting with a killed message, and I removed the delay as ffmpeg has already handled that:

convert -limit memory 1 -limit map 1 -layers Optimize out.gif out_optimised.gif
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.