A way to obtain this result is by using ffprobe and ffmpeg.

ffmepg is an open-source top notch command line toolbox aimed at streamlining common operations on audio-visual files. Mainly converting from one codec or format to another, adjusting framerates and performing audio extraction.

ffprobe is a library contained inside ffmpeg, directly accessible from the command line :

$ ffprobe -h

If you don’t already have ffmpeg installed, we suggest you do it through a packet manager like Homebrew.

Install Homebrew

Open the Terminal and copy paste the following code :

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install ffmpeg

One Homebrew is installed, use it to install ffmpeg :

$ brew install ffmpeg

Use ffprobe

See what audio streams are available in a given file :

$ ffprobe my_input_file.m4v

Look for this part of the output :

Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 718x552 [SAR 64:45 DAR 5744:3105], 1023 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2013-01-26 10:39:52
encoder : JVT/AVC Coding
Stream #0:1(fra): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
Metadata:
creation_time : 2013-01-26 10:39:52
Side data:
audio service type: main
Stream #0:2(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Metadata:
creation_time : 2013-01-26 10:39:52
Side data:
audio service type: main

It tells us that this container file includes two audio streams, identified as #0:1 and #0:2, both are ac3 bitstreams and are 5.1 soundtracks.

Use ffmpeg

Extract the ac3 bitstream of the ‘en’ soundtrack (#0:2) to a file :

$ ffmpeg -i my_input_file.m4v -map 0:2 -c:a copy output_file.ac3

The -map option is here to specify which stream of the input file we want to get in our output file.

Or get a PCM wav 6 channels file of this soundtrack :

$ ffmpeg -i my_input_file.m4v -map 0:2 output_file.wav

This will generate a 6 channels 16 bit PCM wav file. But depending on the length of the original movie, that might lead you to a wav file that exceeds the 2 GB size limit for wav file … (Notice that some systems and players will support up to 4 GB).

In this case, an alternative might be to output the soundtrack as 6 mono PCM wav files. First extract the soundtrack as ac3 file, as shown previously, then split its channels through mapping :

$ ffmpeg -i my_input_file.ac3 -map_channel 0.0.0 l.wav -map_channel 0.0.1 r.wav -map_channel 0.0.2 c.wav -map_channel 0.0.3 ls.wav -map_channel 0.0.4 rs.wav -map_channel 0.0.5 lfe.wav

(Note that channel mapping, ie which is front, rear left and so on might depend on the original bitstream channel mapping).

We have unfortunately not found a way to do this directly from the ac3 stream of an audio+video container.

More

ffmpeg documentation : https://ffmpeg.org/documentation.html

ffprobe documentation : https://ffmpeg.org/ffprobe.html

Source

Stack Exchange / Sound Design (beta) : “How to extract 5.1 audio from mkv/avi/mp4?