Changes between Initial Version and Version 1 of Capture/ALSA


Ignore:
Timestamp:
Jul 5, 2012, 7:42:14 PM (7 years ago)
Author:
burek
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Capture/ALSA

    v1 v1  
     1= Syntax =
     2
     3Capturing audio with FFmpeg and ALSA is pretty much straightforward. Usual way to do this is like this:
     4{{{
     5ffmpeg -f alsa <input_options> -i <input_device> ... output.wav
     6}}}
     7
     8= Selecting the input card =
     9
     10'''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).
     11
     12So, first, list your recording devices:
     13{{{
     14# arecord -l
     15
     16**** List of CAPTURE Hardware Devices ****
     17card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5]
     18  Subdevices: 1/1
     19  Subdevice #0: subdevice #0
     20card 0: ICH5 [Intel ICH5], device 1: Intel ICH - MIC ADC [Intel ICH5 - MIC ADC]
     21  Subdevices: 1/1
     22  Subdevice #0: subdevice #0
     23card 0: ICH5 [Intel ICH5], device 2: Intel ICH - MIC2 ADC [Intel ICH5 - MIC2 ADC]
     24  Subdevices: 1/1
     25  Subdevice #0: subdevice #0
     26card 0: ICH5 [Intel ICH5], device 3: Intel ICH - ADC2 [Intel ICH5 - ADC2]
     27  Subdevices: 1/1
     28  Subdevice #0: subdevice #0
     29card 1: U0x46d0x809 [USB Device 0x46d:0x809], device 0: USB Audio [USB Audio]
     30  Subdevices: 1/1
     31  Subdevice #0: subdevice #0
     32}}}
     33
     34We 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'''":
     35{{{
     36ffmpeg -f alsa -i hw:1 -t 30 out.wav
     37}}}
     38That will give us a 30 seconds WAV audio output, recorded from our USB camera's default recording device (microphone).
     39
     40If 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:
     41{{{
     42ffmpeg -f alsa -i hw:0,2 -t 30 out.wav
     43}}}
     44
     45But, '''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 [http://www.reactivated.net/writing_udev_rules.html 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:
     46{{{
     47#!html
     48<pre class="wiki">
     49# arecord -L
     50null
     51    Discard all samples (playback) or generate zero samples (capture)
     52default:CARD=ICH5
     53    Intel ICH5, Intel ICH5
     54    Default Audio Device
     55sysdefault:CARD=ICH5
     56    Intel ICH5, Intel ICH5
     57    Default Audio Device
     58front:CARD=ICH5,DEV=0
     59    Intel ICH5, Intel ICH5
     60    Front speakers
     61surround40:CARD=ICH5,DEV=0
     62    Intel ICH5, Intel ICH5
     63    4.0 Surround output to Front and Rear speakers
     64surround41:CARD=ICH5,DEV=0
     65    Intel ICH5, Intel ICH5
     66    4.1 Surround output to Front, Rear and Subwoofer speakers
     67surround50:CARD=ICH5,DEV=0
     68    Intel ICH5, Intel ICH5
     69    5.0 Surround output to Front, Center and Rear speakers
     70surround51:CARD=ICH5,DEV=0
     71    Intel ICH5, Intel ICH5
     72    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
     73<b>default:CARD=U0x46d0x809</b>
     74    USB Device 0x46d:0x809, USB Audio
     75    Default Audio Device
     76sysdefault:CARD=U0x46d0x809
     77    USB Device 0x46d:0x809, USB Audio
     78    Default Audio Device
     79front:CARD=U0x46d0x809,DEV=0
     80    USB Device 0x46d:0x809, USB Audio
     81    Front speakers
     82surround40:CARD=U0x46d0x809,DEV=0
     83    USB Device 0x46d:0x809, USB Audio
     84    4.0 Surround output to Front and Rear speakers
     85surround41:CARD=U0x46d0x809,DEV=0
     86    USB Device 0x46d:0x809, USB Audio
     87    4.1 Surround output to Front, Rear and Subwoofer speakers
     88surround50:CARD=U0x46d0x809,DEV=0
     89    USB Device 0x46d:0x809, USB Audio
     90    5.0 Surround output to Front, Center and Rear speakers
     91surround51:CARD=U0x46d0x809,DEV=0
     92    USB Device 0x46d:0x809, USB Audio
     93    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
     94surround71:CARD=U0x46d0x809,DEV=0
     95    USB Device 0x46d:0x809, USB Audio
     96    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
     97iec958:CARD=U0x46d0x809,DEV=0
     98    USB Device 0x46d:0x809, USB Audio
     99    IEC958 (S/PDIF) Digital Audio Output
     100</pre>
     101}}}
     102
     103We can tell FFmpeg exactly what card we want to use, specifying the exact card's name, no matter which ordering it is, like this:
     104{{{
     105#!html
     106<pre class="wiki">
     107ffmpeg -f alsa -i <b>default:CARD=U0x46d0x809</b> -t 30 out.wav
     108</pre>
     109}}}
     110This way, you're always asking for the input from that certain device and will never mix things up.
     111
     112Also, you might find useful a tool named '''alsamixer'''.
     113
     114[[Image()]]
     115
     116It 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).
     117
     118
     119= Input options =
     120
     121.