aac adts 格式分析

AAC音频格式在MPEG-2(ISO-13318-7 2003)中有定义。AAC后来又被采用到MPEG-4标准中。

AAC 有两种格式 ADIF(Audio Data Interchange Forma) 和 ADTS(Audio Data Transport Stream)

  • ADIF: ADIF只有一个统一的头,所以必须得到所有的数据后解码
  • ADTS: 每一帧都有头信息, 可以在任意帧解码

ADIF

adif头 + 对齐字节 + 数据块

1
2
3
4
5
adif_sequence() {
adif_header();
byte_alignment();
raw_data_stream();
}

ADTS

数据流是一帧一帧的adts,可以在任何位置解码。

1
2
3
4
5
6
adts_sequence() {
while (nextbits() == syncword)
{
adts_frame();
}
}

adts_frame

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
adts_frame() {
adts_fixed_header();
adts_variable_header();
if (number_of_raw_data_blocks_in_frame == 0) {
adts_error_check();
raw_data_block();
}
else {
adts_header_error_check();
for (i = 0; i <= number_of_raw_data_blocks_in_frame; i++) {
raw_data_block();
adts_raw_data_block_error_check();
}
}
}

每一帧都有28位的固定header + 28位的可变header组成的,共7字节。

adts_fixed_header

syncword

The bit string 1111 1111 1111.

ID

0 for MPEG-4, 1 for MPEG-2

layer

Indicates which layer is used. Set to 00.

protection_absent

Indicates whether error_check() data is present or not.
0 存在,1 不存在。

profile

sampling_frequency_index

private_bit

Bit for private use. This bit will not be used in the future by ISO/IEC.
set to 0 when encoding, ignore when decoding ??

channel_configuration

声道信息,大于0 根据下表来决定, 等于0?

original/copy

This bit equals ‘O if the bitstream is a copy, ‘1’ if it is an original.

编码时设置为0,解码时忽略?

home

编码时设置为0,解码时忽略?

adts_variable_header

copyright_identification_bit

编码时设置为0,解码时忽略?

copyright_identification_start

编码时设置为0,解码时忽略?

frame_length

Length of the frame including headers and error_check in bytes

adts_buffer_fullness

state of the bit reservoir in the course of encoding the ADTS frame, up to and including the first raw_data_block(). It is transmitted as the number of available bits in the bit reservoir divided by NCC divided by 32 and truncated to an integer value (Table 9). A value of hexadecimal 7FF signals that the bitstream is a variable rate bitstream. In this case, buffer fullness is not applicable

0x7FF 代表码率是可变的。

number_of_raw_data_blocks_in_frame

Number of raw_data_block()’s that are multiplexed in the adts_frame() is equal to
raw_data_block_position[i]
number_of_raw_data_blocks_in_frame + 1. The minimum value is 0 indicating 1 raw_data_block()

根据 number_of_raw_data_blocks_in_frame 是否等于 0 做区分

  • 等于0, 该帧里面中只有一个raw_data_block
  • 大于0, 该帧中有number_of_raw_data_blocks_in_frame + 1个raw_data_block
  • 大于 0 的情况较少见?
  • 每个raw_data_block对应于1024个采样?

adts_error_check

是否开启循环冗余校验,开启后header总长(28 + 28 + 16 = 72)9个字节。

adts_header_error_check

raw_data_block_position[i]

Start position of the i-th raw_data_block() in the adts_frame(), measured as an offset in bytes from the start position of the first raw_data_block() in the adts_frame().

如果开启循环冗余校验,并且number_of_raw_data_blocks_in_frame > 0, 记录每个raw_data_block开始位置,添加crc校验。

raw_data_block

判断声道,根据声道会有变化。

adts_raw_data_block_error_check

每个raw_data_block对应的校验。

工具

访问https://www.p23.nl/projects/aac-header/, 可以输入自己的aac 文件头部, 分析aac header 信息。


aac adts 格式分析
https://yxibng.github.io/2022/09/23/aac/2022-09-23-aac-adts/
作者
yxibng
发布于
2022年9月23日
许可协议