ffmpeg pcm 编码aac问题 急/。。。。。。。。。。。。。。。

ykmao10 2013-03-22 10:21:30
我现在有段pcm数据,数据是完好的,没问题,现在转成aac文件,可是不知为什么转出来的都不对 代码很简单请大牛帮忙看看
int main(int argc, char **argv)
{
if(argc < 3)
{
printf("argc number is error\n");
return 0;
}

av_register_all();
AVCodecContext *encodecCtx = NULL;
AVCodec *encodec;
AVPacket enpacket;
AVFrame avframe;
int gotframeptr;

int frame_size = 0;
int *samples = 0;
int SAMPLESIZE = 0;
encodec = avcodec_find_encoder(CODEC_ID_AAC);
if(!encodec)
{
fprintf(stderr, "Unsupported encodec!\n");
return -1;
}
encodecCtx= avcodec_alloc_context3(encodec);

encodecCtx->channels = 2;
encodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
encodecCtx->sample_rate = 44100;
encodecCtx->bit_rate = 128000;
encodecCtx->profile = FF_PROFILE_AAC_LOW;
encodecCtx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;


if((avcodec_open2(encodecCtx, encodec, NULL) < 0))
{
fprintf(stderr, "can't open encodec!\n");
return -1;
}

frame_size = encodecCtx->frame_size;
samples = malloc(frame_size * 2 * encodecCtx->channels);
SAMPLESIZE = frame_size * 2 * encodecCtx->channels;

FILE *fin = NULL;
fin = fopen(argv[1],"rb");
if(!fin)
{
printf("open fin file error\n");
return 0;
}

FILE *fout = NULL;
fout = fopen(argv[2],"a+");
if(!fout)
{
printf("open fout file error\n");
return 0;
}

uint8_t *out_buf = (uint8_t*)malloc(encodecCtx->frame_size*8);
memset(out_buf,0,encodecCtx->frame_size*8);
int size;
int len;
while(1)
{
size = fread(samples,1,SAMPLESIZE,fin);
if(size == 0)
{
printf("read elf\n");
break;
}
avframe.data[0] = (uint8_t*)samples;
avframe.linesize[0] = SAMPLESIZE;
avframe.extended_data = &avframe.data[0];
avframe.nb_samples = encodecCtx->frame_size;
av_init_packet(&enpacket);
enpacket.data = NULL;
enpacket.size = 0;
len = avcodec_encode_audio(encodecCtx,out_buf,FF_MIN_BUFFER_SIZE,(short*)avframe.data[0]);
int num = fwrite(out_buf,1,len,fout);
if(num == 0)
{
printf("write error\n");
sleep(1);
}
memset(out_buf,0,FF_MIN_BUFFER_SIZE);
}
av_free_packet(&enpacket);
fclose(fout);
fclose(fin);
return 0;
}
...全文
211 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
simsoft 2014-10-16
  • 打赏
  • 举报
回复
http://www.cppblog.com/tx7do/archive/2013/01/31/197653.html
卡卡宇科 2013-05-23
  • 打赏
  • 举报
回复
http://download.csdn.net/detail/hanyujianren/5436473
qq454295775 2013-04-26
  • 打赏
  • 举报
回复
你好,在吗?我遇到了类似的问题,不知道你的解决的怎么样了?谢谢!
ykmao10 2013-03-26
  • 打赏
  • 举报
回复
lairen a

2,554

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧