AAC ADTs format Analysis

Source: Internet
Author: User
1. What is ADTs?

The full name of ADTs is (Audio Data Transport Stream), which is a very common transmission format of AAC.

Remember that when Demux is used for the first time, when the es stream of AAC audio is extracted from the FLV Encapsulation Format and sent to the hardware decoder, it cannot be played. When it is saved to a local PC player for playback, I cannot play it either. At that time, I collapsed and found out the information. Generally, the AAC decoder needs to package the AAC es stream into the ADTs format. Generally, seven bytes of ADTs header must be added before the AAC es stream. That is to say, you can regard the ADTs header as the AAC frameheader.

ADTs AAC
Adts_header AAC es Adts_header AAC es ... Adts_header AAC es

2. ADTs content and structure

Useful information in the ADTs HeaderSampling Rate, number of channels, and frame length. Think about it too. If I were a decoder, you could not solve me by giving me a bunch of AAC audio es streams. Every AAC stream with the ADTs header information will clearly inform the decoder of the information he needs.

In general, the ADTs header information is 7 bytes, divided into two parts:

Adts_fixed_header ();

Adts_variable_header ();



Syncword: The synchronization header is always 0 xfff, all bits must be 1, representing the beginning of an ADTs frame.

ID: MPEG version: 0 for MPEG-4, 1 for MPEG-2

Layer: Always: '00'

Profile: Indicates the level of AAC used. Some chips only support aac lc. Three types are defined in MPEG-2 AAC:

Sampling_frequency_index: Indicates the subscripts of the sampling rate used.Sampling frequencies []Find the sample rate value in the array.

There are 13 supported frequencies:

  • 0: 96000Hz
  • 1: 88200Hz
  • 2: 64000Hz
  • 3: 48000Hz
  • 4: 44100Hz
  • 5: 32000Hz
  • 6: 24000Hz
  • 7: 22050Hz
  • 8: 16000Hz
  • 9: 12000Hz
  • 10:11025Hz
  • 11: 8000Hz
  • 12: 7350Hz
  • 13: Reserved
  • 14: Reserved
  • 15: frequency is written explictly

Channel_configuration:Number of channels

  • 0: defined in AOT specifc config
  • 1: 1 channel: Front-center
  • 2: 2 channels: Front-left, front-Right
  • 3: 3 channels: Front-center, front-left, front-Right
  • 4: 4 channels: Front-center, front-left, front-right, back-center
  • 5: 5 channels: Front-center, front-left, front-right, back-left, back-right
  • 6: 6 channels: Front-center, front-left, front-right, back-left, back-right, LFE-Channel
  • 7: 8 channels: Front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-Channel
  • 8-15: Reserved

Frame_length: The length of an ADTs Frame includes the ADTs header and the AAC original stream.

Adts_buffer_fullness:0x7ff indicates a variable bit rate code stream.

3. Pack AAC into ADTs format

If you use an embedded high-definition decoding chip as a product, the decoding work is generally completed by hardware. Therefore, most of the work is to package the AAC original stream into the ADTs format, and then discard it to the hardware.

By understanding the ADTs format, it is easy to package AAC into ADTs. We only need to obtain information about the audio sampling rate, number of audio channels, metadata length, and aac format in the Encapsulation Format. Add an ADTs header before each AAC original stream.

Paste the code of adding the ADTs header in FFMPEG to clearly understand the structure of the ADTs header:

int ff_adts_write_frame_header(ADTSContext *ctx,                                 uint8_t *buf, int size, int pce_size)  {      PutBitContext pb;        init_put_bits(&pb, buf, ADTS_HEADER_SIZE);        /* adts_fixed_header */      put_bits(&pb, 12, 0xfff);   /* syncword */      put_bits(&pb, 1, 0);        /* ID */      put_bits(&pb, 2, 0);        /* layer */      put_bits(&pb, 1, 1);        /* protection_absent */      put_bits(&pb, 2, ctx->objecttype); /* profile_objecttype */      put_bits(&pb, 4, ctx->sample_rate_index);      put_bits(&pb, 1, 0);        /* private_bit */      put_bits(&pb, 3, ctx->channel_conf); /* channel_configuration */      put_bits(&pb, 1, 0);        /* original_copy */      put_bits(&pb, 1, 0);        /* home */        /* adts_variable_header */      put_bits(&pb, 1, 0);        /* copyright_identification_bit */      put_bits(&pb, 1, 0);        /* copyright_identification_start */      put_bits(&pb, 13, ADTS_HEADER_SIZE + size + pce_size); /* aac_frame_length */      put_bits(&pb, 11, 0x7ff);   /* adts_buffer_fullness */      put_bits(&pb, 2, 0);        /* number_of_raw_data_blocks_in_frame */        flush_put_bits(&pb);        return 0;  }  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.