Changes between Version 11 and Version 12 of Capture/ALSA


Ignore:
Timestamp:
Nov 26, 2023, 2:46:32 AM (2 years ago)
Author:
20kbirds
Comment:

Add amerge example for multi-channel capture from multiple interfaces

Legend:

Unmodified
Added
Removed
Modified
  • Capture/ALSA

    v11 v12  
    222222ffmpeg -f alsa -channels 2 -sample_rate 44100 -i loopout out.wav
    223223}}}
     224
     225== Record multi-channel audio from multiple interfaces ==
     226
     227Suppose you want to record 4 microphones and you have two USB interfaces with two inputs each. You can use [https://ffmpeg.org/ffmpeg-filters.html#amerge amerge] filter to combine the streams from each interface into a single 4-channel WAV file:
     228
     229{{{
     230ffmpeg -f alsa -i hw:1 -f alsa -i hw:2 -filter_complex '[0:a][1:a]amerge=inputs=2' out.wav
     231}}}
     232
     233Maybe your interfaces output audio data in different formats, for example one only provides S24_3LE and the other only S16_LE. Use audio codec arguments to upconvert to the highest quality format:
     234
     235{{{
     236ffmpeg -c:a pcm_s24le -f alsa -i hw:1 -f alsa -i hw:2 -filter_complex '[0:a][1:a]amerge=inputs=2' -c:a pcm_s24le out.wav
     237}}}
     238
     239In this case, my `hw:1` device uses `S24_3LE` format which has to be specified explicitly via `-c:a` prior to the input device argument (`-i`), my `hw:2` device uses `S16_LE` format which I don't specify because ffmpeg figures it out on its own, and I want the result to be output in 24 bits instead of 16 bits which appears to be the default.
     240
     241Output:
     242
     243{{{
     244[aist#0:0/pcm_s24le @ 0x55936db2e7c0] Guessed Channel Layout: stereo
     245Input #0, alsa, from 'hw:1':
     246  Duration: N/A, start: 1700966473.753018, bitrate: 2304 kb/s
     247  Stream #0:0: Audio: pcm_s24le, 48000 Hz, 2 channels, s32 (24 bit), 2304 kb/s
     248[aist#1:0/pcm_s16le @ 0x55936db318c0] Guessed Channel Layout: stereo
     249Input #1, alsa, from 'hw:2':
     250  Duration: N/A, start: 1700966473.755953, bitrate: 1536 kb/s
     251  Stream #1:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
     252Stream mapping:
     253  Stream #0:0 (pcm_s24le) -> amerge
     254  Stream #1:0 (pcm_s16le) -> amerge
     255  amerge:default -> Stream #0:0 (pcm_s24le)
     256Press [q] to stop, [?] for help
     257[Parsed_amerge_0 @ 0x55936db39540] No channel layout for input 1
     258[Parsed_amerge_0 @ 0x55936db39540] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
     259Output #0, wav, to 'out.wav':
     260  Metadata:
     261    ISFT            : Lavf60.16.100
     262  Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, 4.0, s32, 4608 kb/s
     263    Metadata:
     264      encoder         : Lavc60.31.102 pcm_s24le
     265}}}