ADTS: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
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 similar to '''Audio Data Interchange Format''' ('''ADIF'''), 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 15: Line 15:
| A
| A
| 12
| 12
| Syncword 0xFFF, all bits '''must''' be 1
| Syncword, all bits ''must'' be set to 1.
|-
|-
| B
| B
| 1  
| 1  
| MPEG Version: 0 for MPEG-4, 1 for MPEG-2
| MPEG Version, set to 0 for MPEG-4 and 1 for MPEG-2.
|-
|-
| C
| C
| 2
| 2
| Layer: always 0
| Layer, always set to 0.
|-
|-
| D
| D
| 1
| 1
| Protection absent, '''Warning''', set to 1 if there is no CRC and 0 if there is CRC
| Protection absence, set to 1 if there is no CRC and 0 if there is CRC.
|-
|-
| E
| E
| 2
| 2
| Profile, the [[MPEG-4_Audio#Audio_Object_Types|MPEG-4 Audio Object Type]] minus 1
| Profile, the [[MPEG-4_Audio#Audio_Object_Types|MPEG-4 Audio Object Type]] minus 1.
|-
|-
| F
| F
| 4
| 4
| [[MPEG-4_Audio#Sampling_Frequencies|MPEG-4 Sampling Frequency Index]] (15 is forbidden)
| [[MPEG-4_Audio#Sampling_Frequencies|MPEG-4 Sampling Frequency Index]] (15 is forbidden).
|-
|-
| G
| G
| 1  
| 1  
| Private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding
| Private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding.
|-
|-
| 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
| 1  
| 1  
| Originality, set to 0 when encoding, ignore when decoding
| Originality, set to 1 to signal originality of the audio and 0 otherwise.
|-
|-
| J
| J
| 1
| 1
| Home, set to 0 when encoding, ignore when decoding
| Home, set to 1 to signal home usage of the audio and 0 otherwise.
|-
|-
| K
| K
| 1
| 1
| Copyrighted id bit, the next bit of a centrally registered copyright identifier, set to 0 when encoding, ignore when decoding
| Copyright ID bit, the next bit of a centrally registered copyright identifier. This is transmitted by sliding over the bit-string in LSB-first order and putting the current bit value in this field and wrapping to start if reached end (circular buffer).
|-
|-
| L
| L
| 1
| 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
| Copyright ID start, signals that this frame's Copyright ID bit is the first one by setting 1 and 0 otherwise.
|-
|-
| M
| M
| 13
| 13
| Frame length, length of the ADTS frame including headers
| Frame length, length of the ADTS frame including headers and CRC check.
|-
|-
| O
| O
| 11
| 11
| Buffer fullness, states the bit-reservoir per frame.
| Buffer fullness, states the bit-reservoir per frame.
  max_bit_reservoir = minimum_decoder_input_size - mean_bits_per_block; // for CBR
  max_bit_reservoir = minimum_decoder_input_size - mean_bits_per_RDB; // for CBR
   
   
  // bit reservoir state/available bits (≥0 and <max_bit_reservoir); for the i-th frame.
  // bit reservoir state/available bits (≥0 and <max_bit_reservoir); for the i-th frame.
Line 79: Line 79:
| P
| P
| 2
| 2
| Number of AAC frames (RDBs) in ADTS frame '''minus 1''', for maximum compatibility always use 1 AAC frame per ADTS frame
| Number of AAC frames (RDBs (Raw Data Blocks)) in ADTS frame '''minus 1'''. For maximum compatibility always use one AAC frame per ADTS frame.
|-
|-
| Q
| Q
| 16
| 16
| CRC if ''protection absent'' is 0
| CRC check (as of ISO/IEC 11172-3, subclause 2.4.3.1), if ''Protection absent'' is 0.
|}
|}


=== 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. It is advised to ignore this field when decoding and set to VBR mode when encoding (most implementations do).
== Notes ==
Up to field '''Home''' is the fixed header part of ADTS, meaning these values remain unchanged from frame to frame or ideally it should. The rest part of frame is subject to change. '''Private bit''', '''Originality''', '''Home''', '''Copyright ID bit''', '''Copyright ID start''' are subject to ignorance when decoding by setting them to 0 and ignoring it when decoding (most implementations do).
== TODO ==
Add internal structure information about ADTS (i.e layout of RDB and details inside of that).


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

Latest revision as of 05:28, 25 April 2022

Audio Data Transport Stream (ADTS) is a format similar to Audio Data Interchange Format (ADIF), 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, all bits must be set to 1.
B 1 MPEG Version, set to 0 for MPEG-4 and 1 for MPEG-2.
C 2 Layer, always set to 0.
D 1 Protection absence, 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 1 to signal originality of the audio and 0 otherwise.
J 1 Home, set to 1 to signal home usage of the audio and 0 otherwise.
K 1 Copyright ID bit, the next bit of a centrally registered copyright identifier. This is transmitted by sliding over the bit-string in LSB-first order and putting the current bit value in this field and wrapping to start if reached end (circular buffer).
L 1 Copyright ID start, signals that this frame's Copyright ID bit is the first one by setting 1 and 0 otherwise.
M 13 Frame length, length of the ADTS frame including headers and CRC check.
O 11 Buffer fullness, states the bit-reservoir per frame.
max_bit_reservoir = minimum_decoder_input_size - mean_bits_per_RDB; // 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 (Raw Data Blocks)) in ADTS frame minus 1. For maximum compatibility always use one AAC frame per ADTS frame.
Q 16 CRC check (as of ISO/IEC 11172-3, subclause 2.4.3.1), 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. It is advised to ignore this field when decoding and set to VBR mode when encoding (most implementations do).

Notes

Up to field Home is the fixed header part of ADTS, meaning these values remain unchanged from frame to frame or ideally it should. The rest part of frame is subject to change. Private bit, Originality, Home, Copyright ID bit, Copyright ID start are subject to ignorance when decoding by setting them to 0 and ignoring it when decoding (most implementations do).

TODO

Add internal structure information about ADTS (i.e layout of RDB and details inside of that).