<div dir="ltr">Thanks a lot! I will investigate ffmpeg sources and try to use your suggestions!<div><br></div><div>Yes, I start decoding only from I-frames.</div><div><br></div><div>It looks like I had the wrong idea that AVFrame::pkt_dts matters during encoding. For now I found a practical solution to not check AVFrame timestamps. I invalidate only NO_PTS_VALUE frames.</div><div>So when I send frames to encoding, encoder produces corresponding valid dts:</div><div> processing video frame pts/dts: 3225600 3229200<br> send for encoding converted video frame pts/pkt_dts: 0 1<br> after encoding video packet pts/dts: 0 0</div><div><br> processing video frame pts/dts: 3229200 3232800<br> send for encoding converted video frame pts/pkt_dts: 1 2<br> after encoding video packet pts/dts: 1 1<br></div><div><br></div><div>But I need an ideal solution, so I will keep looking.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">пн, 4 июл. 2022 г. в 18:17, Strahinja Radman <<a href="mailto:dr.strashni@gmail.com">dr.strashni@gmail.com</a>>:<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 style="overflow-wrap: break-word;"><br><div><br><blockquote type="cite"><div>On 4. 7. 2022., at 10:52, Jake Eastwood <<a href="mailto:cheloveck2.0@gmail.com" target="_blank">cheloveck2.0@gmail.com</a>> wrote:</div><br><div><div dir="ltr">I have been coding my 'ffmpeg streaming project' for more than two years now, but still don't have full idea what changes happen with pts/dts. Every realization has edge cases when it won't work.<div><br></div><div>I do sometimes remuxing, sometimes transcoding. And 'pts' for me is very significant:</div><div>1) It represents the real time of stream working, like 2d3h35m24s. It impacts on my archive start and end boundaries. Which gives me subproblems:</div><div>1-1) packets show me that there is (start_pts_1 -> pts_end_1) working time, but frames give different numbers (start_pts_1 -> pts_end_2). So only start time matches. Maybe a few frame duration less (or more?), but maybe it will accumulate to bigger divergence.</div><div>2) I have some events happening during streaming. And I should be able to find a frame with specific 'pts' in my archive. Problems:</div><div>2-1) I have a paradox piece of code. I get pts of AVFrame and search for in the remuxing base archive, which boundaries are found on pts of source packets. But archive is not a single blob, but a bunch of small parts, so I believe there could be cases when I miss the right part.</div><div><br></div><div>For now I have a big misunderstanding which broke my logic:</div><div>I start decoding not from the start, only when I need it. I want to check decoder frames right after I get them, to be sure I can use it further at muxer. And sometimes the decoder starts to return frames with 'pts' < 'pkt_dts'. Why and what should I do with it?</div><div><div style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div style="margin-left:5px;padding-top:0px;width:1360.88px"><div style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">Example:</div></div></div></div><div style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div style="margin-left:5px;padding-top:0px;width:1360.88px"><div style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">source pts/dts: 255600/255600 decoded pts/dts 252000 255600 type: P</div><div style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">source pts/dts: 259200/259200 decoded pts/dts 255600 259200 type: P</div></div></div></div><div style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div style="margin-left:5px;padding-top:0px;width:1360.88px"><div style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">source pts/dts: 262800/262800 decoded pts/dts 259200 262800 type: P</div></div></div></div><div style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div style="margin-left:5px;padding-top:0px;width:1360.88px"><div style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">source pts/dts: 266400/266400 decoded pts/dts 262800 266400 type: P</div></div></div></div></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><br></div></div></div></blockquote></div><br><div>AVFrame doesnt have DTS information, it can only be shown at a specific time (PTS). So after decoding you dont have DTS information anymore as its not relevant. </div><div><br></div><div>Maybe it would be best if you tried FFmpeg’s way of generating timestamps. Look at the ffmpeg.c code in github. Try to use their logic in order to generate PTS and DTS info. That way you will not be battling with decoder which sometimes out of the blue returns invalid PTS/DTS information. </div><div><br></div><div>One more possible solution would be to save the last good decoded timestamps and fill in the void that decoder is giving you. This has worked for me in the past. You can calculate all of these things before the stream starts. </div><div><br></div><div>Decoder wants to decode from I frame or it wants to start from the beginning of the GOP sequence. </div><div><br></div><div>Kind regards,</div><div>Strahinja</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>