酷咪哥 2016-08-19 14:09 采纳率: 100%
浏览 3690
已采纳

FFMPE的pkt的PTS如何计算

使用av_read_frame读取的pkt,发现个别pkt.pts是AV_NOPTS_VALUE,求问如何正确的对该值进行计算呢?

目前使用了两种方法,效果都不好:
#if 0
if(pkt.pts==AV_NOPTS_VALUE){
ms_waring( "The stream(%d:%s) has no pts,auto set it", type,(type==AVMEDIA_TYPE_VIDEO) ? "video" : "audio" );
AVRational time_base1=in_stream->time_base;
int64 calc_duration=(double)AV_TIME_BASE/av_q2d(ifmt_ctx->streams[push_param->flagopt.videostream_index]->r_frame_rate);
pkt.pts=(double)(vframe_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);
pkt.dts=pkt.pts;
pkt.duration=(double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);
}
#else

if(pkt.pts==AV_NOPTS_VALUE){
ms_waring( "The stream(%d:%s) has no pts,auto set it", type,(type==AVMEDIA_TYPE_VIDEO) ? "video" : "audio" );
double m_frameRate = in_stream->r_frame_rate.num /(double)in_stream->r_frame_rate.den;
int64_t pts = (int64_t)(AV_TIME_BASE * vframe_index / m_frameRate);
pts = av_rescale_q(pts, AV_TIME_BASE_Q, in_stream->time_base);
if (in_stream->first_dts > -AV_TIME_BASE){
pts += in_stream->first_dts;
}
//pkt.pts=pts;
}
#endif

  • 写回答

1条回答 默认 最新

  • devmiao 2016-08-19 16:00
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗