AAC ADTS format analysis

1. What is ADTS

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

I remember the first time I made demux, when I extracted the ES stream of AAC audio from the FLV package format and sent it to the hardware decoder, it could not be played; when it was saved to the local player and played on a PC, I could not play it. It collapsed at the time, and I found out later by looking for information. The general AAC decoder needs to package the AAC ES stream into the ADTS format, generally adding a 7-byte ADTS header before the AAC ES stream. That is to say, you can regard the ADTS header as the frameheader of AAC.

ADTS AAC

ADTS_header AAC EN ADTS_header AAC EN

...

ADTS_header AAC EN


2. ADTS content and structure

Relatively useful information in the ADTS header  sample rate, number of channels, frame length . Think about it, if I were a decoder, I couldn't solve it if you gave me a bunch of AAC audio ES streams. Each AAC stream with ADTS header information will clearly inform the decoder of the information it needs.

Under normal circumstances, the header information of ADTS is 7 bytes, divided into 2 parts:

adts_fixed_header();

adts_variable_header();



syncword  : The sync header is always 0xFFF, all bits must be 1, which represents the beginning of an ADTS frame

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

Layer:always: '00'

profile : Indicates which level of AAC to use, some chips only support AAC LC. Three are defined in MPEG-2 AAC:

sampling_frequency_index:表示使用的采样率下标,通过这个下标在 Sampling Frequencies[ ]数组中查找得知采样率的值。

There are 13 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: 表示声道数 

  • 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 : 一个ADTS帧的长度包括ADTS头和AAC原始流.

adts_buffer_fullness:0x7FF 说明是码率可变的码流

3.将AAC打包成ADTS格式

如果是通过嵌入式高清解码芯片做产品的话,一般情况的解码工作都是由硬件来完成的。所以大部分的工作是把AAC原始流打包成ADTS的格式,然后丢给硬件就行了。

通过对ADTS格式的了解,很容易就能把AAC打包成ADTS。我们只需得到封装格式里面关于音频采样率、声道数、元数据长度、aac格式类型等信息。然后在每个AAC原始流前面加上个ADTS头就OK了。

贴上ffmpeg中添加ADTS头的代码,就可以很清晰的了解ADTS头的结构:

[html] view plaincopy

  1. int ff_adts_write_frame_header(ADTSContext *ctx,  

  2.                                uint8_t *buf, int size, int pce_size)  

  3. {  

  4.     PutBitContext pb;  

  5.   

  6.     init_put_bits(&pb, buf, ADTS_HEADER_SIZE);  

  7.   

  8.     /* adts_fixed_header */  

  9.     put_bits(&pb, 12, 0xfff);   /* syncword */  

  10.     put_bits(&pb, 1, 0);        /* ID */  

  11.     put_bits(&pb, 2, 0);        /* layer */  

  12.     put_bits(&pb, 1, 1);        /* protection_absent */  

  13.     put_bits(&pb, 2, ctx->objecttype); /* profile_objecttype */  

  14.     put_bits(&pb, 4, ctx->sample_rate_index);  

  15.     put_bits(&pb, 1, 0);        /* private_bit */  

  16.     put_bits(&pb, 3, ctx->channel_conf); /* channel_configuration */  

  17.     put_bits(&pb, 1, 0);        /* original_copy */  

  18.     put_bits(&pb, 1, 0);        /* home */  

  19.   

  20.     /* adts_variable_header */  

  21.     put_bits(&pb, 1, 0);        /* copyright_identification_bit */  

  22.     put_bits(&pb, 1, 0);        /* copyright_identification_start */  

  23.     put_bits(&pb, 13, ADTS_HEADER_SIZE + size + pce_size); /* aac_frame_length */  

  24.     put_bits(&pb, 11, 0x7ff);   /* adts_buffer_fullness */  

  25.     put_bits(&pb, 2, 0);        /* number_of_raw_data_blocks_in_frame */  

  26.   

  27.     flush_put_bits(&pb);  

  28.   

  29.     return 0;  

  30. }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325904550&siteId=291194637