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

http://blog.csdn.net/dancing_night/article/details/45972361