<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 2, 2023 at 12:16 PM wolverin via Libav-user <<a href="mailto:libav-user@ffmpeg.org">libav-user@ffmpeg.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div><div id="m_-7615466201307963749style_16726579780851210439"><div id="m_-7615466201307963749style_16726579780851210439_BODY"><div><div><blockquote style="border-left:1px solid rgb(8,87,166);margin:10px;padding:0px 0px 0px 10px"><div id="m_-7615466201307963749"><div><div><div id="m_-7615466201307963749style_16726518520659420687_BODY_mr_css_attr"><div><div><div><div><span>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><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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://<a href="http://127.0.1.1:555" target="_blank">127.0.1.1:555</a>':</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></blockquote><div><br></div><div>You can not use 15 from video frame rate to calculate PTS when video is variable frame rate.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div id="m_-7615466201307963749style_16726579780851210439"><div id="m_-7615466201307963749style_16726579780851210439_BODY"><div><div><div><div> </div><div> </div></div></div></div></div></div></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div></div>