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

Paul B Mahol onemda at gmail.com
Mon Jan 2 16:51:24 EET 2023


On Mon, Jan 2, 2023 at 3:39 PM wolverin via Libav-user <
libav-user at ffmpeg.org> wrote:

> On Mon, Jan 2, 2023 at 3:13 PM wolverin via Libav-user <
> libav-user at ffmpeg.org
> <//e.mail.ru/compose/?mailto=mailto%3alibav%2duser at ffmpeg.org>> wrote:
>
>
> *Output #0, rtsp, to 'rtsp://127.0.1.1:555 <http://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?
>

Nope.
PTS is just timebase * seconds represented as int64 number

There are no additions with next/prev pts values.


>
> 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.
>

Show your code.


>
> Thank you so much for your help!
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230102/57c3a6d0/attachment.htm>


More information about the Libav-user mailing list