0

I need to extract channels from 5.1 audios. These audio tracks are contained in a MKV file. Structure of "movie.mkv" file is like this:

Input #0, matroska,webm, from 'movie.mkv':
  Duration: 00:40:38.08, start: 0.000000, bitrate: 21128 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x800 [SAR 1:1 DAR 12:5], 24 fps, 24 tbr, 1k tbn, 48 tbc
    Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2(ger): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s
    Stream #0:3(eng): Subtitle: subrip

But the syntax is very messy, so I did not figure out how to extract channels properly.

This code, for the first audio track, works fine:

ffmpeg -i "movie.mkv" -map_channel 0.1.0 "eng channel 1.wav"
ffmpeg -i "movie.mkv" -map_channel 0.1.1 "eng channel 2.wav"
ffmpeg -i "movie.mkv" -map_channel 0.1.2 "eng channel 3.wav"
ffmpeg -i "movie.mkv" -map_channel 0.1.3 "eng channel 4.wav"
ffmpeg -i "movie.mkv" -map_channel 0.1.4 "eng channel 5.wav"
ffmpeg -i "movie.mkv" -map_channel 0.1.5 "eng channel 6.wav"

I believe that 0.1.0 is: input #0 (movie.mkv); then stream 1 (audio eng); then channel 0 (very first channel).

But when I'm trying to extract channels from second audio track...

ffmpeg -i "movie.mkv" -map_channel 0.2.0 "ger channel 1.wav"
ffmpeg -i "movie.mkv" -map_channel 0.2.1 "ger channel 2.wav"
ffmpeg -i "movie.mkv" -map_channel 0.2.2 "ger channel 3.wav"
ffmpeg -i "movie.mkv" -map_channel 0.2.3 "ger channel 4.wav"
ffmpeg -i "movie.mkv" -map_channel 0.2.4 "ger channel 5.wav"
ffmpeg -i "movie.mkv" -map_channel 0.2.5 "ger channel 6.wav"

...it extracts not German sound, but instead it results with the same eng channels (which also sound little louder than in previous case). In this code, 0.2.0 appears to be: input #0 (movie.mkv); then stream 2 (audio ger); then channel 0 (very first channel).

So what am I doing wrong? :-)

Redbraid
  • 63
  • 1
  • 2
  • 8
  • 1
    I provided an answer that give an alternative solution. If you still want to use `-map_channel` then show the complete log from `ffmpeg -i "movie.mkv" -map_channel 0.2.0 "ger channel 1.wav"` – llogan Aug 02 '20 at 20:13
  • No, it's not necessary, channelsplit is just fine :-) – Redbraid Aug 03 '20 at 11:38

1 Answers1

1

Use the channelsplit filter

diagram of splitting 5.1 channel layout to individual mono components

The channelsplit filter is easier:

ffmpeg -i input.mkv -filter_complex "[0:a:0]channelsplit=channel_layout=5.1(side)[FL][FR][FC][LFE][SL][SR]" -map "[FL]" front_left.wav -map "[FR]" front_right.wav -map "[FC]" front_center.wav -map "[LFE]" lfe.wav -map "[SL]" side_left.wav -map "[SR]" side_right.wav
  • The above example will get audio from the first audio stream (Stream #0:1(eng)). If you want Stream #0:2(ger) then change [0:a:0] to [0:a:1]. See this answer for more details on the [0:a:0] syntax.

  • See FFmpeg Wiki: Audio Channels for more examples.

  • See ffmpeg -layouts for a list of channel layouts and channel names which is helpful when using channelsplit.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • I assumed somebody would suggest using filter_complex and channelsplit. I think that using channelsplit really makes the command more readable. Thank you so much for explaining! – Redbraid Aug 03 '20 at 11:34