Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg extract all audio channels

Tags:

ffmpeg

audio

Is there a way in ffmpeg to extract all audio channels giving each a separate name?

The problem is that I don't know in advance how many channels the input file is going to have.

This does splitting into two wav files:

ffmpeg -y -i input.wav -filter_complex
"[0:a]channelsplit=channel_layout=stereo[left][right]" -map "[left]"
left.wav -map "[right]" right.wav

What can be done if the input file contains 3, or 8 channels? Ideally, I would like to have a way to convert Nchannels.mp4 into Nchannels_1.wav, Nchannels_2.wav, ..., Nchannels_N.wav.

like image 731
Alexander F Avatar asked Oct 28 '25 16:10

Alexander F


1 Answers

You will have to do this in multiple steps.

  1. Get number of channels with ffprobe:
    ffprobe -v error -show_entries stream=channels,channel_layout -of default=nw=1 input.wav
        channels=6
        channel_layout=5.1
    
  2. (Optional) Refer to ffmpeg -layouts to get channel names so you know what to name the outputs; as in the example below.
  3. Build ffmpeg command using results from ffprobe:
    ffmpeg -i input.wav -filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR]" -map "[FL]" front_left.wav -map "[FR]" front_right.wav -map "[FC]" front_center.wav -map "[LFE]" low_frequency_effects.wav -map "[BL]" back_left.wav -map "[BR]" back_right.wav
    
like image 141
llogan Avatar answered Oct 31 '25 11:10

llogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!