Get front row seat and watch the development of micro-isv. We make cool product that solves all your problems...

logo

Friends
         
Opensource screen casts: VNC Blender and Mencoder
2009-01-07

Here's my notes on how to make screen casts using a (mostly) open source software stack. We use Vnc to capture the desktop in a cross-platform way, then record that to a dump file with pyvnc2swf. We convert that to a sequence of raw images using edit.py (part of pyvnc2swf), and load the resulting image sequence in blender's video editor.

We can use blender to edit the video and add effects like picture in picture or an overlay, then encode the lot to h264 or flv and play it with a flash player.

Blender will treat a sequence of images as a video: In the VSE timeline do add → images, select the directory with the images in, press 'a' to select them all and click 'Select Images' to import them.

Capturing

# Start x11vnc with 'Copyrect' disabled, since pyvnc2swf doesn't know about it
x11vnc -nowcr

# Start recording
pyvnc2swf-0.9.5/pyvnc2swf/vnc2swf.py -r 10 -o recording.swf myhost:0
# ...Write a wiki in 19 minutes...

# output 1 frame every 3 seconds, to see which bits of the desktop to display
pyvnc2swf-0.9.5/pyvnc2swf/edit.py -R 30 -o recording-overlay2.bmp -t bmp  recording.swf 

Now look at recording-overlay*.bmp in gimp and decide that the 640x480 at 1224+184 is our openoffice session, which we want to show.

mkdir openoffice
pyvnc2swf-0.9.5/pyvnc2swf/edit.py -o openoffice/office.bmp -C 640x480+1224+184 -t bmp  recording.swf 

After repeating this for other windows, we now we have a bunch of directories that contain view of of the various important windows on our main (large) desktop. Go to blender and edit these into a movie.

Capturing From UltraVNC

It appears that pyvncswf doesn't do a good job of negotiating the VNC connection settings with UltraVNC. This bit me when recording a Windows session (running on Amazon EC2, but that's another story). The answer here is to use a slightly different incantation:

# Start recording (UltraVNC)
pyvnc2swf-0.9.5/pyvnc2swf/vnc2swf.py -r 10 -e 4 -o recording.vnc myhost:0

Encoding

Blender can encode the output directly using ffmpeg, but I prefer to use mencoder, since it has more flexibility. First export the movie from blender as a sequence of PNGs, then encode using mencoder:

# encode the video (lavc gives better quality than x264, somehow)
mencoder -o vid.avi -of avi -ovc lavc -oac faac -lavcopts \
 vcodec=libx264:vbitrate=80:keyint=50:vpass=1 \
 -faacopts mpeg=4:object=2:br=80 -fps 10 mf://blender-output/*.png \
 -audiofile blender-output/0001_0237.wav 

# split the audio and video
mencoder -ovc copy -oac copy -of rawaudio -o vid.aac vid.avi
mencoder -ovc copy -oac copy -of rawvideo -o vid.h264 vid.avi

# mux the two together in a mp4 stream
MP4Box vid.mp4 -new -add vid.h264 -hint -inter 500 -add vid.aac

# encode flv
mencoder -o vid.flv -of lavf -ovc lavc -oac mp3lame -lavcopts \
 vcodec=flv:vbitrate=100:trell:keyint=50 -fps 10 mf://blender-output/*.png \
 -audiofile blender-output/0001_0237.wav -lavfopts format=flv
flvtool2 -UP vid.flv

These can be played in flv-scrubber or JW Player. Note that 'keyint=50' is required to make seeking work.

Overlays

Overlays can be created by creating a transparent png in Gimp/Inkscape and adding the image to the Blender VSE. In order to make it work right, three settings have to be made on the Sequencer button bar. With the image strip selected:

  1. Enable 'Premul' in the 'filters' section, to make Alpha blending work

  2. Change 'Replace' to 'Alpha Over' in the 'Edit' section

  3. Enable 'Use Translate' to stop the image scaling, and adjust the positioning of the overlay with the 'X-Ofs' and 'Y-Ofs' controls below

Reducing File sizes

The disk space taken up by raw bmp files is quite large (but so are modern disks). Pyvnc doesn't like producing output in other formats (at least on my machine). It is quick to convert them to PNGs though:

mogrify -format png *.bmp

or

find . -iname '*.bmp' | xargs mogrify -format png

The 'Real' solution would be to teach blender how to read vnc dump files. Making pyvnc/edit produce PNGs directly is probably easier, but that will have to wait for another day.