[Libav-user] How to calculate pts/dts ???

wolverin wolverin82 at mail.ru
Mon Jan 2 16:39:06 EET 2023


>On Mon, Jan 2, 2023 at 3:13 PM wolverin via Libav-user < libav-user at ffmpeg.org > wrote:  
>>>>Output #0, rtsp, to 'rtsp:// 127.0.1.1:555 ':
>>>>  Stream #0:0: Video: h264, yuv422p(tv, bt470bg/unknown/unknown), 1280x720, q=2-31, 500 kb/s, 15 tbr, 90k tbn
>>>> 
>>>> 
>>>>I compared such an approximate calculation of pts/dts in ffprobe for my code and ffmpeg and they match until the real fps becomes different from the calculated one, then I see either delays or frame losses in VLC.
>>> 
>>>You can not use 15 from video frame rate to calculate PTS when video is variable frame rate.
>> 
>>ok, but then how do I calculate the pts/dts of each frame correctly???
> 
>PTS is represented as relative time starting from 0 for start of file.
> 
>PTS is just a int64_t number that tells relative time.
>To know time resolution one use timebase.num/den, so they are actually tied together with pts timestamp.
> 
>If video is VFR than there are gaps e.g. non-monotonous increasing of pts from older to newer ones.
> 
>Say time of frame is 5.5 seconds and timebase used is 1/90000 than time of 1 second would have value of 90000 stored in pts.
>5.5 seconds would then be 5*90000 + 0.5*90000.
> 
>Hope that you can conclude from this demonstration how to solve your problem.
> 
>To rescale PTS from one timebase resolution to another one use av_rescale_q().
 
Did I understand you correctly that I need to multiply time_base and system time between adjacent frames and add the resulting time to the previous PTS?
 
I used av_rescale_q to scale time_base from an incoming MJPEG stream to an outgoing H264 one, but for some reason timestamps pts/dts are meaningless in this case.
 
Thank you so much for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230102/22b1510f/attachment.htm>


More information about the Libav-user mailing list