X11 screencast (with audio)
Screenrecording of a 1024x768 pixel area, with an x/y-offset of 80/120px. Sound is recorded at a bitrate of 128kb/s from the analog input of the default ALSA sound card, the outline of the captured region is displayed on screen:
avconv -f x11grab -show_region 1 \
-s 1024x768 -i :0.0+80,120 \
-f alsa -i hw:0 \
-b:v 1200k -b:a 128k \
-y ~/screencast.mpg
Don't forget to check the mixer settings!
Recording sound from another application instead of an external source requires to modprobe
the snd_aloop
kernel module and a line of ALSA configuration:
### File: ~/.asoundrc
pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }
Additionally, the avconv
audio input parameters need to be changed to
-f alsa -i hw:Loopback,1,0
The configuration of an optional output channel for audio monitoring is described here at ffmpeg.org.
ALSA: changing audio device priority
ALSA enumerates available audio devices in the order their corresponding kernel modules are loaded, so e.g. connecting an audio capable HDMI device can break on-board sound. For a permanent and system wide change of audio device priority, this order can be manipulated by adding a simple configuration file with the suffix .conf
to the folder /etc/modprobe.d/
.
First it needs to get a list of the loaded sound modules:
$ cat /proc/asound/modules
0 MODULE_X
1 MODULE_Y
2 MODULE_Z
In the best case, all audio devices use different kernel modules, which will be listed, one per line, with the key options
and an index
value:
### File: /etc/modprobe.d/alsa.conf
options MODULE_1 index=0
options MODULE_2 index=1
options MODULE_3 index=2
If there are several audio devices based on the same chipset, additionally their associated card IDs need to be specified. The command
$ aplay -l | grep ^card
will return the necessary identifiers in the second column, right after card #:
. Add them to the respective lines in /etc/modprobe.d/alsa.conf
as new column three, between module name and index number.
To be prepared for the occasional use of a USB audio adapter, I suggest to additionally list the snd-usb-audio
module and assign it index=0
.
Here my current configuration:
### File: /etc/modprobe.d/alsa.conf
options snd-usb-audio index=0
options snd-hda-intel id=VT82xx index=1
options snd-hda-intel id=HDMI index=2
Although this is Linux, the easiest way to make the changes take effect is to reboot the system ;)
If you have several devices with the same ID, you can make ALSA directly address the hardware by adding the following entries to /etc/asound.conf
or ~/asoundrc
- the respective card number can again be determined with the command aplay -l
.
### File: /etc/asound.conf
### OR
### ~/.asoundrc
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
Note: This way no other applications can access the sound card concurrently.
As a last solution, it is possible to fully disable specific cards with a line like the following in /etc/modprobe.d/alsa.conf
:
### File: /etc/modprobe.d/alsa.conf
options snd-hda-intel enable=0,1
The array will disable (0
) the first and enable (1
) the second of two cards.