ADTS: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
Line 1: Line 1:
'''Audio Data Transport Stream''' ('''ADTS''') is a format, used by [[MPEG-2_Transport_Stream|MPEG TS]] or Shoutcast to stream audio, usually [[AAC]].
'''Audio Data Transport Stream''' ('''ADTS''') is a format, used by [[MPEG-2_Transport_Stream|MPEG TS]] or Shoutcast to stream audio defined in MPEG-2 Part 7, usually [[AAC]]. However, an MPEG-4 decoder may or may not support decoding it, which uses LOAS or LATM.


=== Structure ===
== Header ==


AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)
AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)
Line 43: Line 43:
| H
| H
| 3
| 3
| [[MPEG-4_Audio#Channel Configurations|MPEG-4 Channel Configuration]] (in the case of 0, the channel configuration is sent via an inband PCE)
| [[MPEG-4_Audio#Channel Configurations|MPEG-4 Channel Configuration]] (in the case of 0, the channel configuration is sent via an inband PCE (Program Config Element))
|-
|-
| I
| I
Line 86: Line 86:
|}
|}


=== Usage in MPEG-TS ===
== Usage ==
 
=== MPEG-TS ===


ADTS packet must be a content of PES packet. Pack AAC data inside ADTS frame, than pack inside PES packet, then mux by TS packetizer.
ADTS packet must be a content of PES packet. Pack AAC data inside ADTS frame, than pack inside PES packet, then mux by TS packetizer.


=== Usage in Shoutcast ===
=== Shoutcast ===


ADTS frames goes one by one in TCP stream. Look for syncword, parse header and look for next syncword after.
ADTS frames goes one by one in TCP stream. Look for syncword, parse header and look for next syncword after.
=== 3GPP, MOV, MP4 ===
FFmpeg's <code>[https://ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc aac_adtstoasc]</code> bitstream filter constructs [[MPEG-4_Audio#Audio_Specific_Config|MPEG-4 Audio Specific Config]] for MP4A-LATM (3GPP) and MOV/MP4 and related formats from an ADTS header.
== Buffer Fullness ==
Buffer Fullness, apparently, is merely an informative field with no clear use case defined in the specification. [http://blog.olivierlanglois.net/index.php/2008/09/12/aac_adts_header_buffer_fullness_field Oliver Langlois's blog] sheds some light on this topic. FFmpeg's ADTS parser [https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/adts_header.c#L58 ignores it] along with several optional/informative fields and [https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/adtsenc.c#L158 ignorantly puts a 0x7FF] like most software.




[[Category:Container Formats]]
[[Category:Container Formats]]

Revision as of 03:16, 25 April 2022

Audio Data Transport Stream (ADTS) is a format, used by MPEG TS or Shoutcast to stream audio defined in MPEG-2 Part 7, usually AAC. However, an MPEG-4 decoder may or may not support decoding it, which uses LOAS or LATM.

Header

AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)

Header consists of 7 or 9 bytes (without or with CRC).

Letter Length (bits) Description
A 12 Syncword 0xFFF, all bits must be 1
B 1 MPEG Version: 0 for MPEG-4, 1 for MPEG-2
C 2 Layer: always 0
D 1 Protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC
E 2 Profile, the MPEG-4 Audio Object Type minus 1
F 4 MPEG-4 Sampling Frequency Index (15 is forbidden)
G 1 Private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding
H 3 MPEG-4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE (Program Config Element))
I 1 Originality, set to 0 when encoding, ignore when decoding
J 1 Home, set to 0 when encoding, ignore when decoding
K 1 Copyrighted id bit, the next bit of a centrally registered copyright identifier, set to 0 when encoding, ignore when decoding
L 1 Copyright id start, signals that this frame's copyright id bit is the first bit of the copyright id, set to 0 when encoding, ignore when decoding
M 13 Frame length, length of the ADTS frame including headers
O 11 Buffer fullness, states the bit-reservoir per frame.
max_bit_reservoir = minimum_decoder_input_size - mean_bits_per_block; // for CBR

// bit reservoir state/available bits (≥0 and <max_bit_reservoir); for the i-th frame.
bit_reservoir_state[i] = (int)(bit_reservoir_state[i - 1] + mean_framelength - framelength[i]);

// NCC is the number of channels.
adts_buffer_fullness = bit_reservoir_state[i] / (NCC * 32);

However, a special value of 0x7FF denotes a variable bitrate, for which buffer fullness isn't applicable.

P 2 Number of AAC frames (RDBs) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame per ADTS frame
Q 16 CRC if protection absent is 0

Usage

MPEG-TS

ADTS packet must be a content of PES packet. Pack AAC data inside ADTS frame, than pack inside PES packet, then mux by TS packetizer.

Shoutcast

ADTS frames goes one by one in TCP stream. Look for syncword, parse header and look for next syncword after.

3GPP, MOV, MP4

FFmpeg's aac_adtstoasc bitstream filter constructs MPEG-4 Audio Specific Config for MP4A-LATM (3GPP) and MOV/MP4 and related formats from an ADTS header.

Buffer Fullness

Buffer Fullness, apparently, is merely an informative field with no clear use case defined in the specification. Oliver Langlois's blog sheds some light on this topic. FFmpeg's ADTS parser ignores it along with several optional/informative fields and ignorantly puts a 0x7FF like most software.