Skip to main content

Screencasting for X11: an FFmpeg screen recorder

vnc2swf, vncrec, xvidcap. Either they can't record audio (vnc2swf, vncrec) or they can't keep audio in sync (xvidcap). xvidcap is the most advanced utility but it seem rather unmaintained and I also dislike the internal code structure (amorphic functions that behaviours strongly depend on semi-global state variables).

ffmpeg already comes with grabbing code, but only for V4L. The requirements are not so different from X11 grabbing, so I decided to hack a new X11 grabber into ffmpeg (after verifying that ffmpeg does correct A/V syncing).

The result is a working mixture of videograb.c of ffmpeg and capture.c/xtoffmpeg.c of xvidcap. I'm now able to do screencasts from X11 where I'm able to comment the things I'm doing via microphone.

Here is the patch for ffmpeg-0.4.9-p20051216: ffmpeg-x11-screen-recorder.diff. Compile like:

./configure --enable-x11grab --enable-gpl
Run like:
./ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -vd x11:0,0 -s 1280x1024 test.avi
The -vd option is required. The two values following the colon describe the left upper coordinate of the grabbing region. The -s option describes the grabbing size. I'm using a frame rate of 10fps (-r 10) and a group size of 300 frames (so you have an intra frame every 30 seconds).