SoXを使用して2つ以上のチャンネルを持つオーディオデバイスを録音するには?

SoXを使用して2つ以上のチャンネルを持つオーディオデバイスを録音するには?

私はそれぞれ10、18、32の入力チャンネルを備えた複数のUSBオーディオインターフェースを持っています。主にバンドの各楽器を別々のトラックに録音するために使用されます。

私は生のWAVフォーマット(s32le @ 48kHz)で録音します。だから実際に録画したいチャンネルだけを録画すればいいのです。 SoXでは、フラグを使用して必要なチャンネル数を指定し、-cEffectsremixを使用して録音するチャンネルを選択することでこれを達成できることがわかりました。

この小さな概念の証明は、それが実際に動作することを示しています。

$ export SOURCE_NAME="alsa_input.usb-Behringer_FLOW_8_03-FF-02-11-55-44-00.Direct__hw_F8__source"

# Record only 1 channel(s) (-c 1) - The channel(s) to record: 2
$ sox -t pulseaudio "${SOURCE_NAME}" -r 48000 -c 1 -b 16 -e signed-integer output.w64 remix 2

ただし、拡張は機能しません。

# Record only 4 channel(s) (-c 4) - The channel(s) to record: 1 2 6 8
$ sox -t pulseaudio "${SOURCE_NAME}" -r 48000 -c 4 -b 32 -e signed-integer output.w64 remix 1 2 6 8

何らかの理由で、SoXは最初の2つのチャンネルのみを認識します。

Input File     : 'alsa_input.usb-Behringer_FLOW_8_03-FF-02-11-55-44-00.Direct__hw_F8__source' (pulseaudio)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

sox FAIL remix: too few input channels

2つ以上のチャンネルを録音してもFFmpegは失敗します。

$ ffmpeg -f pulse -i "${SOURCE_NAME}" -c:a pcm_s32le -ar 48000 -ac 10 -channel_layout 0x3ff output.w64

FFmpegで次のエラーが発生します。

Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, pulse, from 'alsa_input.usb-Behringer_FLOW_8_03-FF-02-11-55-44-00.Direct__hw_F8__source':
  Duration: N/A, start: 1689504465.730127, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Multiple -ac options specified for stream 0, only the last option '-ac 10' will be used.
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s32le (native))
Press [q] to stop, [?] for help
[pcm_s32le @ 0x55bc4d7d6040] Channel layout '10 channels (FL+FR+FC+LFE+BL+BR+FLC+FRC+BC+SL)' with 10 channels does not match number of specified channels 2
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

二重チェックffmpeg probe:

$ ffprobe -f pulse -i "${SOURCE_NAME}"
Input #0, pulse, from 'alsa_input.usb-Behringer_FLOW_8_03-FF-02-11-55-44-00.Direct__hw_F8__source':
  Duration: N/A, start: 1689504633.181940, bitrate: 1536 kb/s
  Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s

それで、次に考えたのは、PulseAudio自体にバグがあるということでした。ただし、pactl次のユーティリティを使用すると、エラーを簡単に確認できます。

$ pactl list sources
Source #1414
    ...
    Name: alsa_input.usb-Behringer_FLOW_8_03-FF-02-11-55-44-00.Direct__hw_F8__source
    ...
    Sample Specification: s32le 10ch 48000Hz
    Channel Map: aux0,aux1,aux2,aux3,aux4,aux5,aux6,aux7,aux8,aux9
    ...
    Volume: aux0: 48287 /  74% / -7.96 dB,   aux1: 48287 /  74% / -7.96 dB,   aux2: 48287 /  74% / -7.96 dB,   aux3: 48287 /  74% / -7.96 dB,   aux4: 48287 /  74% / -7.96 dB,   aux5: 48287 /  74% / -7.96 dB,   aux6: 48287 /  74% / -7.96 dB,   aux7: 48287 /  74% / -7.96 dB,   aux8: 48287 /  74% / -7.96 dB,   aux9: 48287 /  74% / -7.96 dB
            balance 0.00
    ...
    Properties:
        ...
        audio.channels = "10"
        ...

これは、PulseAudioがこのUSBオーディオインターフェースの10個の入力チャンネルをすべて知っていることを明らかに示しています。

それでPulseAudioのツールを試してみましたparecord

$ parecord --device=${SOURCE_NAME} --format=s32le --rate=48000 --channels 10 --file-format=w64 output.w64
Warning: failed to write channel map to file.

この警告は発生しましたが(それが何を意味していても)、実際には10チャンネルすべてが正常に録音されました。

次のように特定のチャンネルを選択することもできます。

parecord --device=${SOURCE_NAME} --format=s32le --rate=48000 --channels 4 --channel-map=aux0,aux1,aux5,aux7 --file-format=w64 output.w64

それでは、これがSoXやFFmpegでは機能しないのはなぜですか?

また、SoXにALSAを代わりに使用するように指示しましたが、まったく機能しません。

$ sox -t alsa "plughw:CARD=F8,DEV=0" -r 48000 -c 4 -b 32 -e signed-integer output.w64 remix 1 2 6 8
sox FAIL formats: can't open input  `plughw:CARD=F8,DEV=0': snd_pcm_open error: Device or resource busy

PipeWireとPulseAudioが動作しているときは、ALSAを介したアクセスが機能しないようです。

ALSAユーティリティで録画できることを確認しましたが、arecord同じ「デバイスを使用中」エラーが発生しました。

$ arecord -D plughw:CARD=F8,DEV=0 -r 48000 -c 10 -f S32_LE -t wav output.wav
arecord: main:867: audio open error: Device or resource busy

ちなみに、pw-recordPipeWireユーティリティを使って直接録音するのはうまくいきます。

$ pw-record --target ${SOURCE_NAME} --format s32 --rate 48000 --channels 10

録画したいチャンネルを選択することもできます。

$ pw-record --target ${SOURCE_NAME} --format s32 --rate 48000 --channels 4 --channel-map=aux0,aux1,aux5,aux7 output.w64

SoXを見て、PipeWireを直接サポートしているかどうかを見ましたが、残念ながらそうではありません。しかし、PulseAudioは実際にすべてのチャンネルを見ることができるので、ここでSoXとFFmpegが失敗する理由を理解できません。

どんなアイデアがありますか?

ベストアンサー1

おすすめ記事