Random Thoughts – Randocity!

Audio Tip: How to decode 5.1 DTS / AC3 to 6 WAV files

Posted in audio engineering by commorancy on April 10, 2016

[Updated 02/21/2017] Please see the updated Alternative Solutions below. These don’t require Cubase.

For those of us who are hobbiest home audio engineers, here’s a tip that might come in handy when trying to extract 5.1 (6 channel) audio from DTS/AC3 to individual WAV (or more specifically, WAV 64) files. This technique may or may not work for 7.1 (8 channel) audio. Let’s explore.

What You Will Need

First Step – TSMuxer GUI

Extract the DTS/AC3 stream from video container using TSMuxer Gui. To do this…

  1. Load the *.m2ts, *.vob, *.mkv, etc file into TSMuxer Gui using File=>Open.
  2. Once the file is loaded, uncheck all other streams except the audio stream (DTS or AC3)
  3. Choose ‘Demux’ as the Output type
  4. Choose ‘Browse’ if you want to place the output file somewhere other than where the app has chosen
  5. Click ‘Start Demuxing’
  6. When completed, you will have a *.dts or *.ac3 file as output.

This step demuxes the audio from the full movie container.

Second Step – FFMpeg

Extract the DTS 5.1 audio to single 6 channel WAV file via FFMpeg using the following:

ffmpeg -i 00000.track_4352.dts -acodec pcm_s24le output-file.w64

This will create a 6 channel w64 (wave 64) file. You’ll want to use *.w64 because of the 4GB max size of standard *.wav files. If you know your output file will be sized smaller than 4GB, you can use *.wav instead. Also, if you want to master in 32 bit or higher, you can choose the pcm output version that corresponds to the bit size you want to use. I’m using 24 bits for my remastering efforts. The larger amount of bits you use for mastering, the more likely you will need to use w64.

Third Step – Cubase

  1. File=>Import to input output-file.w64 into Cubase
  2. When the small panel appears asking how you would like to import, choose Split Channels. You can number them if you like.Cubase Import
  3. It may take a little while to split them all out.

Note, this is the part that I do not know if Audacity supports. It may be able to perform Split Channels like Cubase, but you would need to test Audacity to find out whether it can and how. Cubase can definitely split the channels, though.

Fourth Step – Exporting WAV / W64 files

  1. From here, you can continue to use Cubase or Audacity to produce a remastered audio file or …
  2. You can save each individual channel as a separate WAV file for some other use. Note, you should use *.w64 (wave 64) if the files are expected to be larger than 4GB in size.

It’s up to you what you want to do with the resulting files.

Alternative Solutions

Using ffmpeg only.

Note, you will need to install the latest version of ffmpeg to ensure compatibility with this solution.

I have since found you can accomplish the extraction to individual WAVes using ffmpeg only. You won’t need Cubase or tsmuxer for this alternative solution. You extract your WAVes by setting up channel mappings, then assigning those mappings to each output file. Though, this solution is just a tad bit more complicated in that you need to know what channels your input audio offers, which channels to extract and what the two letter abbreviation for the channel is within ffmpeg.

For extracting 5.1, use the following command (Linux line break style shown):

ffmpeg -i infile \
-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]" lfe.wav \
-map "[BL]" back_left.wav \
-map "[BR]" back_right.wav

To extract 7.1, use the following command:

ffmpeg -i infile \
-filter_complex "channelsplit=channel_layout=7.1[FL][FR][FC][LFE][BL][BR][FLC][FRC]" \
-map "[FL]" front_left.wav \
-map "[FR]" front_right.wav \
-map "[FC]" front_center.wav \
-map "[LFE]" lfe.wav \
-map "[BL]" back_left.wav \
-map "[BR]" back_right.wav \
-map "[FLC]" front_left_center.wav \
-map "[FRC]" front_right_center.wav

Where infile is your source file. The input can be a video file (i.e., vob, m2ts, mkv, etc) or a multitrack audio file (i.e., AC3, DTS, etc). If you are running Windows using a CMD command shell, you will need to type the command in without the line breaks shown above. So, copy and paste won’t directly work on Windows. You’ll need to use an editor to make the command Windows friendly.

Note that there are a lot of different possible mappings for various types of audio input files. Since there are now many formats of soundtrack audio available such as Dolby Atmos, Dolby DTS, AC3 and various others, you should first determine the format of the input audio with ffprobe (see below) to better understand how to map and extract the audio. The channels available for possible extraction in ffmpeg include the following:

Command:

ffmpeg -layouts -hide_banner

Output:

Individual channels:
NAME        DESCRIPTION
FL          front left
FR          front right
FC          front center
LFE         low frequency
BL          back left
BR          back right
FLC         front left-of-center
FRC         front right-of-center
BC          back center
SL          side left
SR          side right
TC          top center
TFL         top front left
TFC         top front center
TFR         top front right
TBL         top back left
TBC         top back center
TBR         top back right
DL          downmix left
DR          downmix right
WL          wide left
WR          wide right
SDL         surround direct left
SDR         surround direct right
LFE2        low frequency 2

Standard channel layouts:
NAME        DECOMPOSITION
mono        FC
stereo      FL+FR
2.1         FL+FR+LFE
3.0         FL+FR+FC
3.0(back)   FL+FR+BC
4.0         FL+FR+FC+BC
quad        FL+FR+BL+BR
quad(side)  FL+FR+SL+SR
3.1         FL+FR+FC+LFE
5.0         FL+FR+FC+BL+BR
5.0(side)   FL+FR+FC+SL+SR
4.1         FL+FR+FC+LFE+BC
5.1         FL+FR+FC+LFE+BL+BR
5.1(side)   FL+FR+FC+LFE+SL+SR
6.0         FL+FR+FC+BC+SL+SR
6.0(front)  FL+FR+FLC+FRC+SL+SR
hexagonal   FL+FR+FC+BL+BR+BC
6.1         FL+FR+FC+LFE+BC+SL+SR
6.1         FL+FR+FC+LFE+BL+BR+BC
6.1(front)  FL+FR+LFE+FLC+FRC+SL+SR
7.0         FL+FR+FC+BL+BR+SL+SR
7.0(front)  FL+FR+FC+FLC+FRC+SL+SR
7.1         FL+FR+FC+LFE+BL+BR+SL+SR
7.1(wide)   FL+FR+FC+LFE+BL+BR+FLC+FRC
7.1(wide-side)FL+FR+FC+LFE+FLC+FRC+SL+SR
octagonal   FL+FR+FC+BL+BR+BC+SL+SR
downmix     DL+DR

Using FFProbe

To determine the audio channels available to extract from your infile, use ffprobe as follows:

Linux / MacOS X

$ /path/to/ffprobe -i infile -hide_banner 2>&1 | egrep "^I|^ "

Windows

C:\path\to\ffprobe -i infile -hide_banner

The output will look something like

Input #0, mpegts, from 'my_movie.m2ts':
  Duration: 01:37:13.61, start: 11.650667, bitrate: 43437 kb/s
  Program 1
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
    Stream #0:1[0x1100]: Audio: dts (DTS-HD MA) ([134][0][0][0] / 0x0086), 48000 Hz, 5.1(side), fltp, 1536 kb/s
    Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)
    Stream #0:3[0x1201]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090)

The stream marked in red is the stream you will need to examine. In the output example above, this audio contains 5.1(side) audio using the DTS format. For 5.1(side) extraction, the command would look like the following:

# From the above -layouts output
# input = 24 bits and preserve output at 24 bits
# 5.1(side)   FL+FR+FC+LFE+SL+SR

ffmpeg -i infile \
-filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][SL][SR]" \
-acodec pcm_s24le \
-map "[FL]" front_left.wav \
-acodec pcm_s24le \
-map "[FR]" front_right.wav \
-acodec pcm_s24le \
-map "[FC]" front_center.wav \
-acodec pcm_s24le \
-map "[LFE]" lfe.wav \
-acodec pcm_s24le \
-map "[SL]" side_left.wav \
-acodec pcm_s24le \
-map "[SR]" side_right.wav

Audio Output Format

If you don’t specify an audio output format, ffmpeg defaults to using pcm_s16le which creates a 16 bit WAV file for each channel. If you want to preserve the bit rate of the original audio, then you’ll want to specify the output format to be the same as the input for each WAV. This means that you can, if you want, specify 16 bit for some channels and 24 bit for others. For 24 bits, specify -acodec pcm_s24le just before each -map flag (see example above). For 32 bits, specify -acodec pcm_s32le.

Also note that while you can select the individual audio track within the a movie container, you don’t really need to. Ffmpeg automatically selects the best quality audio stream available in the container. However, if there are multiple 5.1 or 7.1 audio streams containing equal quality or there are multiple separate programs, you will need to tell ffmpeg to choose which stream to decode into WAV files. Note that if you need the syntax for selecting a specific audio stream using ffmpeg, please leave a comment below and I’ll write up an example for you.

Below is a list of PCM output formats available in ffmpeg version 3.2.4:

# Find these with the command

$ ffmpeg -formats | grep PCM

 DE alaw            PCM A-law
 DE f32be           PCM 32-bit floating-point big-endian
 DE f32le           PCM 32-bit floating-point little-endian
 DE f64be           PCM 64-bit floating-point big-endian
 DE f64le           PCM 64-bit floating-point little-endian
 DE mulaw           PCM mu-law
 DE s16be           PCM signed 16-bit big-endian
 DE s16le           PCM signed 16-bit little-endian
 DE s24be           PCM signed 24-bit big-endian
 DE s24le           PCM signed 24-bit little-endian
 DE s32be           PCM signed 32-bit big-endian
 DE s32le           PCM signed 32-bit little-endian
 DE s8              PCM signed 8-bit
 DE u16be           PCM unsigned 16-bit big-endian
 DE u16le           PCM unsigned 16-bit little-endian
 DE u24be           PCM unsigned 24-bit big-endian
 DE u24le           PCM unsigned 24-bit little-endian
 DE u32be           PCM unsigned 32-bit big-endian
 DE u32le           PCM unsigned 32-bit little-endian
 DE u8              PCM unsigned 8-bit

You’ll need to prefix pcm_ to the name of the format to use it on the command line. For example, if you want to use u16be, then you would specify that as -acodec pcm_u16be.

Windows Only (eac3t0)

Tool required: eac3to

Here is the command to use to extract all of the waves with eac3to:

# N: means the stream number in the input file
# You will need to determine which stream number to use
C:\path\to\eac3to "C:\path\to\infile" N: C:\path\to\output.wavs

Example:
  C:\bin\eac3to "C:\Movies Folder\mymovie.m2ts" 1: D:\Audio\mymovie.wavs

You’ll want to choose the proper drive for each of the paths instead of C:\. Also note, the .wavs (with the ‘s’) extension is important so that all of the WAVes will be exported from this tool.

Thanks go to Eli for the eac3to solution. If you are running Windows in your audio workflow, then this tool seems to be a fast one-step alternative.

Tagged with: , , , , , , ,

4 Responses

Subscribe to comments with RSS.

  1. Eli B. said, on February 18, 2017 at 12:21 am

    This can be achieved in a single command with eac3to. It would go something like this:

    eac3to “path_to_video_file” X: blah.wavs

    where X is the stream number of the AC3 or DTS audio that you want decoded. This stream number (and other information about the contents and structure of your input) can be found by simply running “eac3to ‘path_to_video_file'” with no other arguments. Also, in the above command, note the s at the end of wavs; otherwise you’ll get one wav file with all the channels in it, instead of one wav file per channel.

    More info on this invaluable tool can be found at its official thread at doom9:
    https://forum.doom9.org/showthread.php?t=125966

    Like

    • commorancy said, on February 18, 2017 at 12:26 am

      Hi Eli,

      I don’t typically use eac3to in my workflow, but perhaps I need to look into it more. I think I remember trying it sometime back and couldn’t get a proper handle on it (like, it just didn’t do the things I needed at the time). This addition you mention may be more recent than the last time I tried it. Thanks for the alternative solution.

      After reviewing the eac3to tool again, now I know why I’m not using it. The eac3to tool is a Windows only tool. Since I’m using a Mac, my article is effectively the only workable solution. If you’re using Windows, then eac3to seems a faster alternative. Yes, I know that I show a Windows version of Cubase, but there is a Mac version also. My solution will work on both Mac and Windows.

      I have updated the article to reflect both an ffmpeg only and eac3to only solution.

      Like

      • Eli B. said, on February 19, 2017 at 10:23 pm

        Very cool update with ffmpeg and all! Great to have multiple different workflows. But note that in the command for eac3to, the last part should read something like ‘1: “C:\path\to\output.wavs”‘ where 1 is the stream number within the input file (hence why I gave it a letter as the stream number you’ll want to extract will vary).

        Like

        • commorancy said, on February 19, 2017 at 10:34 pm

          Hi Eli,

          I’ve updated the article to reflect the stream number in the example. Thanks for your update.

          Like


Comments are encouraged under these rules: 1. No personal attacks allowed. 2. Comments with personal attacks will not be posted. 3. Please keep your words civil. Thank you for contributing!

This site uses Akismet to reduce spam. Learn how your comment data is processed.