An AC-3 or Enhanced AC-3 stream needs no header of its own: every syncframe describes itself. Containers still announce it, so a player can choose a stream without opening it. ETSI TS 102 366 specifies the carriage in MPEG-2 transport streams (Annexes A and G), in ISO base media files such as MP4 (Annex F), in MPEG-DASH (Annex I) and in CMAF (Annex J).
Raw streams
An .ac3, .ec3 or .eac3 file is the syncframes
one after another. The stream is normally big-endian, starting 0B 77; a
stream kept as little-endian 16-bit words starts its frames 77 0B and is
read by swapping each pair of bytes. TS 102 366 allows that order in MP4 files but
recommends big-endian.
MPEG-2 transport streams
In an MPEG-2 transport stream each syncframe is an access unit, carried in PES packets
and byte-aligned. In ATSC systems (System A) AC-3 has stream_type 0x81 and
PES stream_id 0xBD (private_stream_1); the programme map table carries a
registration descriptor (tag 0x05, length 4, format_identifier 0x41432D33,
“AC-3”) and the AC-3 audio stream descriptor below. In DVB systems (System B) the rules
are in ETSI TS 101 154 and EN 300 468, and AC-3’s descriptor is a public one with a
different syntax. Enhanced AC-3 in transport streams is specified in ATSC A/52 Annex G
and, for DVB, in the same two ETSI documents. Streams to be played in sync (a main
service and an associated one) must be encoded frame-synchronously and carry the same
PTS values.
AC-3 audio stream descriptor (System A)
| Bits | Field | Meaning |
|---|---|---|
| 8 | descriptor_tag | 0x81 |
| 8 | descriptor_length | bytes that follow; the descriptor may end after any of the groups below |
| 3 | sample_rate_code | 0 = 48 kHz, 1 = 44.1, 2 = 32, 3 reserved, 4 = 48 or 44.1, 5 = 48 or 32, 6 = 44.1 or 32, 7 = any of the three |
| 5 | bsid | as in the stream |
| 6 | bit_rate_code | low 5 bits: 0–18 for 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 kbit/s; top bit 0 the exact rate, 1 an upper limit |
| 2 | surround_mode | the stream’s dsurmod, or 0 (not indicated) |
| 3 | bsmod | as in the stream |
| 4 | num_channels | top bit 0: the low bits are the stream’s acmod (0 for 1+1, … 7 for 3/2); top bit 1: at most 1 (1000), 2, 3, 4, 5 or 6 (1101) channels counting the LFE; 1110 and 1111 reserved |
| 1 | full_svc | 1: the service is complete in itself; 0: it must be mixed with another |
| 8 | langcod | the stream’s langcod, or 0xFF; no longer used for language |
| 8 | langcod2 | only when num_channels is 0 (dual mono) |
| 3 + 2 + 3 | mainid, priority, reserved (111) | if bsmod is 0 or 1: the main service number 0–7, and priority 0 reserved, 1 primary audio, 2 other audio, 3 not specified |
| 8 | asvcflags | otherwise: bit n set when this associated service goes with main service n |
| 7 + 1 | textlen, text_code | length in bytes of a description, and its coding: 1 ISO 8859-1, 0 two-byte Unicode |
| textlen × 8 | text | a short description of the service |
| 1 + 1 + 6 | language_flag, language_flag_2, reserved (111111) | which language fields follow (the second only in dual mono) |
| 24, 24 | language, language_2 | ISO 639-2/B codes in ISO 8859-1, for the service or Ch1, and for Ch2 |
| n × 8 | additional_info | reserved for ATSC |
The transport stream system target decoder’s main audio buffer for AC-3 is BSmux (736 bytes) + BSpad (64 bytes) + BSdec, where BSdec is sized for the highest bit rate the system allows.
MP4 and other ISO base media files
An AC-3 track is a sound track (handler soun) whose sample description is
an ac-3 AC3SampleEntry; Enhanced AC-3 uses an ec-3
EC3SampleEntry (encrypted tracks use their scheme’s type instead). Both are laid out
exactly as an AudioSampleEntry, whose ChannelCount and SampleSize a reader ignores, with
the sample rate in SamplingRate and in the media timescale, and end with a box
describing the stream. Using MP4AudioSampleEntry with an object type for AC-3 is not
allowed.
An AC-3 sample is one syncframe; an Enhanced AC-3 sample is as many syncframes as it
takes to give six blocks of every substream, starting with independent substream 0.
Either way sample_delta is 1,536, and a sample is padded with up to 7 zero
bits to a byte. The stream’s parameters (bsid, bsmod, acmod, lfeon, fscod, frmsizecod for
AC-3; the number of substreams and each one’s bsid, bsmod, acmod, lfeon, fscod and
chanmap for E-AC-3) must not change within the track.
dac3: AC3SpecificBox
| Bits | Field | Meaning |
|---|---|---|
| 32 + 32 | size, type | type dac3 |
| 2 | fscod | as in the stream |
| 5 | bsid | as in the stream |
| 3 | bsmod | as in the stream |
| 3 | acmod | as in the stream |
| 1 | lfeon | as in the stream |
| 5 | bit_rate_code | 0–18: 32 to 640 kbit/s, from frmsizecod (the same list as above) |
| 5 | reserved | 0 |
dec3: EC3SpecificBox
| Bits | Field | Meaning |
|---|---|---|
| 32 + 32 | size, type | type dec3 |
| 13 | data_rate | the whole stream’s rate in kbit/s (the sum of the substreams’, each its frame size over its frame duration), or the maximum for a variable rate |
| 3 | num_ind_sub | the substream ID of the last independent substream (one less than their number) |
| for each independent substream: | ||
| 2, 5 | fscod, bsid | as in that substream |
| 1 | reserved | 0 |
| 1 | asvc | 1: an associated service, to be mixed with a main service (a player that cannot mix ignores it); 0: a main service |
| 3, 3, 1 | bsmod, acmod, lfeon | as in that substream (bsmod 0 if the substream has no informational metadata) |
| 3 | reserved | 0 |
| 4 | num_dep_sub | the substream ID of the dependent substream just before the next independent one |
| 9 or 1 | chan_loc or reserved | if there are dependent substreams: the extra channel locations their channel maps add, by bit from the least significant: 0 Lc/Rc, 1 Lrs/Rrs, 2 Cs, 3 Ts, 4 Lsd/Rsd, 5 Lw/Rw, 6 Lvh/Rvh, 7 Cvh, 8 LFE2 |
| rest | reserved | bytes a reader skips |
MPEG-DASH
An adaptation set of AC-3 or E-AC-3 has @codecs ac-3 or
ec-3, @mimeType audio/mp4 and
@startWithSAP 1, and an AudioChannelConfiguration descriptor. With the
scheme urn:mpeg:mpegB:cicp:ChannelConfiguration its value is the
ISO/IEC 23001-8 channel configuration:
| Value | Channels (acmod and chanmap) |
|---|---|
| 1 | C |
| 2 | L, R |
| 3 | L, C, R |
| 4 | L, C, R, Cs |
| 5 | L, C, R, Ls, Rs |
| 6 | L, C, R, Ls, Rs, LFE |
| 7 | L, C, R, Lw/Rw, Ls, Rs, LFE (L and R as the front centre pair, Lw/Rw as the front pair) |
| 9 | L, R, Cs |
| 10 | L, R, Ls, Rs |
| 11 | L, C, R, Ls, Rs, Cs, LFE |
| 12 | L, C, R, Ls, Rs, Lrs/Rrs, LFE |
| 14 | L, C, R, Ls, Rs, LFE, Vhl/Vhr |
| 16 | L, C, R, Ls, Rs, LFE, Vhl/Vhr, Lts/Rts |
| 17 | L, C, R, Ls, Rs, LFE, Vhl/Vhr, Vhc, Lts/Rts, Ts |
| 19 | L, C, R, Lsd/Rsd, Lrs/Rrs, LFE, Vhl/Vhr, Lts/Rts |
With the scheme tag:dolby.com,2014:dash:audio_channel_configuration:2011 the
value is the 16-bit channel map as
four hexadecimal digits, left channel first: F801 for L, C, R, Ls, Rs and
LFE.
CMAF
CMAF tracks follow the MP4 rules above, with codecs ac-3 or
ec-3, and further limits: big-endian frames only; no dual mono; bsid,
bsmod, acmod, lfeon, fscod, frmsizecod and chanmap fixed for the track. For E-AC-3, every
substream has the same number of blocks a frame, no substream is of type 2 or 3, and
there are at most two substreams: independent substream 0 (bsid 16 alone; 6, 8 or 16
with a dependent) and dependent substream 0 (bsid 16). The first frame of each sample is
independent substream 0 with convsync 1. Because a block can only be fully
decoded with the one before it, encoders add a delay, which an edit list or the
encapsulation must remove. The Core Audio Media Profile, brand ceac,
further requires 48 kHz and at most 3,024 kbit/s, and the stream should carry DRC words
and EMDF loudness data.
WAV
Microsoft’s list of WAV format codes names three for AC-3: 0x2000 (WAVE_FORMAT_DVM, used for plain AC-3 frames), 0x0092 (WAVE_FORMAT_DOLBY_AC3_SPDIF: AC-3 packed for an S/PDIF link as IEC 61937 bursts, each a preamble F872 4E1F, a type word and a length word, then the frame as byte-swapped 16-bit words and padding) and 0x0241 (ESST_AC3). Extensible WAV files name IEC 61937 Dolby Digital Plus with a SubFormat GUID ending -0CEA-0010-8000-00AA00389B71. These codes come from Microsoft, not from TS 102 366. This site’s WAV viewer plays all three codes with its AC-3 decoder, which finds frames in either byte order.