FILE *m_fd = NULL;
FILE *m_fd2 = NULL;
HANDLE_AACDECODER decoder = aacDecoder_Open(TT_MP4_ADTS, 1);
if (!decoder) {
printf("Failed to open AAC decoder");
return -1;
}
m_fd = fopen(s_acc.c_str(), "rb");
m_fd2 = fopen(s_pcm.c_str(), "wb");
decoder = aacDecoder_Open(TT_MP4_ADTS, 1);
if (!decoder) {
printf("Failed to open AAC decoder");
return -1;
}
m_fd = fopen(s_acc.c_str(), "rb");
m_fd2 = fopen(s_pcm.c_str(), "wb");
unsigned int size = 1024;
unsigned int valid;
unsigned char *data = (unsigned char *) malloc(size);
unsigned int decsize = 8 * 2048 * sizeof(INT_PCM);
unsigned char *decdata = (unsigned char *) malloc(decsize);
int frameCnt = 0;
do {
int len = fread(data, 1, size, m_fd);
if (len <= 0) {
break;
}
valid = len;
AAC_DECODER_ERROR err = aacDecoder_Fill(decoder, &data, &size, &valid);//往aac内部缓存中填数据
if (err != AAC_DEC_OK) {
printf("Failed to fill AAC decoder: %d\n", err);
break;
}
while (1) { //一定要加循环,一次有可能解码不完导致数据丢失
err = aacDecoder_DecodeFrame(decoder, (INT_PCM *) decdata, decsize / sizeof(INT_PCM),
0);
if (err != AAC_DEC_OK) {
printf("Failed to DecodeFrame: %d\n", err);
break;
}
//获取解码后码流的信息
CStreamInfo *info = aacDecoder_GetStreamInfo(decoder);
printf("--------------------frameSize:%d ", info->frameSize);//输出解码数据大小
printf("-------------------- sampleRate:%d ", info->sampleRate);//输出解码后采样率
printf("-------------------- numChannels:%d ", info->numChannels);//通道数
printf("-------------------- aacSampleRate:%d ", info->aacSampleRate);//输入aac数据采样率
//int flen = convert_16khz_to_8khz(tmp,decdata,info->frameSize*2); 重采样需要可以到其他链接中获取
fwrite(decdata, 1,info->frameSize * 4, m_fd2);
frameCnt++;
}
} while (1);
aacDecoder_Close(decoder);
if (data)
free(data);
if (decdata)
free(decdata);
if (m_fd)
fclose(m_fd);
if (m_fd2)
fclose(m_fd2);
fdk-aac解码aac为pcm数据
最新推荐文章于 2024-07-08 18:00:10 发布