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

Paul B Mahol onemda at gmail.com
Mon Jan 2 14:00:33 EET 2023


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

> On Thu, Dec 29, 2022 at 9:45 AM wolverin via Libav-user <
> libav-user at ffmpeg.org
> <http://e.mail.ru/compose/?mailto=mailto%3alibav%2duser@ffmpeg.org>>
> wrote:
>
> I'm transcoding live video from MJPEG to H264 using ffmpeg library in my
> C/C++ project
>
> Help me figure out how to calculate the pts/dts correctly, using various
> av_rescale* functions did not give the correct values and I tried my simple
> version, but the number of frames per second is different all the time and
> of course these values are approximate
>
> int64_t * pcnt
>
> pPktOut->pos = (*pcnt);
> pPktOut->pts = pPktOut->pos * pFmtCtxOut->streams[0]->time_base.den  /
> pCdcCtxOut->time_base.den;
>
>
> This does not make any sense.
>
> Time base is rational and thus both numerator and denumerator should be
> used.
>
>
> Thanks for your reply.
> Yes, you are right, but I have time_base.num = 1 (for out stream 1/90000,
> for codeccontext 1/15 — 15 fps is the desired frequency, but in reality it
> varies between 16-20)
> Here is an example of my time base dumps
>
> *Input #0, video4linux2,v4l2, from '/dev/video0':*
> *  Duration: N/A, start: 532397.028007, bitrate: N/A*
> *  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc,
> bt470bg/unknown/unknown), 1280x720, 30 fps, 30 tbr, 1000k tbn*
>
> *[libx264 @ 0x14ef370] using cpu capabilities: ARMv6 NEON*
> *[libx264 @ 0x14ef370] profile High 4:2:2, level 3.1, 4:2:2 8-bit*
> *[libx264 @ 0x14ef370] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC
> codec - Copyleft 2003-2015 - http://www.videolan.org/html
> <http://www.videolan.org/html> - options: cabac=0 ref=1 deblock=0:0:0
> analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16
> chrom1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1
> chroma_qp_offset=0 threads=4 lookahead_threads=4 sliced_threads=1 sl4 nr=0
> decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0
> weightp=0 keyint=250 keyint_min=15 scenecut=0 _refresh=0 rc_lookahead=0
> rc=cbr mbtree=0 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69
> qpstep=4 vbv_maxrate=500 vbv_ze=1000 nal_hrd=none filler=0 ip_ratio=1.40
> aq=0*
> *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.


>
>
> _______________________________________________
> 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/d37d37fd/attachment.htm>


More information about the Libav-user mailing list