标签:aac adts 解码
AAC原始流能让ffmpeg软解或系统硬解,最简单的处理可在前面加上ADTS头,那么这个ADTS头如何添加呢?其实就是七个字节,下面分享一个我使用的代码样例,每次传递数据都是以一个个sample为单元的:
adts_header[7] = {0xff,0xf9,0x00,0x00,0x00,0x1f,0xfc};
//AAC level
switch(AAC_level)
{
case AUDIO_AACM:
adts_header[2] |= (0x00 << 6)&0xc0;
break;
case AUDIO_AACL:
adts_header[2] |= (0x01 << 6)&0xc0;
break;
case AUDIO_AACS:
adts_header[2] |= (0x02 << 6)&0xc0;;
break;
default:/*use AACL*/
adts_header[2] |= (0x01 << 6)&0xc0;
break;
}
//sampling rate
switch(AAC_sample_rate)
{
case SAMPLINGRATE_96000HZ:
adts_header[2] |= (0x00 << 2)&0x3c;
break;
case SAMPLINGRATE_88200HZ:
adts_header[2] |= (0x01 << 2)&0x3c;
break;
case SAMPLINGRATE_64000HZ:
adts_header[2] |= (0x02 << 2)&0x3c;
break;
case SAMPLINGRATE_48000HZ:
adts_header[2] |= (0x03 << 2)&0x3c;
break;
case SAMPLINGRATE_44100HZ:
adts_header[2] |= (0x04 << 2)&0x3c;
break;
case SAMPLINGRATE_32000HZ:
adts_header[2] |= (0x05 << 2)&0x3c;
break;
case SAMPLINGRATE_24000HZ:
adts_header[2] |= (0x06 << 2)&0x3c;
break;
case SAMPLINGRATE_22050HZ:
adts_header[2] |= (0x07 << 2)&0x3c;
break;
case SAMPLINGRATE_16000HZ:
adts_header[2] |= (0x08 << 2)&0x3c;
break;
case SAMPLINGRATE_12000HZ:
adts_header[2] |= (0x09 << 2)&0x3c;
break;
case SAMPLINGRATE_11025HZ:
adts_header[2] |= (0x0a << 2)&0x3c;
break;
case SAMPLINGRATE_8000HZ:
adts_header[2] |= (0x0b << 2)&0x3c;
break;
default:/*use 44100*/
adts_header[2] |= (0x04 << 2)&0x3c;
break;
}
//channels
switch(AAC_channel_no)
{
case CHANNEL_NUMBER_1:
adts_header[2] |= (0x01 >> 2)&0x01;
adts_header[3] |= (0x01 << 6)&0xc0;
break;
case CHANNEL_NUMBER_2:
adts_header[2] |= (0x02 >> 2)&0x01;
adts_header[3] |= (0x02 << 6)&0xc0;
break;
case CHANNEL_NUMBER_3:
adts_header[2] |= (0x03 >> 2)&0x01;
adts_header[3] |= (0x03 << 6)&0xc0;
break;
case CHANNEL_NUMBER_4:
adts_header[2] |= (0x04 >> 2)&0x01;
adts_header[3] |= (0x04 << 6)&0xc0;;
break;
case CHANNEL_NUMBER_5:
adts_header[2] |= (0x05 >> 2)&0x01;
adts_header[3] |= (0x05 << 6)&0xc0;
break;
case CHANNEL_NUMBER_6:
adts_header[2] |= (0x06 >> 2)&0x01;
adts_header[3] |= (0x06 << 6)&0xc0;
break;
case CHANNEL_NUMBER_8:
adts_header[2] |= (0x07 >> 2)&0x01;
adts_header[3] |= (0x07 << 6)&0xc0;
break;
default:/*use number 2*/
adts_header[2] |= (0x02 >> 2)&0x01;
adts_header[3] |= (0x02 << 6)&0xc0;
break;
}
adts_header[3] = adts_header[3] | ((AAC_adts_sample_size >> 11)& 0x3);
adts_header[4] = adts_header[4] | ((AAC_adts_sample_size >> 3) & 0xff);
adts_header[5] = adts_header[5] | (((AAC_adts_sample_size >> 0)& 0x07) << 5);
标签:aac adts 解码
原文地址:http://blog.csdn.net/acm2008/article/details/42971473