关于ffmpeg的avpacket里的pts问题



                    在进行存储视频流的时候,必须将avpacket里的pts设置好,否则会出现视频过快或过慢的情况,在此主要用到ffmpeg里的av_rescale_rnd函数,可看之前的博客。

               

                      //time_base:time_base.num/time_base.den,1/9000

                      AVRational time_base1=in_stream->time_base;

//Duration between 2 frames (us)
int64_t calc_duration=(double)AV_TIME_BASE/av_q2d(in_stream->r_frame_rate);
//Parameters
packet->pts=(double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);
packet->dts=packet->pts;
packet->duration=(double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);
frame_index++;
        }
/* copy packet */
//转换PTS/DTS(Convert PTS/DTS) packet->pts*out_stream->time_base.den/  in_stream->time_base.den算出现在的时间
packet->pts = av_rescale_rnd(packet->pts, out_stream->time_base.den,in_stream->time_base.den,AV_ROUND_NEAR_INF);
packet->dts = av_rescale_rnd(packet->dts, out_stream->time_base.den,in_stream->time_base.den,AV_ROUND_NEAR_INF);
packet->duration = av_rescale_q(packet->duration, in_stream->time_base,out_stream->time_base);
packet->pos = -1;
packet->stream_index=0;

你可能感兴趣的:(关于ffmpeg的avpacket里的pts问题)