Changes between Version 4 and Version 5 of Capture/ALSA


Ignore:
Timestamp:
Jun 5, 2014, 10:14:30 PM (5 years ago)
Author:
llogan
Comment:

minor formatting

Legend:

Unmodified
Added
Removed
Modified
  • Capture/ALSA

    v4 v5  
    33= Syntax =
    44
    5 Capturing audio with FFmpeg and ALSA is pretty much straightforward. Usual way to do this is like this:
     5Capturing audio with `ffmpeg` and ALSA is pretty much straightforward:
    66{{{
    77ffmpeg -f alsa <input_options> -i <input_device> ... output.wav
    88}}}
    99
     10See the [https://ffmpeg.org/ffmpeg-devices.html#alsa FFmpeg ALSA input device documentation] for more info.
     11
    1012= Selecting the input card =
    1113
    12 '''input_device''' tells FFmpeg which audio capturing card`/`device you would like to use. To get the list of all installed cards on your machine, you can type '''arecord -l''' (small L) or '''arecord -L''' (longer output).
     14`input_device` tells `ffmpeg` which audio capturing card or device you would like to use. To get the list of all installed cards on your machine, you can type `arecord -l` or `arecord -L` (longer output).
    1315
    14 So, first, list your recording cards/devices:
     16To list recording cards or devices:
    1517{{{
    16 # arecord -l
     18$ arecord -l
    1719
    1820**** List of CAPTURE Hardware Devices ****
     
    3436}}}
    3537
    36 We can see there are 2 audio cards installed 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'''":
     38We can see there are 2 audio cards installed 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`:
    3739{{{
    3840ffmpeg -f alsa -i hw:1 -t 30 out.wav
    3941}}}
    40 That will give us a 30 seconds WAV audio output, recorded from our USB camera's '''default recording device''' (microphone). The default recording device can be selected using "alsamixer" tool (see below) or specifying the device using an additional parameter Y in '''hw:<X>,<Y>''', where <X>=card, <Y>=device. For example, to select "MIC2 ADC" from Intel card (look above at the list), we would use:
     42That will give us a 30 seconds WAV audio output, recorded from our USB camera's '''default recording device''' (microphone). The default recording device can be selected using the `alsamixer` tool (see below) or specifying the device using an additional parameter Y in `hw:<X>,<Y>`, where <X>=card, <Y>=device. For example, to select "MIC2 ADC" from Intel card (look above at the list), we would use:
    4143{{{
    4244ffmpeg -f alsa -i hw:0,2 -t 30 out.wav
    4345}}}
    44 The best way is to select your card and default recording device with "alsamixer" tool, because some audio cards have a complicated way of selecting the default input through the FFmpeg's command line.
     46The best way is to select your card and default recording device with the `alsamixer` tool, because some audio cards have a complicated way of selecting the default input through the `ffmpeg` command line.
    4547
    4648== Surviving the reboot ==
    4749
    48 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:
     50If 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:
    4951{{{
    5052#!html
     
    104106}}}
    105107
    106 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:
     108We can tell `ffmpeg` exactly what card we want to use, specifying the exact card's name, no matter which ordering it is, like this:
    107109{{{
    108110#!html
     
    115117== ALSA mixer tool ==
    116118
    117 You might find useful a tool named '''alsamixer'''.
     119You might find useful a tool named `alsamixer`.
    118120
    119121[[Image(alsamixer.png)]]
    120122
    121 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).
     123It 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, etc), 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).
    122124
    123125= Input options =
    124126
    125 The only useful [http://ffmpeg.org/ffmpeg.html#Audio-Options audio input options] for ALSA input are "-ar" (audio sample rate) and "-ac" (audio channels).
     127The only useful [https://ffmpeg.org/ffmpeg.html#Audio-Options audio input options] for ALSA input are `-ar` (audio sample rate) and `-ac` (audio channels).
    126128
    127129Specifying audio sampling rate/frequency will force the audio card to record the audio at that specified rate. Usually the default value is "44100" (Hz).
     
    132134== Grab an audio from your microphone ==
    133135
    134 When doing screencast recordings, you usually want to record your voice too, so you would probably want to do something like this:
     136When doing screencast recordings, you usually want to record your voice too:
    135137{{{
    136138ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0 -t 30 out.wav