<HTML><BODY><div class="js-helper js-readmsg-msg"><div id="style_16726579780851210439"><div id="style_16726579780851210439_BODY"><div class="cl_749072"><div><blockquote style="border-left:1px solid #0857A6;margin:10px;padding:0 0 0 10px;"><div id=""><div class="js-helper_mr_css_attr js-readmsg-msg_mr_css_attr"><div><div id="style_16726518520659420687_BODY_mr_css_attr"><div class="cl_747902_mr_css_attr"><div><div class="gmail_quote_mr_css_attr"><div class="gmail_attr_mr_css_attr"><span data-type="sender">On Thu, Dec 29, 2022 at 9:45 AM wolverin via Libav-user <<a href="http://e.mail.ru/compose/?mailto=mailto%3alibav%2duser@ffmpeg.org" target="_blank">libav-user@ffmpeg.org</a>> wrote:</span></div><div data-type="body"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote_mr_css_attr"><div><div>I'm transcoding live video from MJPEG to H264 using ffmpeg library in my C/C++ project</div><div> </div><div>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</div><div> </div><div>int64_t * pcnt</div><div> </div><div><div><div>pPktOut->pos = (*pcnt);</div><div>pPktOut->pts = pPktOut->pos * pFmtCtxOut->streams[0]->time_base.den  / pCdcCtxOut->time_base.den;</div></div></div></div></blockquote><div> </div><div>This does not make any sense.</div><div> </div><div>Time base is rational and thus both numerator and denumerator should be used.</div></div></div></div></div></div></div></div></div></blockquote></div><div> </div><div><div><div>Thanks for your reply.</div><div>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)</div><div>Here is an example of my time base dumps</div><div> </div><div><div><div><em>Input #0, video4linux2,v4l2, from '/dev/video0':</em></div><div><em>  Duration: N/A, start: 532397.028007, bitrate: N/A</em></div><div><em>  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 30 fps, 30 tbr, 1000k tbn</em></div><div> </div></div></div><div><div><div><em>[libx264 @ 0x14ef370] using cpu capabilities: ARMv6 NEON</em></div><div><em>[libx264 @ 0x14ef370] profile High 4:2:2, level 3.1, 4:2:2 8-bit</em></div><div><em>[libx264 @ 0x14ef370] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - <a href="http://www.videolan.org/html" target="_blank">http://www.videolan.org/html</a> - 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</em></div><div><em>Output #0, rtsp, to 'rtsp://127.0.1.1:555':</em></div><div><em>  Stream #0:0: Video: h264, yuv422p(tv, bt470bg/unknown/unknown), 1280x720, q=2-31, 500 kb/s, 15 tbr, 90k tbn</em></div></div></div><div> </div><div> </div><div>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.</div><div> </div><div> </div></div></div></div></div></div></div></BODY></HTML>