Difference between revisions of "ADTS"

From MultimediaWiki
Jump to navigation Jump to search
m (Cross reference MPEG-4 Audio)
 
(6 intermediate revisions by 2 users 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 ==


Header consists of 7 or 9 bytes (with or without CRC).
AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)


* 12 bits of syncword 0xFFF, all bits '''must''' be 1
Header consists of 7 or 9 bytes (without or with CRC).
* 1 bit of field ID. 0 for MPEG-4, 1 for MPEG-2
* 2 bits of MPEG layer. If you send AAC in MPEG-TS, set to 0
* 1 bit of protection absense. '''Warning''', set to 1 if there is no CRC and 0 if there is CRC
* 2 bits of profile code. The [[MPEG-4_Audio#Audio_Object_Types|MPEG-4 Audio Object Type]] minus 1
* 4 bits of sample rate code. [[MPEG-4_Audio#Sampling_Frequencies |MPEG-4 Sampling Frequency Index]] (15 is not allowed)
* 1 bit of private stream. Set to 0
* 3 bits of channels code. [[MPEG-4_Audio#Channel Configurations|MPEG-4 Channel Configuration]] (in the case of 0, the channel configuration is sent via an inband PCE)
* 1 bit of originality. Set to 0
* 1 bit of home. Set to 0
* 1 bit of copyrighted stream. Ignore it on read and set to 0
* 1 bit of copyright start. Set to 0
* 13 bits of frame length. This value must include 7 or 9 bytes of header length:  FrameLength = (ProtectionAbsent == 1 ? 7 : 9) + size(AACFrame)
* 11 bits of some data. unknown yet
* 2 bits of frames count in one packet. Set to 0
* aac frame going.


=== Usage in MPEG-TS ===
{|
|-
! 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#Audio_Object_Types|MPEG-4 Audio Object Type]] minus 1.
|-
| F
| 4
| [[MPEG-4_Audio#Sampling_Frequencies|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_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
| 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 <code>0x7FF</code> 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.
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).