The problem of PTS in the avpacket of FFmpeg

Source: Internet
Author: User
Tags current time



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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.