In the storage video stream, you must set the PTS in the Avpacket, or the video will appear too fast or too slow, where the main use of ffmpeg in the Av_rescale_rnd function, you can see the previous blog.
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 */
//Convert Pts/dts (convert Pts/dts) packet->pts*out_stream->time_base.den/ in_stream- >time_base.den calculate the current time
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;