#include <stdio.h>
#include <memory.h>
#include "faad.h"
#include <string>
#include <iostream>
#include <stdlib.h>
#define FRAME_MAX_LEN 1024*5
#define BUFFER_MAX_LEN 1024*1024
using namespace std;
/**
* * fetch one ADTS frame
* */
int get_one_ADTS_frame(unsigned char* buffer, size_t buf_size, unsigned char* data ,size_t* data_size)
{
size_t size = 0;
if(!buffer || !data || !data_size )
{
return -1;
}
while(1)
{
if(buf_size < 7 )
{
return -1;
}
if((buffer[0] == 0xff) && ((buffer[1] & 0xf0) == 0xf0) )
{
size |= ((buffer[3] & 0x03) <<11); //high 2 bit
size |= buffer[4]<<3; //middle 8 bit
size |= ((buffer[5] & 0xe0)>>5); //low 3bit
break;
}
--buf_size;
++buffer;
}
if(buf_size < size)
{
return -1;
}
memcpy(data, buffer, size);
*data_size = size;
return 0;
}
int main(int argc, char* argv[])
{
static unsigned char frame[FRAME_MAX_LEN];
static unsigned char buffer[BUFFER_MAX_LEN] = {0};
static unsigned char frame_mono[BUFFER_MAX_LEN];
char src_file[128] = {0};
char dst_file[128] = {0};
FILE* ifile = NULL;
FILE* ofile = NULL;
unsigned long samplerate;
unsigned char channels;
NeAACDecHandle decoder = 0;
size_t data_size = 0;
size_t size = 0;
NeAACDecFrameInfo frame_info;
unsigned char* input_data = buffer;
unsigned char* pcm_data = NULL;
//ifile = fopen("/usr/local/nginx/html/MP4/aac/151869402028019501/20180105/151869402028019501_20180105171732.aac","rb");
ifile = fopen("tdjm.aac","rb");
ofile = fopen("2.pcm","wb");
data_size = fread(buffer, 1, BUFFER_MAX_LEN, ifile);
printf("the data_size is :%d\n", data_size);
decoder = NeAACDecOpen();
if(get_one_ADTS_frame(buffer, data_size, frame, &size) < 0)
{
return -1;
}
NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(decoder);
conf->defObjectType = LC;
conf->outputFormat = FAAD_FMT_16BIT;
conf->dontUpSampleImplicitSBR = 1;
NeAACDecSetConfiguration(decoder,conf);
NeAACDecInit(decoder, frame, size, &samplerate, &channels);
printf("samplerate %d, channels %d\n", samplerate, channels);
while(get_one_ADTS_frame(input_data, data_size, frame, &size) == 0)
{
pcm_data = (unsigned char*)NeAACDecDecode(decoder, &frame_info, frame, size);
if(frame_info.error > 0)
{
printf("%s\n",NeAACDecGetErrorMessage(frame_info.error));
}
else if(pcm_data && frame_info.samples > 0)
{
printf("frame info: bytesconsumed %d, channels %d, header_type %d\
object_type %d, samples %d, samplerate %d\n",
frame_info.bytesconsumed,
frame_info.channels, frame_info.header_type,
frame_info.object_type, frame_info.samples,
frame_info.samplerate);
int i,j;
//read the data from the two channels
for(i=0, j=0; i<4096&&j<2048;i+=4, j+=2)
{
frame_mono[j] = pcm_data[i];
frame_mono[j+1] = pcm_data[i+1];
}
//fwrite(frame_mono, 1, frame_info.samples, ofile); //2个通道
fwrite(frame_mono, 1, frame_info.samples, ofile);
//fwrite(pcm_data, 1, frame_info.samples*frame_info.channels, ofile);
fflush(ofile);
}
data_size -= size;
input_data += size;
}
NeAACDecClose(decoder);
fclose(ifile);
fclose(ofile);
return 0;
}

lingzhaoli
- 粉丝: 4
最新资源
- 基于Qt数据库项目实现Sqlite3为例 (1).zip
- 基于仓颉编程语言的web快速开发框架.zip
- 基于51单片机的心率检测仪资源下载.zip
- 基于OpenCv的SVM实现车牌检测与识别系统.zip
- 基于pyqt5和MySQL的学生管理系统.zip
- 基于二次曲面模型的动态对象SLAM.zip
- 基于SpringBoot + Vue的社区桶装水配送平台.zip
- 一种基于氮转换速率的算法.zip
- 基于QChart和QChartView创建各种图表和美化图表.zip
- 基于SpringBoot + Vue在线电子书阅读平台.zip
- 基于爬虫技术的商品数据监测系统.zip
- 基于SpringBoot + Vue的城市社区食堂管理系统.zip
- 基于Witin-nn的ResNet18量化抗噪研究.zip
- 基于SpringBoot + Vue的实验室耗材管理系统.zip
- 针对月时间长度的重力观测数据的时頻分析方法和绘图.zip
- 基于深度学习的边缘提取方法.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0