Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 16 down vote accepted

OK then

ffcast -s ffmpeg -r 15 -- -pix_fmt rgb24 out.gif

GIF vimcast!

I selected a region, did some vim, pressed q, got a .gif.
(I ran that command in another terminal.)

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, ffmpeg, libx11, xorg-dpyinfo and xorg-xwininfo.

Internally, it works by invoking xrectsel from libx11 (the same standard function scrot uses) and letting the user select a screen region. It then substitutes the correct dimensions for %x, %y, %w, %h and %d in the given command. There's a preset for ffmpeg, which automatically inserts the correct selection area flags for it to record video.

You can also append ffmpeg flags right after the command. Conveniently, ffmpeg can output .gif files if you specify -pix_fmt rgb24. Then there's no need for an additional conversion step from some video format to GIF.


The -r flag specifies frame capture rate (set to 15 frames per second in the example). Keep file size in mind when changing this.

ImageMagick has some GIF optimisation tricks that drastically reduce file size, preserving quality: convert -layers Optimize out.gif out_optimised.gif invokes the general-purpose optimiser. There's an ImageMagick manual page on advanced animation optimisations.

I've strung these together as

ffcast -s ffmpeg -r 15 -- -pix_fmt rgb24 out.gif \
    && echo "Optimising" \
    && convert -layers Optimize out.gif out_opt.gif \
    && echo "Done!"

in /usr/local/bin/gifcast.


share|improve this answer
This is really cool. Thanks for sharing. –  WhiteHotLoveTiger Feb 5 at 18:35
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 at 4:31
add comment

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.