1 2 3 4 # audio recording from usb microphone 5 6 with linux ubuntu 16, ffmpeg, arecord, 7 8 alsamixer, lsusb, audacity 9 10 11 12 ref: 13 14 https://trac.ffmpeg.org/wiki/Capture/ALSA 15 16 http://tuxradar.com/content/how-it-works-linux-audio-explained 17 18 http://trac.edgewall.org/ 19 20 21 ## ALSA, OSS 22 23 On Linux, recording with a USB microphone is best done under ALSA 24 (Advanced Linux Sound Architecture). Current Audacity provides native 25 ALSA support. 1.2.x versions of Audacity only support the older OSS 26 (Open Sound System), but can work with ALSA using an OSS emulation 27 layer. 28 29 30 ## capturing from ALSA 31 32 Capturing audio with ffmpeg and ALSA is pretty much straightforward: 33 34 ffmpeg -f alsa <input_options> -i <input_device> ... output.wav 35 36 -f fmt (input/output) 37 38 Force input or output file format. The format is normally auto 39 detected for input files and guessed from the file extension 40 for output files, so this option is not needed in most cases. 41 42 -i url (input), input file url 43 44 45 ## Selecting the input card 46 47 input_device tells ffmpeg which audio capturing card or device you 48 would like to use. To get the list of all installed cards on your 49 machine, you can type arecord -l or arecord -L (longer output). 50 51 To list recording cards or devices: 52 53 $ arecord -l 54 55 **** List of CAPTURE Hardware Devices **** 56 card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5] 57 Subdevices: 1/1 58 Subdevice #0: subdevice #0 59 card 0: ICH5 [Intel ICH5], device 1: Intel ICH - MIC ADC [Intel 60 ICH5 - MIC ADC] 61 Subdevices: 1/1 62 Subdevice #0: subdevice #0 63 64 We can see there are 2 audio cards installed that 65 provide capturing capabilities, namely "card 0" 66 (Intel ICH5) and "card 1" (Microphone on the USB 67 web cam). The easiest thing to do is to reference 68 each of them directly using 69 70 -f alsa -i hw:0 71 72 #@or 73 74 -f alsa -i hw:1: 75 76 77 ffmpeg -f alsa -i hw:1 -t 30 out.wav 78 79 That will give us a 30 seconds WAV audio output, 80 recorded from our USB camera's default recording 81 device (microphone). The default recording device 82 can be selected using the alsamixer tool (see 83 below) or specifying the device using an 84 additional parameter Y in hw:<X>,<Y>, where 85 <X>=card, <Y>=device. For example, to select "MIC2 86 ADC" from Intel card (look above at the list), we 87 would use: 88 89 ffmpeg -f alsa -i hw:0,2 -t 30 out.wav 90 91 The best way is to select your card and default 92 recording device with the alsamixer tool, because 93 some audio cards have a complicated way of 94 selecting the default input through the ffmpeg 95 command line. 96 97 98 ## Input options 99 100 The only useful audio input options for ALSA input are -ar (audio sample rate) 101 and -ac (audio channels). 102 103 Specifying audio sampling rate/frequency will force the audio card to record 104 the audio at that specified rate. Usually the default value is "44100" (Hz). 105 Specifying audio channels will force the audio card to record the audio as 106 mono, stereo or even 2.1/5.1 (if supported by your audio card). Usually the 107 default value is "1" (mono) for Mic input and "2" (stereo) for Line-In input. 108 109 110 Another option for ffmpeg: 111 112 -thread_queue_size 512 113 114 115 ## Example 116 117 Record audio from the microphone 118 119 120 ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0 -t 30 out.wav 121 122 ffmpeg -thread_queuq_size 512 \ 123 -f alsa \ 124 -ac 1 \ 125 -ar 44100 \ 126 -i hw:0 \ 127 -t 30 \ 128 youFileName.wav 129 130 131 132 133 ## end of part 1 134 135 <!-- vim: set tw=70 ft=markdown nowrap fdm=marker ignorecase: -->
Tuesday, January 10, 2017
audio recording from usb microphone with linux ubuntu 16, ffmpeg, arecord,
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment