Wednesday, August 5, 2009

old school screencasting

Screencasting with GNU screen and ImageMagick.

Something I just stumbled over the other day while putting together some screencasts for a Linux class I teach is that between the ability of GNU screen to write hardcopies of the terminal and ImageMagick's text image format... terminal sessions can be screencast as simple animated gifs with a couple config tweeks and a command or two.

First, configure screen, you'll need a recent enough version to have the "idle" command.

hardcopy_append on
idle 1 hardcopy

This will configure screen to take a snapshot every time you pause for a second. Ok, I know, its annoying to have to stop for a second between each key to get the individual keys to show up one at a time. On the other hand, you get used to it and slowing down helps me to avoid typing mistakes while screencasting.

So, fire up screen and start demonstrating away. When you are done, you will have a rather large hardcopy (usually, hardcopy.0) your terminal at one second intervals. A quick sed script to strip out the line delimiter screen places between each hardcopy like so, pipe to split to make one file per capture (assuming your terminal is 24 lines).

sed '/^.==*.$/' hardcopy.0 | split -l 24
Ok, now with one file per second for our entire terminal session, it is time to fire up convert from the ImageMagick suite. convert has the ability to read plain text files, render the text in an image and then write that image in a variety of formats. Of those formats, gifs support adding multiple images to create an animation. So, take all those files created by split as input, write one animated gif as output.

convert -extent 576x320+38+36 -font LucidaCons text:x?? -negate -loop 0 screen.gif

And there you have it, and old school screencast that will make your vnc-recording, windows-installer-running, heavy-weight-video-editing friends jealous.

1 comment:

Anton Vasiljev said...

You can make just plain text terminal screencasts with http://shelr.tv/

Records can be replayed on the web or in your own terminal.