panthema / 2014 / vncrec-rgb

Patched vncrec-rgb 0.4 - Output Frame-Perfect RGB Screencasts Videos

No posts yet.

Posted on 2014-07-02 08:35 by Timo Bingmann at Permlink.

VNCrec is a modification of the vncviewer from AT&T Laboratories Cambridge. It allows to record packets at the VNC protocol level and replay them for viewing or creating screencast movies.

For more information why create screencasts with vncrec please refer to my two blog entries Recording Frame-Perfect, High-Resolution Screencasts on Linux in the Year 2014 and Experiences Producing a Screencast on Linux for CryptoTE from 2009.

The original vncrec (webpage/local copy) outputted XPM images. This was improved in the vncrec-twibright edition (webpage/local copy), which is a really nice piece of software, but it has one problem: bleeding edges and some "washed-out" colors. These artefacts are due to vncrec-twibright's conversion of the frames into the YUV 4:2:0 colorspace, which is nice for videos but of course does not match the RGB colorspace of a screencast.

Enhancements to vncrec-rgb:

And this is what I added to vncrec "rgb edition":


vncrec-rgb-0.4 (current) published 2014-07-02
Source code archive: vncrec-rgb-0.4.tar.bz2 vncrec-rgb-0.4.tar.bz2 (78.3 KiB) Browse online

The program is published under the GNU General Public License v2 (GPL), which can also be found in the file LICENSE.TXT.

A git repository containing all sources and revisions is fetchable by running
git clone

Sample Output

As an example, I did a very short recording of an xubuntu desktop: showing a terminal and a webpage in firefox. The recording was done via x11vnc on a VirtualBox.

This is the resulting VNC file: example.vnc (5.25 MiB), which was later encoded with lossless x264 into an AVI movie using ffmpeg: example-x264.avi (1.76 MiB). Then, the resulting x264 AVI video was converted into an animated PNG (APNG) with 25 fps, example-apng-25full.png (1.27 MiB):

Screencast APNG Video

Using vncrec and ffmpeg Encoding Incantations

Set up a VNC server, I highly recommend TigerVNC from, but VMware's VNC interface and most others work as well.

Start the VNC session up, e.g. on DISPLAY :1, so you can view it with VNC viewer as follows:

$ vncrec :1

Then you can record a VNC session "video" using:

$ vncrec -record out.vnc :1

The session can be terminated by pressing F8, and selecting Quit. Later, you can play it back by:

$ vncrec -play out.vnc

Playing Recorded VNC Sessions

The vncrec-twibright edition enables output of the session quickly into a 4:2:0 Y'CbCr YUV4MPEG2 video stream to stdout, and this format can be played directly by mplayer or ffplay:

$ vncrec -movie out.vnc -writeYUV | ffplay -f yuv4mpegpipe -i -
# or
$ vncrec -movie out.vnc -writeYUV | mplayer -demuxer y4m -

This format however has washed-out colors and bleeding edges due to the RGB to YUV conversion. Removing -writeYUV instructs vncrec-rgb to output raw RGB frames!

However, as raw frames have no width/height/framerate information, one needs to provide this information to ffmpeg directly. To make this easier, "vncrec -ffinfo" outputs the required ffmpeg parameters by inspecting the vnc session log:

$ vncrec -ffinfo -movie out.vnc
-pixel_format rgb24 -video_size 1600x1200 -framerate 25

Using backticks, one can play a record vnc session in RGB quality with ffplay using the following incantation.

$ vncrec -movie out.vnc | ffplay -f rawvideo `vncrec -ffinfo -movie out.vnc` -i -

The frame rate of the movie is 25 by default, but that can overriden by setting the VNCREC_MOVIE_FRAMERATE environment variable. For mplayer/mencoder the vncrec doesn't have a parameter generator, however, a command line similar to the following yields the same result:

$ vncrec -movie out.vnc | mplayer -demuxer rawvideo -rawvideo w=1600:h=1200:format=rgb24:fps=25 -

Encoding Recorded VNC Sessions into Video Formats

Of course, the movie output of vncrec can also be encoded by ffmpeg into a real video file. ffmpeg is a swiss army knife for video processing, you just have to find the right command line paramters. Today, ffmpeg has good a documentation and HOWTO wiki:

Currently, my favorite encoder is lossless X264 for screencasts. To encode a vnc file into a losslessly compressed .avi file do:

$ vncrec -movie out.vnc | \
ffmpeg -f rawvideo `vncrec -ffinfo -movie out.vnc` -i - \
-vcodec libx264 -crf 0 -preset ultrafast \

While this will convert the RGB stream into YUV, the conversion is done by ffmpeg and into YUV 4:4:4, which both result into a much higher quality! For the final encoding, one can replace "ultrafast" with "veryslow" for very small losslessly compressed files.

For a true losslessly encoded RGB video, the only option I know is ffmpeg's V1 codec:

$ vncrec -movie out.vnc | \
ffmpeg -f rawvideo `vncrec -ffinfo -movie out.vnc` -i - \
-vcodec ffv1 \

While my current system cannot play the resulting file without frame drops, the file format may be useful for further processing stages. YouTube will happily process both lossless formats.

Recording VNC Session with Audio

In Linux, the most simple method to record audio is to use ALSA's arecord tool. To start vncrec and arecord simultaneously one has to configure the VNC server without a password or provide a -passwd option, as seen below. The rest can be done using the shell to background the recording process:

$ (vncrec -record out.vnc -passwd ~/.vnc/passwd :1 &); arecord  -f cd out.wav

After recording both VNC session and audio, the two can be combined using ffmpeg and encoded into any desired format:

# encode into out.avi using FFV1 video and raw PCM audio
$ vncrec -movie out.vnc | \
ffmpeg -f rawvideo `vncrec -ffinfo -movie out.vnc` -i - \
-i out.wav \
-vcodec ffv1 \
-acodec pcm_s16le -shortest \

# encode into out.avi using X264 video and AAC audio
$ vncrec -movie out.vnc | \
ffmpeg -f rawvideo `vncrec -ffinfo -movie out.vnc` -i - \
-i out.wav \
-vcodec libx264 -crf 0 -preset veryslow \
-acodec libfaac -ab 128k -shortest \

Additional options and patches to vncrec-rgb

There are three additional small patches or features in vncrec-rgb:

Happy screencasting.