Eric Radman : a Journal

Screencasting with OpenBSD

USB Audio

Any USB microphone should appear as a new audio device

uaudio0 at uhub3 port 4 configuration 1 interface 0 "Logitech USB Headset"
uaudio0: audio rev 1.00, 6 mixer controls
audio1 at uaudio0

audioctl can read off all of the specific characterisitcs of this device.

$ audioctl -f /dev/audio1 | grep record
record.rate=44100
record.sample_rate=44100
record.channels=1
record.precision=16
record.bps=2
record.msb=1
record.encoding=slinear_le
record.gain=127
record.balance=32
record.port=0x0
record.avail_ports=0x0
record.seek=0
record.samples=0
record.eof=0
record.pause=0
record.error=0
record.waiting=0
record.open=1
record.active=0
record.buffer_size=65536
record.block_size=4400
record.errors=0

Now test the recording using the sun:1 to specify audio device 1 using aucat(1)

aucat -m rec -f sun:1 -o file.wav

If the device also has a headset audio can be played through the same ddevice.

aucat -f sun:1 -i file.wav

Screen Capture using Xvfb

The rate at which a framebuffer for your video card is a feature of the hardware and software your using, and it's often very slow. x11vnc will print an estimate of the banwidth for the system your running.

x11vnc
...
09/05/2012 22:23:45 fb read rate: 7 MB/sec

This is about 4fps. We can do much better by using a virtual framebuffer. Here I'm setting up a new screen, setting the background color, starting cwm and an instance of xterm

Xvfb :2 -screen 0 800x600x16 &
DISPLAY=:2 xsetroot -solid steelblue &
DISPLAY=:2 cwm &
DISPLAY=:2 xterm +sb -fa "Inconsolata" -fs 12 &

Much better! Now we're up around 20fps.

x11vnc -display :2  &
...
11/05/2012 18:04:07 fb read rate: 168 MB/sec

Make a connection to this virtual screen using raw encoding to eliminate time wasted on compression.

vncviewer localhost -encodings raw

A test recording with sound then looks like this

ffmpeg -f s16le -i /dev/audio1 -f x11grab -s 800x600 -i :2.0 -vcodec ffv1 out.avi

Screen Capture using Xephyr

Xephyr is perhaps the easiest way to run X with a shadow framebuffer. This solution also avoids reading from the video card's RAM, so it's reasonably fast.

Xephyr -ac -br -noreset -screen 800x600 :1 &
DISPLAY=:1 xsetroot -solid steelblue &
DISPLAY=:1 cwm &
DISPLAY=:1 xterm +sb -fa "Inconsolata" -fs 12 &

Capture works in exactally the same way. This command tries to maintain 15fps.

ffmpeg -y -f x11grab -s 800x600 -i :1.0 -vcodec ffv1 ~/out.avi

Audio/Video Sync

If you find that the audio is way out of sync with the video, you can ajust the start using the -ss before the audio input to specify the number of seconds to delay. My final recording command line, that delays the audio by 4.3 seconds, writing 10fps

ffmpeg -ss 4.3 -f s16le -i /dev/audio1 -y -f x11grab -r 10 -s 800x600 -i :2.0 -vcodec ffv1 ~/out.avi

Sharring a Terminal with tmux

If you're trying to record a terminal session, tmux is able to share a session. In this way a recording of an X framebuffer can be taken without even using the screen. Start by creating the session.

tmux -2 -S /tmp/tmux0

Then on the remote side connect on the same socket

tmux -2 -S /tmp/tmux0 attach

References

x11vnc FAQ

Awesome guide to Using Xephyr

$ 2012-08-24 20:18:08 -0400 $