codegourmet

savory code and other culinary highlights

Screencasting With Ubuntu as GIF

| Comments

Sometimes I need to send someone instructions on how to use software.

Instead of fiddling with annotated screenshots, wouldn’t it be nice to just send an animated GIF via email? Also, I now can show off my struggles with Vim! ;)

Here’s a setup that I found on the internet and it works like a charm with my system (Ubuntu 14.04 LTS and xmonad).

1. (optional) Install FFcast

FFcast is a tool to select a rectangular region with the mouse and pass this region as a geometry string to another command.

It can be installed like this (source: superuser.com):

1
2
3
4
5
6
7
sudo apt-get install autoconf automake build-essential checkinstall git libx11-dev x11-utils
git clone --recursive https://github.com/lolilolicon/FFcast.git
cd FFcast
./bootstrap
./configure --prefix=/usr/local --enable-xrectsel
make
sudo checkinstall --pkgname ffcast --pkgversion "1:2.4.1+git$(git rev-parse --short HEAD)" --fstrans=no --default

2. Install ffmpeg

ffmpeg isn’t part of Ubuntu anymore, so you won’t find official ubuntu packages for it.

But I found this instruction for Ubuntu 14.04 on the Ubuntu forums:

1
2
3
4
sudo add-apt-repository ppa:jon-severinsson/ffmpeg
sudo apt-get update
sudo apt-get install ffmpeg
sudo apt-get install frei0r-plugins

3. Wire it all up

The following is a nice script I found on stackexchange, just put it somewhere in your PATH:

1
2
3
4
5
6
7
8
#!/bin/bash

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 8 -layers Optimize $TMP_AVI out.gif

I had to adapt the - set delay convert option from 10 to 8, else it would play in slo-mo!

It works!

Above script uses ffcast to let you draw a rectangle with the mouse. This is passed on to ffmpeg, which records a video into a tempfile. The result is then converted to a gif file out.gif in the current working directory.

I’d like to add a delay to the start of recording, but haven’t managed that yet.

4. Selecting windows via mouse click and more

Note that ffcast can do a lot more, for example if you’re using the -w option you can select a window via mouseclick, instead of a region. You can even use -ww to select two windows, whose regions will get combined! Type man ffcast to get more information on this.

Also, there’s a way to register subcommands with ffcast, take a look into the manual and/or /usr/local/libexec/ffcast/subcmd. There’s already a screencast command named rec, but I haven’t tested it out yet since above script works so well.

Happy Coding! – codegourmet

Comments