Changes between Version 4 and Version 5 of Capture/ALSA
- Timestamp:
- Jun 5, 2014, 7:14:30 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Capture/ALSA
v4 v5 3 3 = Syntax = 4 4 5 Capturing audio with FFmpeg and ALSA is pretty much straightforward. Usual way to do this is like this:5 Capturing audio with `ffmpeg` and ALSA is pretty much straightforward: 6 6 {{{ 7 7 ffmpeg -f alsa <input_options> -i <input_device> ... output.wav 8 8 }}} 9 9 10 See the [https://ffmpeg.org/ffmpeg-devices.html#alsa FFmpeg ALSA input device documentation] for more info. 11 10 12 = Selecting the input card = 11 13 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). 13 15 14 So, first, list your recording cards/devices:16 To list recording cards or devices: 15 17 {{{ 16 #arecord -l18 $ arecord -l 17 19 18 20 **** List of CAPTURE Hardware Devices **** … … 34 36 }}} 35 37 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'''":38 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`: 37 39 {{{ 38 40 ffmpeg -f alsa -i hw:1 -t 30 out.wav 39 41 }}} 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:42 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 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: 41 43 {{{ 42 44 ffmpeg -f alsa -i hw:0,2 -t 30 out.wav 43 45 }}} 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'scommand line.46 The 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. 45 47 46 48 == Surviving the reboot == 47 49 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:50 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: 49 51 {{{ 50 52 #!html … … 104 106 }}} 105 107 106 We can tell FFmpegexactly what card we want to use, specifying the exact card's name, no matter which ordering it is, like this:108 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: 107 109 {{{ 108 110 #!html … … 115 117 == ALSA mixer tool == 116 118 117 You might find useful a tool named '''alsamixer'''.119 You might find useful a tool named `alsamixer`. 118 120 119 121 [[Image(alsamixer.png)]] 120 122 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 cardand 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).123 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, 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). 122 124 123 125 = Input options = 124 126 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).127 The only useful [https://ffmpeg.org/ffmpeg.html#Audio-Options audio input options] for ALSA input are `-ar` (audio sample rate) and `-ac` (audio channels). 126 128 127 129 Specifying audio sampling rate/frequency will force the audio card to record the audio at that specified rate. Usually the default value is "44100" (Hz). … … 132 134 == Grab an audio from your microphone == 133 135 134 When doing screencast recordings, you usually want to record your voice too , so you would probably want to do something like this:136 When doing screencast recordings, you usually want to record your voice too: 135 137 {{{ 136 138 ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0 -t 30 out.wav
