最新ffmpeg,提取音频,pts设置问题,求救啊!!!!

haitao111313 2013-12-20 11:42:53

while (av_read_frame(ic, &packet) >= 0) {
if (packet.stream_index == videoindex + 111) {
} else if (packet.stream_index == audioindex) {
int ret = 0;
while (packet.size > 0) {
out_buf = NULL;
if (packet.size > 0)
samples = (short *) av_fast_realloc(samples, &samples_size,
FFMAX(packet.size*sizeof
(*samples),2000));
LOGI("LOGI----------------19 ");

ret = avcodec_decode_audio4(aCodecCtx, oAFrame, &frameFinished2,
&packet);
// ret = avcodec_decode_audio3(aCodecCtx,samples,&out_size,&packet);//若为音频包,解码该音频包
LOGI("retretret:%d", ret);
if (ret < 0) {
LOGI("while decode audio failure\n");
exit(0);
}
packet.data += ret;
packet.size -= ret;
av_fifo_generic_write(fifo,oAFrame->data[0],oAFrame->linesize[0],NULL);
if (frameFinished2) {
out_buf = (uint8_t *) samples;
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
ret1 = avcodec_encode_audio2(oAcc, &pkt, oAFrame,
&got_output);
if (ret1 < 0) {
fprintf(stderr, "Error encoding audio frame\n");
exit(1);
}
if (got_output) {

if (oAcc->coded_frame&& oAcc->coded_frame->pts != AV_NOPTS_VALUE) {
pkt.pts= av_rescale_q(oAcc->coded_frame->pts, oAcc->time_base, audio_st->time_base);
}
pkt.flags |= AV_PKT_FLAG_KEY;
pkt.stream_index = audioindex;
av_write_frame(oc, &pkt);
av_free_packet(&pkt);
m_nAudioTimeStamp++;
}
}


}
}

av_free_packet(&packet);
}

上面是从mp4文件提取音频生成mp4文件的主要代码,报错:Encoder did not produce proper pts, making some up.
但是如果从mp3文件提取音频生成mp4,就不会报错,这个pkt的pts到底该怎么设置? 我的编码器的属性设置完全是按照解码器来设置的!!!!!!
如果直接用fwrite写成aac文件也是没有问题的,但是我现在的需求就是要从mp4文件提取音频,怎么办????
...全文
659 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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