1. What's a Adts?
The Adts full name is (Audio Data Transport Stream) and is a very common transmission format for AAC.
Remember the first time to do Demux, the AAC audio es stream extracted from the FLV package format to the hardware decoder, can not be broadcast, save to the local PC player, I can not broadcast. It collapsed and was later known by looking for information. The general AAC decoder needs to pack the AAC es stream into a Adts format, typically adding a 7-byte Adts header before the AAC es stream. That means you can adts this head as AAC's frameheader.
2. Adts content and Structure
The information sampling rate, channel number and frame length of the ADTS header are relatively useful. Think about it too, if I were a decoder, you give me a bunch of AAC audio es stream I can not solve it. Each AAC stream with Adts header information clearly sends the decoder the information he needs.
In general, Adts header information is 7 bytes, divided into 2 parts:
Adts_fixed_header ();
Adts_variable_header ();
Syncword : The sync head is always 0xFFF, all bits must is 1, which represents the beginning of a Adts frame
ID: MPEG version:0 for MPEG-4, 1 for MPEG-2
Layer: Always: ' 00 '
Profile: Indicates which level of AAC is used, and some chips only support AAC LC. There are 3 types defined in MPEG-2 AAC:
Sampling_frequency_index: Represents the sample rate subscript used to find the value of the sample rate through this subscript in the sampling frequencies[] array.
There is supported frequencies:
- 0:96000 Hz
- 1:88200 Hz
- 2:64000 Hz
- 3:48000 Hz
- 4:44100 Hz
- 5:32000 Hz
- 6:24000 Hz
- 7:22050 Hz
- 8:16000 Hz
- 9:12000 Hz
- 10:11025 Hz
- 11:8000 Hz
- 12:7350 Hz
- 13:reserved
- 14:reserved
- 15:frequency is written explictly
channel_configuration: indicates the 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 a Adts frame includes the Adts header and the AAC primitive stream.
adts_buffer_fullness:0x7ff Description is a code stream with variable rate
3. Package AAC into ADTS format
If it is through the embedded high-definition decoder chip to do products, the general situation of decoding work is done by the hardware. So most of the work is to package the AAC original stream into a Adts format and then throw it to the hardware.
By understanding the Adts format, it is easy to package AAC into Adts. We just need to get information about the audio sample rate, channel number, metadata length, AAC format type, etc. in the package format. Then add a Adts header to the front of each AAC original stream to be OK.
By pasting the code that adds the Adts header to the ffmpeg, you can clearly understand the structure of the Adts head:
int Ff_adts_write_frame_header (Adtscontext *ctx, uint8_t *buf, int size, int pce_size) {P Utbitcontext PB; Init_put_bits (&PB, buf, adts_header_size); /* Adts_fixed_header */put_bits (&PB, 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, adts_header_size + SIZE + pce_size); /* Aac_frame_length */put_bits (&PB, one, 0x7ff); /* adts_buffer_fullness */put_bits (&PB, 2, 0); /* Number_of_raw_data_blocks_in_frame */flush_put_bits (&PB); return 0;}
AAC Adts Format Analysis