<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 4. 7. 2022., at 10:52, Jake Eastwood <<a href="mailto:cheloveck2.0@gmail.com" class="">cheloveck2.0@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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 class=""><br class=""></div><div class="">I do sometimes remuxing, sometimes transcoding. And 'pts' for me is very significant:</div><div class="">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 class="">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 class="">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 class="">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 class=""><br class=""></div><div class="">For now I have a big misunderstanding which broke my logic:</div><div class="">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 class=""><div class="gmail-kiwi-messagelist-item" style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div class="gmail-kiwi-messagelist-message--own gmail-kiwi-messagelist-message--modern gmail-kiwi-messagelist-message--authorrepeat gmail-kiwi-messagelist-message-privmsg gmail-kiwi-messagelist-message" style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div class="gmail-kiwi-messagelist-modern-right" style="margin-left:5px;padding-top:0px;width:1360.88px"><div class="gmail-kiwi-messagelist-body" style="min-height:0px;line-height:1.5em;margin:0px 0px 10px;padding:0px;white-space:pre-wrap">Example:</div></div></div></div><div class="gmail-cye-lm-tag gmail-kiwi-messagelist-item" style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div class="gmail-kiwi-messagelist-message--own gmail-kiwi-messagelist-message--modern gmail-kiwi-messagelist-message--authorrepeat gmail-kiwi-messagelist-message-privmsg gmail-cye-lm-tag gmail-kiwi-messagelist-message" style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div class="gmail-cye-lm-tag gmail-kiwi-messagelist-modern-right" style="margin-left:5px;padding-top:0px;width:1360.88px"><div class="gmail-cye-lm-tag gmail-kiwi-messagelist-body" 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 class="gmail-cye-lm-tag gmail-kiwi-messagelist-body" 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 class="gmail-kiwi-messagelist-item" style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div class="gmail-kiwi-messagelist-message--own gmail-kiwi-messagelist-message--modern gmail-kiwi-messagelist-message--authorrepeat gmail-kiwi-messagelist-message-privmsg gmail-kiwi-messagelist-message" style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div class="gmail-kiwi-messagelist-modern-right" style="margin-left:5px;padding-top:0px;width:1360.88px"><div class="gmail-kiwi-messagelist-body" 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 class="gmail-kiwi-messagelist-item" style="overflow:hidden;color:rgb(34,35,31);font-family:"Source Sans Pro",Helvetica,sans-serif"><div class="gmail-kiwi-messagelist-message--own gmail-kiwi-messagelist-message--modern gmail-kiwi-messagelist-message--authorrepeat gmail-kiwi-messagelist-message-privmsg gmail-kiwi-messagelist-message" style="padding:0px 10px;border-left:7px solid transparent;overflow:hidden;line-height:1.5em;margin:0px;border-top:none;display:flex"><div class="gmail-kiwi-messagelist-modern-right" style="margin-left:5px;padding-top:0px;width:1360.88px"><div class="gmail-kiwi-messagelist-body" 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 class=""></div></div></div></blockquote></div><br class=""><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Decoder wants to decode from I frame or it wants to start from the beginning of the GOP sequence. </div><div class=""><br class=""></div><div class="">Kind regards,</div><div class="">Strahinja</div></body></html>