Screencasting with Linux

1560

Author: Chad Files

Many times a simple screencast showing how to do something by using a series of screenshots in sequence in a video can explain what paragraph after paragraph of words cannot. Linux and a few open source applications make the job of creating such screencasts easy.

There are several ways to grab screenshots in Linux. The method that I employ here is a shell script that uses the ImageMagick import program:

#!/bin/sh

# NTSC 720x486 in columns 88x27

i=0

while [ 1 ]
do
   x=$[i+10000];
   import -frame -window $1 "cap_${x/1/}.miff"
   i=$(( $i + 1 ))
   # sleep 2s
done

This script takes one parameter, the internal ID of the window that will be captured, which you can get by running the command xwininfo -frame. The xwininfo program will give you all of the X11 information about the window/frame that you click on, but the only line you need to see is the first one, which will look something like this:

xwininfo: Window id: 0xa0348b (has no name)

This ID is what you want to pass to the shell script. Once the script starts, it will save screenshots of the window in the directory in which the script was launched. The script will run until it is interrupted by your pressing Ctrl-c. Each image is given a sequential name in the form of cap_XXXX.miff. The miff image format is ImageMagick’s own format. ImageMagick can write miff images faster than any of the other supported image types, which is why we are using it here.

Making the video file

After all the screenshots have been captured, you can start putting them together in a video file. The ImageMagick convert program will combine all of the miff files into one video file. Run the command below in the directory where all of the screenshots are located:

$ convert -antialias -resize 720x486! -delay 60 *.miff capture.m2v
  • -antialias removes pixel-aliasing. This makes for a smoother-looking video.
  • -resize resizes all of the images to the specified size — in this case, that of an NTSC video. NTSC is the standard for analog television in North America.
  • -delay tells the convert program to pause between frames, in this case for 60 hundredths of a second. This setting will have to be customized almost every time you make a screencast, because the rate you speak and the rate the screenshots are taken will almost always change with every screencast.
  • One option that I did not use but which is worth mentioning is -quality, which controls the value to use when compressing the images. The larger the number, the larger the video file and the better the quality. However, this option tends to cause overflow problems and dropped frames, and too many dropped frames will result in an unusable video.

The result of the command will be a file called capture.m2v. The m2v format is an MPEG-2 video-only stream. The next step is to add audio to the video.

Capturing audio

You can use Audacity to capture audio for the screencast. You will obviously need a microphone hooked up to your computer, and the quality of the audio will be dependent on the quality of the microphone.

To start recording, open Audacity and press the red record button in the tool bar. When you are finished, save the audio file as a WAV file (File > Export As WAV). The WAV format is uncompressed and thus the best quality.

You can record when you are creating the screen captures, or after you’ve put the video file together. I find it beneficial to do both. I usually create a script and read it while making the screenshots. Then I put the video together and read the script again while it is playing back. Going through the script while capturing screenshots ensures that the captures are spaced correctly. Recording the audio a second time, while watching the finished video, allows you to concentrate on the audio portion.

Combining the audio and video

The final step in creating a screencast is to bring the audio and video together. One way to do this is to use mplex, an audio/video multiplexer that is part of the MJPEG toolkit, but to do so, you first need to convert the audio file from WAV to something that mplex can use with a command like:

$ ffmpeg -i audio.wav audio.mp3

Here, FFmpeg converts the original WAV file to MP3. You could also make the conversion with Audacity.

To combine the audio and video, use the command:

$ mplex -f 3 -o final.mpg capture.m2v audio.mp3

This command tells mplex to make final.mpg out of capture.m2v and audio.mp3. The -f option tells mplex that we want a generic MPEG2-coded video file. Now, final.mpg contains a complete screencast.

An alternative way to create the final screencast is to use Kino, a non-linear video editor, which gives you the opportunity to add extra features like titles and transitions to your screencast. Using Kino also allows you to combine the screencast with other videos and filmed footage.

To get started in Kino you must convert the captured video into the DV (Digital Video) format.

$ ffmpeg -i capture.m2v -target ntsc-dv capture.dv

Here, the -target option tells ffmpeg to convert the file into an NTSC-compatible DV video.

Now you can use Kino to add the audio track. In Kino, import the DV file (File > Insert Before). To add the audio, use the FX tools (Tab bar to the right of the stage). On the Audio Transition tab, change the value to Dub. Now browse for the audio file; Kino only accepts WAV files. Use the Preview button at the bottom of the screen to see and hear what the final video will be like before it is rendered. If you like what you see, click the Render button to make the video. From here you can export the video in various formats directly from Kino.

Conclusion

As you can see, creating a screencast with Linux is relatively painless, and you can apply the process to a multitude of tasks — provide visitors to your Web site with visual how-to help, show off an application to your friends, or create a stunning in-depth presentation for your boss.

Chad Files, a software developer from Arkansas, has been developing Web-based applications for more than 10 years, and is a contributing developer to many open source projects.