# Eac3to/In Depth Technical Explanation
## File Formats

Below is an introduction to file formats eac3to is able to handle either as an input or an output.

### Audio Codecs

* PCM: Also known as Linear PCM (LPCM). It's the standard format for uncompressed audio data. PCM can have up to 7.1 ch, bitdepth up to 32 bit (common values are 16, 24 bit) and samplerate up to 192 kHz (common values are 44,1 and 48 kHz). It is found on Blu-ray Disc (and DVD-Audio) only, due to the huge filesize requirements. These files have no header, containing only RAW data in big endian byte order for Blu-ray Disc compliance. For detail information see the LPCM article at Wikipedia.
* RAW: When used in eac3to is exactly the same as PCM format except that the byte order is swapped, using little endian instead of big endian. This is arguably more useful for manipulation of the contents (as .raw or .wav files are generally assumed by common programs to use little endian, rather than big endian, byte order) but it generally doesn't matter as long as you don't accidentally instruct a program to read little endian as big endian or vice versa. If muxing for Blu-ray Disc, use PCM instead.
* AC3: The algorithm behind the well known Dolby Digital format. It's a lossy compression algorithm, supports up to 6.1 ch (5.1 discrete + 1 matrix) and is widely used on DVD (bitrate up to 448 kbps) and Blu-ray Disc (bitrate up to 640kbps). It is also one of the most preferred formats for movie backup on pc, as it offers very good compression / quality ratio and can be easily transmitted though S/PDIF connections. For detail information see the Dolby Digital article at Wikipedia.
* E-AC3: Also known as Dolby Digital Plus. It's found on HD DVD (bitrate up to 3.0 mbps, up to 7.1 ch), as well as on Blu-ray Disc (there are no BD titles featuring E-AC3 though). Additional info are available in the Dolby Digital Plus article at Wikipedia.
* MLP: Meridian Lossless Packing, also known as Packed PCM (PPCM), is a lossless compression technique developed by Meridian. MLP is the standard lossless compression method for DVD-Audio content (5.1 ch, 24 bit, 96 kHz or 2.0 ch, 24 bit, 192 kHz). For details see the MLP article at Wikipedia.
* TrueHD: Is a lossless compression audio format from Dolby, used on Blu-ray Disc and HD DVD. TrueHD is based on Meridian's MLP, but details differ substantially: up to 7.1 ch, 24 bit, 96 kHz are supported here. Additional information can be found in the Dolby TrueHD article at Wikipedia.
* DTS: Digital Theater System is a lossy compression format, initially introduced on DVD-Video (up to 1536 kbps, 5.1 channels, 24 bit, 48 kHz). In addition to the standard DTS, there are the following variants: DTS-ES (6.1 ch) also used in DVD-Video and DTS 96/24 (up to 5.1 ch, 24 bit, 96 kHz) found on DVD-Video & DVD-Audio. Any of these forms can be found on Blu-ray Disc and HD DVD also. For details see the Digital Theater System article in Wikipedia.
* DTS-HD High Resolution: Is an extension to the original DTS format used on Blu-ray Disc and HD DVD. It delivers up to 7.1 ch, 24 bit, 96 kHz at bitrates up to 6.0 mbps and 3.0 mbps on BD and HD DVD respectively, through lossy compression. For details see the Digital Theater System article in Wikipedia.
* DTS-HD Master Audio: Is an extension to the original DTS format, but uses lossless compression opposed to the previous one. Supports up to 7.1 ch, 24 bit, 96 kHz or up to 5.1 ch, 24 bit, 192 kHz. It's found on Blu-ray Disc and HD DVD. For details see the Digital Theater System article in Wikipedia.
* FLAC (Free Lossless Audio Codec): Supports up to 7.1 channels, 24 bit, 192 kHz and, as stated in the name, uses lossless compression. Addition info can be found in the FLAC home page.
* MP3 (MPEG-2 Audio Layer III): Extremely popular and quite flexible lossy codec, but not necessarily the most efficient.
* AAC (Advanced Audio Coding): Another popular lossy codec. Generally more efficient than MP3, since it was designed specifically to replace it.

### Video Codecs

* MPEG-2:
* VC-1:
* H.264:

### Containers

* VOB: Video OBject. Supports MPEG-2 video and PCM, AC3, DTS audio. Used on DVD-Video.
* AOB: Audio OBject. Supports MPEG-2 video and PCM, AC3, DTS, MLP audio. Used on DVD-Audio.
* M2TS: Supports MPEG-2, VC-1, H.264 video and PCM, AC3, E-AC3, TrueHD, DTS, DTS-HD Hi Res, DTS-HD MA audio. Used on Blu-ray Disc.
* EVO: Also known as EVOB (Enhanced Video OBject). Supports MPEG-2, VC-1, H.264 video and AC3, E-AC3, TrueHD, DTS, DTS-HD Hi Res, DTS-HD MA audio. Used on HD DVD.
* MKV: Also known as Matroska Video. Supports MPEG-2, VC-1, H.264 video and PCM, AC3, E-AC3, DTS, DTS-HD Hi Res (new feature!), DTS-HD MA (new feature!), TrueHD, FLAC, MP3, AAC, VORBIS audio. Used on PCs and other devices.
* MKA: Also known as Matroska Audio. Supports PCM, AC3, E-AC3, DTS, DTS-HD Hi Res (new feature!), DTS-HD MA (new feature!) FLAC, MP3, AAC, VORBIS audio. Used on PCs and other devices.
* MP4: ???

## Decoding compressed audio
### Background information

There are four common problems with "properly" decoding compressed audio tracks. The first two problems have to do with that the purpose of a media player is different than the purpose of people who want to reencode audio tracks. A media player may want to adjust volume levels to specific parameters and circumstances. Reencoders absolutely want to avoid any processing on the precious audio data. This is a conflict which can not always be solved. The four known problems are:
* Some decoders apply DRC (Dynamic Range Compression). Stupidly, Dolby's license requests that DRC must be applied, unless your decoder has an option to turn it on/off. Only then the decoder is allowed to not apply DRC. The purpose of DRC is to limit the dynamic range of an audio track, mainly to not annoy neighbours or to accommodate to noisy living room conditions. For reencoding purposes DRC is catastrophic.
* Most decoders apply Dialog Normalization. This feature is supposed to make sure that for all audio sources the dialog is automatically played at the same volume. Dialog Normalization is quite "unnice", although it's just a volume change, so it doesn't really destroy the audio quality.
* Some decoders forcefully downconvert to 16bit, or raise volume for unknown reasons or do other stupid stuff.
* Some decoders don't make use of the full available information, but just extract and decode the "core" of the compressed audio data, which obviously results in less than optimal audio quality.

### Evaluation of available decoders

* The Sonic (E-)AC3 decoder forcefully applies DRC. As a result, it's not recommended to use the Sonic (E-)AC3 decoder.
* The Sonic TrueHD decoder suffers from (2) and (3). The current version is totally unusable. eac3to doesn't allow being used at all.
* The Sonic DTS decoder seems to be more or less perfect for DTS, DTS-ES, DTS-96/24, DTS-HD Master Audio and DTS-HD High Resolution tracks. Dialog normalization is ignored by the Sonic DTS decoder. The only "problem" of the Sonic DTS decoder is that it decodes DTS-HD 7.1 tracks only as 5.1. DTS-ES and DTS-HD Master Audio 6.1 tracks are fully decoded as 6.1, though.
* The Nero (E-)AC3 decoder normally suffers from (1) and (2) and the Nero TrueHD decoder normally suffers from (2). The Nero (E-)AC3 works fine for most audio tracks, but sometimes DRC is still enabled, so it's not really recommended.
* The Nero DTS decoder suffers from (2) and (4). eac3to can work around (2), but because of (4) the Nero DTS decoder is not recommended for anything except conventional DTS tracks.
* The Cyberlink decoders always only output 16bit and can't be used outside of PowerDVD. So they currently do not make a lot of sense for eac3to.
* The libav/ffmpeg (E-)AC3 decoder works really well, but don't support 7.1 decoding yet.
* The libav/ffmpeg DTS decoder works well, too, but currently ignores the additional DTS-HD information, so especially DTS-HD Master Audio can't be decoded in full quality.
* The libav/ffmpeg TrueHD decoder works perfectly fine, including full 7.1 decoding.
* The ArcSoft DTS decoder seems to be perfect for DTS and DTS-HD decoding. It supports every format and channel configuration that exists including 6.1 and 7.1.
* The ArcSoft TrueHD and ArcSoft (E-)AC3 decoders are currently not supported by eac3to.

### Default decoders used by eac3to

* AAC: Nero
* MP1, MP2, MP3: libav/ffmpeg
* (E-)AC3: libav/ffmpeg
* TrueHD: libav/ffmpeg
* DTS(-HD): ArcSoft

### Known problems

* (E-)AC3 decoding is currently limited to 5.1. A new version of the libav/ffmpeg decoder with 7.1 channel support will be available soon.

## Special audio tracks
### DTS-HD tracks

As described in the audio codecs section, DTS-HD Hi Res & DTS-HD Master Audio tracks are extensions to the original DTS codec. As a result every DTS-HD track contains a conventional 1536 kbps 5.1 ch, 24 bit, 48 kHz DTS core coded inside. eac3to can extract this core without reencoding the source track.

### Blu-ray TrueHD / AC3 tracks

TrueHD tracks that come from a Blu-ray (only) disc can have an AC3 track coded in them. eac3to can extract the AC3 stream from such tracks and can also convert them to plain TrueHD tracks.

### E-AC3 7.1 tracks

"Normal" E-AC3 tracks have one E-AC3 frame per audio frame. 7.1 E-AC3 tracks have two E-AC3 frames per audio frame. The first E-AC3 frame is a conventional 5.1 E-AC3 core. The 2nd E-AC3 frame is an E-AC3 frame with 4 channels in it. Two of those channels replace the surround channels of the 5.1 core. The other two channels are the back surround channels. The surround channels of the 5.1 core are totally dropped when a decoder decodes the 7.1 extension. The surround channels of the core contain a downmix of the surround and back surround channels.