AAC ADTS 解析与生成

一、ADTS 格式

ADTS(Audio Data Transport Stream),通常被用于 MPEG TS 标准和流化音频格式为 AAC 的一种音频数据格式。

ADTS 数据格式: 

MorphologyLength(Bits)Description
syncword12syncword 0xFFF, all bits must be 1
ID1MPEG Version: 0 for MPEG-4, 1 for MPEG-2
layer2Layer: always 0
protection_absent1protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC
profile2profile, the MPEG-4 Audio Object Type minus 1
sampling_frequency_index4MPEG-4 Sampling Frequency Index (15 is forbidden)
private_bit1private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding
channel_configuraion3MPEG-4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE)
original_copy1originality, set to 0 when encoding, ignore when decoding
home1home, set to 0 when encoding, ignore when decoding
copyright_identification_bit1copyrighted id bit, the next bit of a centrally registered copyright identifier, set to 0 when encoding, ignore when decoding
copyright_identification_start1copyright id start, signals that this frame's copyright id bit is the first bit of the copyright id, set to 0 when encoding, ignore when decoding
aac_frame_length13frame length, this value must include 7 or 9 bytes of header length: FrameLength = (ProtectionAbsent == 1 ? 7 : 9) + size(AACFrame)
adts_buffer_fullness11Buffer fullness
number_of_raw_data_blocks_in_frame2Number of AAC frames (RDBs) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame per ADTS frame
CRC16CRC if protection absent is 0

二、ADTS 解析

常用参数解析:

    // profile [16-17]
    fmt->profile = frm_buf[2] >> 6;
    
    // sample index [18-21]
    uint8_t sampling_index = (frm_buf[2] & 0x3c) >> 2;
    fmt->sample_rate = sample_rate_for(sampling_index);
    
    // channels [23-25]
    fmt->channels = (frm_buf[2] & 0x01) << 7 | frm_buf[3] >> 6;
    
    // frame size [30-42]
    uint32_t frame_size = 0;
    frame_size |= (((frm_buf[3] & 0x03)) << 11);//high 2 bit
    frame_size |= (frm_buf[4] << 3);//middle 8 bit
    frame_size |= ((frm_buf[5] & 0xe0) >> 5);//low 3bit

三、ADTS 生成

    int sample_rate_index = sample_index_for(fmt->sample_rate);
    if (sample_rate_index < 0) {
        return sample_rate_index;
    }
    
    adts_buf[0] = 0xff;
    adts_buf[1] = 0xf1;
    adts_buf[2] = fmt->profile << 6 | sample_rate_index << 2 | 0x02 | fmt->channels >> 2;
    int aac_frame_length = fmt->data_size + HP_AAC_ADTS_HEADER_SIZE;
    adts_buf[3] = fmt->channels << 6 | aac_frame_length >> 11;
    adts_buf[4] = aac_frame_length >> 3 & 0x000000ff;
    adts_buf[5] = (aac_frame_length & 0x00000007) << 5 | 0x1f;
    adts_buf[6] = 0xfc;

已验证,源码地址:https://github.com/cwyethism/hp-utils-adts

四、参考

1、ISO_IEC_13818-7_2006(E).pdf

2、https://wiki.multimedia.cx/index.php?title=ADTS

3、https://www.jianshu.com/p/5c770a22e8f8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值