...making Linux just a little more fun!
Capturing screenshots has been an invaluable tool for users of graphical environments for a long time. Utilities like import, the Gimp's acquire screenshot, and those included with one's preferred window manager or desktop environment enable users to share screenshots of their desktop and enhance tutorials by not just writing about how to do something, but also providing images for reference.
But how about taking this to the next level, and instead of merely providing a static image, play a nice video clip which clearly demonstrates the steps being explained? Such a screen recording would be an invaluable complement to tutorials and demonstrations, and have many other practical purposes.
Unfortunately, a quick search on Google reveals that the choice of screen recording applications on Linux is pretty sparse. While other Operating Systems have a wide array of commercial and shareware applications available for screen recording, Linux seems to come up short. But two applications rise to the surface as outstanding utilities to fit this niche: vncrec and vnc2swf. What makes these utilities even more useful is that they take advantage of Virtual Networking Computing, commonly called VNC. VNC was developed by Olivetti Research Laboratory (ORL) and has been a staple tool for system administrators everywhere. VNC's greatest benefit is its cross-platform capability.
VNC makes use of thin-client technology to create a session between a VNC server and VNC client via an IP connection. This session allows the VNC client to either take control of the VNC server, watch what is happening on the VNC server, or engage in a group view where any number of VNC clients connect to a VNC server. Both the VNC server and client run on most modern operating systems. You can run the server on a Windows workstation and connect with the client running on Linux. Or, you can run the client on NetBSD and the server on Mac OSX.
This article assumes you know the basics of running both the vncviewer and vncserver. For complete documentation on VNC consult the Real VNC website and documentation files included with VNC.
With vncrec and vnc2swf the capabilities of VNC are taken to another level by allowing the recording of VNC sessions for future use. This is one of the rare screen recording applications that is not limited to capturing a single platform, as you can easily record Windows, Linux, OS X, and Solaris sessions. Currently, though, vncrec and vnc2swf only run on Linux, OS X, the BSD's, and other Unix based OS's.
Vncrec was developed by Yoshiki Hayashi and released under the GNU GPL. The source code is available at www.sodan.org/~penny/vncrec. The current version is 0.2 and very stable. The only requirement to compile vncrec is Xvnc which is included in the download of VNC from Real VNC. After fulfilling the requirement and unpacking the sources, vncrec is built issuing these commands in the vncrec-0.2 directory:
xmkmf make WorldAfter a successful compile vncrec will be ready for use in that directory, or you can run make install as root to install vncrec.
Vncrec is used to both record and play back a vncrec session. If you are familiar with vncviewer's (the VNC client program) options you will notice that vncrec adds three more parameters for recording and playback of vncrec sessions:
The play option will play back a recorded VNC session. Playback of a recorded VNC session is optimal if the playback is done on the same machine that performed the recording. Many times playback on other machines fails to produce a viewable session. There tends to be extreme distortion, or just a black screen.
Vncrec's third option: -movie will extract each frame of the recorded session out to an .xpm file. Before you call this option it is recommended that you do so in a separate directory dedicated for these frame exports only.
To start recording a VNC session simply enter the following command:
vncrec -record filename servernameFor example:
vncrec -record session1.vnc 192.168.0.130You will be prompted for the VNC server's password. After authentication you will connect to the VNC server much like you would with vncviewer. When you are ready to terminate your session press F8 which will produce the following menu:
Now that you have captured your first session, enjoy the playback:
vncrec -play session.vncYour recorded session will now be played through vncrec. If you watch the session all the way through it will close upon completion. To terminate the session before completion press ctrl-c in the terminal you issued vncrec from (the F8 menu is not accessible during playback).
In addition, the homepage for vncrec and the README included with the sources provides some other examples on how to use vncrec. As always, vncrec -help will produce the basic usage and outline the accepted options.
There are a handful of different options you can pass to vncrec just like you can pass to the regular vncviewer, such as depth, geometry, shared, and fullscreen. These options generally do not produce the desired results when issued with vncrec. For instance, you can try to specify a different geometry for vncrec to use but it will drop back (or up) to the screen size run by the server. The same will occur with depth. If you pass the fullscreen option you will still get a screen size and a recording screen size that equals the geometry of the server screen. If the geometry of the server is smaller than that of the workstation you are running the recording session from, the vncrec session will be centered on the screen with the excess screen real estate forming a black border around the session (which will not be recorded). Playback using the fullscreen option will produce the expected results: Full screen with a border should the recording geometry be smaller than that your workstation's geometry.
There are some options that do make a difference. One of those is the truecolour option. Particularly when connecting to other operating systems that are using a "truecolour" screen depth (usually 24 or 32 bit color depth), specifying truecolour can help reduce any anomalies in the session. This is particularly pertinent when recording sessions connected to Windows workstations.
Both the vncviewer and vncrec support the viewonly options where the client connects to the VNC server but only for viewing purposes. There is no keyboard or mouse control passed between the server and the client. The viewonly options would be practical to record a session where a third party is conducting a demonstration.
Vncrec cannot export the session to a video format like mpeg or avi. Transcode provides the necessary codecs for converting a vncrec session into any other video codec supported by Transcode.
Vncrec does not record audio as VNC does not support audio transfer. Users can work around this limitation by employing Transcode to stream an audio track, created separately, into the final video.
This section will cover how to convert a vncrec session to a video codec supported by transcode or mencoder. We will also cover the -movie option of vncrec. To follow along with the examples you will need a current version of Transcode (version 0.6.12 is the current stable as of this writing but any version from 0.6.9 should work),Mplayer (version 1.0pre3 is the latest), and a recent version of ImageMagick (version 5.5.7 was installed on the testing workstation).
The greatest advantage of exporting the vncrec session to a video codec is portability. This allows your recorded session to be usable outside of the vncrec application and on other workstations that run a video player supporting the codec used to encode the vncrec session. Transcoding a vncrec session into a cross-platform viewable video file requires that you have compiled transcode or installed a binary package of transcode compiled with the necessary codecs acceptable for use by the other operating system. Inquisitive readers are directed to the Transcode website for more information.
There is a wonderful example of using transcode to encode a vncrec session into an avi file that was created by Tilmann Bitterberg and is available from the vncrec website. This section will expand on that video and hopefully add some useful information.
The basic syntax for transcoding a vncrec session into an avi file is:
transcode -i session.vnc -g 800x600 -y xvid -o session.avi -k -zThe -i switch designates the input file and -g declares the video stream frame size, which in this case is 800x600. Inclusion of the -g switch may be required depending on the version of transcode you are using and how it was compiled. Not declaring the video stream frame size may produce an error message like this:
[transcode] critical: static framebuffer allocation failedThe -y switch declares the video export module, in this case xvid. The output file, designated by -o, is session.avi. The -k and -z switches are optional, but may be necessary for proper output. The -z switch will "flip video frame upside down," so if you your output video looks like a mirror image of what you are expecting, you need to pass this switch. -k will swap the red/blue in the video frame to produce more accurate colors.
Transcode has more extensive features and will even allow you to include an audio channel in the final output. Thus, one could include audio commentary or instruction to the video. Curious readers are encouraged to visit the transcode site and documentation for more information.
If for some reason the playback of your transcoded session is not optimal, there may be some artifacts or distortions along the bottom and left edges of the video. You may want to try resizing the video during the transcode process. Standard video sizes follow an aspect ratio divisible by 32, 16, 8, 4, or 2. Typical sizes include 800x600, 640x480, 720x480, 480x260, 320x172, and 240x128.
Resize the vcnrec session with transcode can be accomplished using the -Z switch:
transcode -i session.vnc -g 800x600 -y xvid -Z 720x480 -o session.avi -k -zIn this example the original 800x600 session is reduced to an avi file that is 720x480. There is more to the -Z switch, like the capability of augmenting the type of filtering. Furthermore, there are other resizing switches one may want to employ. These switches are explained in the transcode man page.
Remember that the resize value should be a factor of 32, 16, 8, 4, or 2. Some of the resize switches used by transcode require a strict ratio be applied. Consult the Transcode website for in depth coverage and examples.
Finally, keep in mind that clarity of the video decreases proportionally with size. Transcoding an 800x600 vncrec session to a 240x128 sized .AVI file will produce a video that is next to impossible to watch, especially if there is text to be read.
Creating cross-platform compatible videos using transcode can be difficult. In fact, the author and his colleagues had a problem doing this. You must use a codec that is available on the target system[s]. If your video is made available as a download to the public, it may be difficult to guarantee that the recipient[s] will have the necessary codecs installed.
Another quirk found with transcode is a tendency for the transcoding process to bail out before completing. One particular problem is when the vncrec session involved browsing the Internet. When the browser window changes in the vncrec session transcode exits without an error. (This was tested on multiple machines with consistent results.) A possible reason is that the workstations did not have enough memory and processor speed to handle what was required by transcode. Transcoding a vncrec session of a browser using a 2ghz machine produced the desired results. Interestingly, the sample video created by a transcoded vncrec session showed the creator using a web browser, albeit Netscape 2.1.
Successful conversion of a vncrec session does not depend on transcode alone. If your vncrec session suffers from the drop out problem described above, you may want to give mencode a shot.
Vncrec has an option to dump out each frame from of the vncrec session to a .xpm file. By using the -movie switch each frame will be dumped out in sequential order give an appropriate file name to maintain that order:
vncrec -movie session.vncBefore executing this command it is recommended you start in an empty directory, or alternately a directory created for the purpose of holding these files, as this command will most likely generate up to a few thousand files.
Once you have the vncrec session exported to individual frames you will convert these frames to a format mencoder can handle. (For the purposes of this article jpeg will be the format used.) This is easily accomplished using mogrify (part of the ImageMagick suite):
mogrify -format jpg *.xpmMogrify will convert each .xpm file to a .jpg file. This can take some time depending on the number of files and the hardware specifics of your workstation.
Once the conversion process is finished, use mencoder to sequentially encode them into the video format of choice:
mencoder \*.jpg -mf on:fps=8 -o session.mpg -ovc lavc -lavcopts vcodec=mpeg1videoThe "-mf on:fps=8" tells mencoder to turn on the multiple files option and encode at 8 frames per second all the jpg files in the same directory. The output file, -o, will be session.mpg. Mencoder will use the lavc (libavc codec) as the output video codec (-ovc) and pass the lavc option (-lavcopts) to create a mpeg1 video. Once the conversion process is finished, the resulting video should be playable on any media player capable of playing mpeg1 video. Furthermore, the file size should be very small.
In summary, the vncrec utility makes it a snap to capture vnc sessions on any platform the server is running on. File sizes of the sessions tend to be small. There is a tendency for the recorded session to only playback on the machine it was recorded from. Although there is no native export to standard video codecs, vncrec sessions can be encoded to a video using transcode. Additionally, individual frames can be exported from the session and later pulled together using mencoder.
The second screen recording utility examined can be considered a cousin to vncrec: Vnc2swf. Vnc2swf exports the screen recording to Flash format for playback, either embedded in a web page using a browser with the Macromedia Flash plug-in, or a standalone Flash player.
Vnc2swf, distributed under the GNU GPL, can be downloaded from http://www.unixuser.org/~euske/vnc2swf and requires that you have the Ming library installed. The Ming library allows applications to export to the Flash format. As of this writing the latest version of ming-0.3alpha2 will not work with the current version vnc2swf (version 0.3), Ming version 0.2a had no problems. I strongly recommend starting with Ming 0.2a.
After extracting the Ming library, you may want to edit the Makefile and change some parameters (like installation destination). To compile simply:
make make install (root access required)There are more installation scenarios for Ming such as integrating with PHP and Python. Review the README file for more information. The above provides the basic installation necessary for vnc2swf.
Compiling vnc2swf takes three steps:
./configure make make install (root access required)
Like vncrec, vnc2swf has similar command parameters to vncviewer, with some added options for recording the session. Unlike vncrec you do not have to start recording the vnc session right away; you can start the recording via the F8 menu. This also means you can stop a recording without closing the session and even pause, then resume the recording later on--two features not available in vncrec. Another interesting feature is the ability to record a sound file in conjunction with the session. Right now the mp3 format is supported and must be generated beforehand. You can pipe in live miked audio, but this requires patching the Ming Libraries. The patch and directions are provided with the vnc2swf sources. See the README file for more information
Execution of vnc2swf is as simple as vncrec. For example:
vnc2swf -truecolour -startrecording sample.swf localhost:1This starts recording (-startrecording) a vnc session to the server running on localhost:1 using the truecolour parameter and outputting to sample.swf. If we did not specify the startrecording parameter, then we would need to start the recording via the F8 menu, which is a bit different than that for vncrec:
Vnc2swf will allow you to loop in a pre-recorded mp3 file using the -soundfile option:
vnc2swf -soundfile music.mp3 sound_sample.swf localhost:1Notice that the -startrecording option was not used in this example. This means that recording would have to be started in the vnc2swf session either by the F8 menu or pressing F9. The mp3 file is looped into the Flash output only when the vnc2swf session is recording. Thus, the mp3 will start recording into the flash when recording starts on the vnc2swf session. Furthermore, if you pause the recording, the mp3 recording will also pause. Upon resuming the recording, the mp3 will continue from the point it was left off.
Adding an audio track to a tutorial session can be a bit tricky. Getting the audio to sync with the video is key for proper effect. The best option is to follow the directions in the vnc2swf README file to patch the Ming library and allow live miked audio to be recorded by vnc2swf through a pipe. But there are other methods to accomplish this task.
First and foremost, you should carefully plan your tutorial. You may want to create some story boards and even script a dialog. Adequate preparation is essential for a polished product.
Once your script is complete you will record an audio session. Most Linux distributions have some recording software installed. Sox is a command line utility that will record audio in from your sound card to a .WAV file. Both Gnome and KDE have recording applications. There are also a number of graphical programs like Audacity and ReZound that are excellent choices. Use any one of these to create a .WAV file of your script. Be careful not to rush through your script. Leave pauses long enough to account for your actions and how long they may take to execute in the session. It is also recommended to create a seperate count-down .WAV file (a recording counting down from 5 is adequate).
After creating a .WAV of your script use an encoder like Lame to convert the .WAV to an .MP3 file for use by vnc2swf.
The difficulty is in making sure the audio is synced with the video. Since vnc2swf will not play the audio while recording the session, you will need to play the audio through another program while recording. I.e.; the recommendation for two files. Furthermore, creating the count down audio will provide enough time to start the recording. You may want to reherse the process before recording using vncviewer instead of vnc2swf with the next few steps.
Open up two xterm sessions: One to run the vnc2swf session and the other to play the scripted audio so you can follow along. In the first xterm start your vnc2swf session without the -startrecording option and make sure you specify the audio file with the -soundfile option:
vnc2swf -audiofile audio.mp3 session.swf :1In the second xterm set up to play the count down and .WAV version of the audio file. You may also want to add a few extra buffer seconds to give you time to switch back to your vnc2swf session by using the sleep command:
sleep 5; play countdown.wav audio.wavAt the end of the count down press the F9 key to start the recording and follow the directions of your audio script. Upon completion press the F9 key to stop the recording and then exit vnc2swf. Play the Flash session back in a web browser or through gflashplayer.
If you stop recording the vnc2swf session, but do not exit, this will pause the audio recording. Resuming the recording will continue to record the audio into the session from where it was left off. Should your tutorial contain needless filler like internet downloads or program compiles, you can break the audio file you are following up into parts and repeat the above steps toggling the F9 key to pause each part until the filler completes.
Getting the audio and video to sync can be a tricky process. You may need to repeate the vnc2swf recording process above a few times until you get the hang of it.
Once your Flash recording has been created you should embed the Flash in some HTML code, specifying the height and width value of the Flash file. Failure to do so will result in distorted playback. Here is sample code:
<embed src="sample.swf" width="800" height="600" loop="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">This code should work without a problem on Mozilla-based browsers. For Internet Explorer you will need to make use of the <object> tag. Notice that the width and height values of the Flash file are specified. Also, the loop="false" will prevent your Flash from looping continuously. You can also specify a numeric value to have the Flash loop "x" number of times. For more information on embedding a Flash file in a web page check out Macromedia's Technote on Object and Embed Tag Syntax. The vnc2swf session can be played in a standalone Flash player (i.e.; gflashplayer). Playback will suffer the same distortions as when played in a web browser without embedding the Flash in HTML and specifying the height and width, unless you specify playing at 100%. The 100% option is available under the View menu.
Hopefully this overview of VNC recording utilities has sparked some interest in playing with these tools and putting them to practical application. This article has only scratched the surface, the rest is up to your exploration. For instance, you can record real-time audio with vnc2swf, but this requires patching Ming (hint: see the vnc2swf README file). You can also add audio to transcoded vncrec sessions for which one is directed to the transcode documentation. As always, have fun.
O'Reilly has an excellent article in their Linux DevCenter site on creating a bash script that uses applications standard in most Linux distributions to create screen recordings. For more information read the article: Making Screen-Capture Movies by Robert Bernier.
Dann is die-hard Slackware enthusiast who lives in Bethlehem, Pennsylvania,
USA. About 6 years ago he decided it was time for a career change and left the
field of Psychology for Computers and Network administration. Taking a job on
the "bench" at a local office supply chain for ground level experience, he
stumbled upon a boxed copy of Red Hat Linux 6.0. After that there was no
turning back. a few months later Dann co-founded the Lehigh Valley Linux Users Group
which is still running strong today. In addition to the LVLUG, Dann operates
his own domain thelinuxlink.net which
strives to be a portal to Linux and Open Source happenings in and around the
Lehigh Valley, PA, USA. He is one of three hosts for the weekly Linux Link Tech Show, a streamed
web radio show. Dann is currently employed as an Applications Specialist for a
local school district. His wife and two daughtes do their best to tolerate his