wiki:

Capture

/

ALSA


Version 1 (modified by burek, 7 years ago) (diff)

--

Syntax

Capturing audio with FFmpeg and ALSA is pretty much straightforward. Usual way to do this is like this:

ffmpeg -f alsa <input_options> -i <input_device> ... output.wav

Selecting the input card

input_device tells FFmpeg which audio capturing device/card you would like to use. To get a list of all supported devices, you can type arecord -l (small L) or arecord -L (longer output).

So, first, list your recording devices:

# 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: U0x46d0x809 [USB Device 0x46d:0x809], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

We can see there are 2 audio cards that provide capturing capabilities, namely "card 0" (Intel ICH5) and "card 1" (Microphone on the USB web cam). The easiest thing to do is to reference each of them directly using "-f alsa -i hw:0" or "-f alsa -i hw:1":

ffmpeg -f alsa -i hw:1 -t 30 out.wav

That will give us a 30 seconds WAV audio output, recorded from our USB camera's default recording device (microphone).

If you need a specific device from the specified card, then you can use hw:<X>,<Y> notation, where X=card, Y=device. For example, to select "MIC2 ADC" from Intel card, we would use:

ffmpeg -f alsa -i hw:0,2 -t 30 out.wav

But, if you reboot your machine, you will notice sometimes your cards get reordered, so "card 0" is listed as USB Audio and "card 1" is listed as Intel audio card. You might want to play with udev rules, but there is an easier solution for this. Typing arecord -L will give us a little bit more detailed listing of recording devices:

# arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ICH5
    Intel ICH5, Intel ICH5
    Default Audio Device
sysdefault:CARD=ICH5
    Intel ICH5, Intel ICH5
    Default Audio Device
front:CARD=ICH5,DEV=0
    Intel ICH5, Intel ICH5
    Front speakers
surround40:CARD=ICH5,DEV=0
    Intel ICH5, Intel ICH5
    4.0 Surround output to Front and Rear speakers
surround41:CARD=ICH5,DEV=0
    Intel ICH5, Intel ICH5
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=ICH5,DEV=0
    Intel ICH5, Intel ICH5
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=ICH5,DEV=0
    Intel ICH5, Intel ICH5
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
default:CARD=U0x46d0x809
    USB Device 0x46d:0x809, USB Audio
    Default Audio Device
sysdefault:CARD=U0x46d0x809
    USB Device 0x46d:0x809, USB Audio
    Default Audio Device
front:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    Front speakers
surround40:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=U0x46d0x809,DEV=0
    USB Device 0x46d:0x809, USB Audio
    IEC958 (S/PDIF) Digital Audio Output

We can tell FFmpeg exactly what card we want to use, specifying the exact card's name, no matter which ordering it is, like this:

ffmpeg -f alsa -i default:CARD=U0x46d0x809 -t 30 out.wav

This way, you're always asking for the input from that certain device and will never mix things up.

Also, you might find useful a tool named alsamixer.

It will let you visually select, for each specified card (intel or usb), which recording device do you want to use (if the specified card has got multiple inputs, like Line-In, CD-In, Mic, ...), so you can just run "alsamixer", press F6 to choose the card and then use TAB key to switch to recording devices (pressing it multiple times just switches between playback/recording/all devices), after that just use arrow keys to highlight desired device and just hit the SPACEBAR key to select it (and up/down, page up/dn keys to change the input volume).

Input options

.

Attachments (1)

Download all attachments as: .zip