Screen recording with Linux
Hello to my future self – I’ve anticipated that I will be back in the future to read this post because I’m sure I would have forgotten how to do this stuff. Firstly, a disclaimer – I am by no means an expert in this field, I just banged it ’till it worked. If you are having trouble doing similar things then I encourage you to post comments where they can be seen and responded to by all.
Secondly, an explanation of what it is I’m doing here. A while back I saw some screencasts re Inkscape at screencasters.heathenx.org. I was impressed – it was a great way to teach people how to use Inkscape.
I had a play around and managed to get to the point where I can now do the following:
- Record my screen, or any particular window
- Use my Logitech USB headset to record the audio
- Play the resulting movie back, sound through speakers or headset
For some reason I seem to be having a ridiculously hard time determining where the audio output goes for my Linux apps. In Windows, when I plug my headset in, it becomes the default audio device for all applications. Currently running applications still use their normal sound output, until restarted. If I dig deep enough I might even be able to find settings in each program that allows me to specify which sound device (headset or sound card) should get the output.
In Linux (Ubuntu 8.04, Gnome to be precise) I discovered under System > Preferences > Sound an application that allows me to adjust the sound preferences. In the dropdown list for each playback type I have seven possible playback device options (Auto, USB Audio, Intel ICH5, Intel ICH5 – IEC958, ALSA, OSS & PulseAudio). It seems that if I set them all to USB Audio then I get lucky and most things play through the headphones. Some things, especially the Adobe Flash Player plugin insists on playing through my desktop speakers regardless. I saw someone complaining that this was Adobe’s fault, not Linux but I can’t comment. In order to avoid all this confusion I found out how to specify the sound device that you want to use for each operation. This is pretty much the crux of this post.
Anyway, here’s what I did …
Recorded My Desktop
There’s a package in the Ubuntu universe repository called recordmydesktop which as the name suggests can be used to record your desktop, with sound. This is great for making recordings of how to do things to share with others. I installed the recordmydesktop package, along with the GTK front end to save me having to look up the commands all the time..
bob@sparkie:~$ sudo apt-get install recordmydesktop gtk-recordmydesktop
Once installed I then hit Alt-F2 (to bring up the Run Application dialog) and typed in gtk-recordmydesktop.
It seemed that by default it was trying to record sound via the mic input on my sound card. Fat chance it would have had because I don’t have a mic in my soundcard, instead I have a USB headset.
After Googling around I discovered that if I click the Advanced button in gtk-recordmydesktop I could then enter the sound device to use to capture audio. I used the device name “plughw:Headset,0,0″ and was able to record sound via my USB headset.
The key to this was finding out what to type in for the device name. I discovered the aplay and arecord utilities that allow you to play and record sound. Each utility has a -l switch which lists the available devices. Here’s the output of my arecord -l:
bob@sparkie:~$ arecord -l **** List of CAPTURE Hardware Devices **** card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: ICH5 [Intel ICH5], device 1: Intel ICH - MIC ADC [Intel ICH5 - MIC ADC] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: ICH5 [Intel ICH5], device 2: Intel ICH - MIC2 ADC [Intel ICH5 - MIC2 ADC] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: ICH5 [Intel ICH5], device 3: Intel ICH - ADC2 [Intel ICH5 - ADC2] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: Headset [Logitech USB Headset], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
You can see beside each “card” there is a device name, either ICH5 (my sound card) or Headset. Each of those cards has a number of subdevices – in the case of the sound card you can see there are four possible subdevices I could have chosen (numbered 0 to 3) and for the headset it’s a free ride because there’s only one to choose from (as I would have expected).
So, now that plughw:Headset,0,0 should make a bit more sense. With that all set up, I hit record, wiggled my mouse around, spoke some gibberish and created a .ogg file of my session.
Sound Recording and Playback
While I was debugging my sound devices I fiddled around a bit with arecord and aplay. Using the command arecord -Dplughw:Headset,0,0 -f S16_LE -c2 -r44100 > myfile.wav I created a 44kHz wav file using the headset mic as my recording device.
When I played it back with aplay myfile.wav, it played through my desktop speakers. To play it through my headset I just specified the device name as I did with the arecord command, thus aplay -Dplughw:Headset,0 myfile.wav
If you want to use mplayer to play something back using a specific device for audio output, this command will do the trick for you: mplayer -ao alsa:device=hw=1.0 ep069.flv. Device 1.0 is card #1, device 0 – and that’s the headset.
If you need to adjust the volume, I found you can use the alsamixer. To control each card you can specify which one with the -c switch. In my case card 0 is the default and internal sound card, and card 1 is the USB Headset: alsamixer -c 1
That’s all for now!