[Libav-user] pts/dts validation
cheloveck2.0 at gmail.com
Mon Jul 4 16:43:13 EEST 2022
Thanks a lot! I will investigate ffmpeg sources and try to use your
Yes, I start decoding only from I-frames.
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.
So when I send frames to encoding, encoder produces corresponding valid dts:
processing video frame pts/dts: 3225600 3229200
send for encoding converted video frame pts/pkt_dts: 0 1
after encoding video packet pts/dts: 0 0
processing video frame pts/dts: 3229200 3232800
send for encoding converted video frame pts/pkt_dts: 1 2
after encoding video packet pts/dts: 1 1
But I need an ideal solution, so I will keep looking.
пн, 4 июл. 2022 г. в 18:17, Strahinja Radman <dr.strashni at gmail.com>:
> On 4. 7. 2022., at 10:52, Jake Eastwood <cheloveck2.0 at gmail.com> wrote:
> 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.
> I do sometimes remuxing, sometimes transcoding. And 'pts' for me is very
> 1) It represents the real time of stream working, like 2d3h35m24s. It
> impacts on my archive start and end boundaries. Which gives me subproblems:
> 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.
> 2) I have some events happening during streaming. And I should be able to
> find a frame with specific 'pts' in my archive. Problems:
> 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.
> For now I have a big misunderstanding which broke my logic:
> 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?
> source pts/dts: 255600/255600 decoded pts/dts 252000 255600 type: P
> source pts/dts: 259200/259200 decoded pts/dts 255600 259200 type: P
> source pts/dts: 262800/262800 decoded pts/dts 259200 262800 type: P
> source pts/dts: 266400/266400 decoded pts/dts 262800 266400 type: P
> 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.
> 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.
> 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
> Decoder wants to decode from I frame or it wants to start from the
> beginning of the GOP sequence.
> Kind regards,
> Libav-user mailing list
> Libav-user at ffmpeg.org
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user