ffmpeg.c what are pts and dts ? what does this code block do in ffmpeg.c? ffmpeg.c what are pts and dts ? what does this code block do in ffmpeg.c? c c

ffmpeg.c what are pts and dts ? what does this code block do in ffmpeg.c?


Those are the decoding time stamp (DTS) and presentation time stamp (PTS). You can find an explanation here inside a tutorial.

So let's say we had a movie, and the frames were displayed like: I B B P. Now, we need to know the information in P before we can display either B frame. Because of this, the frames might be stored like this: I P B B. This is why we have a decoding timestamp and a presentation timestamp on each frame. The decoding timestamp tells us when we need to decode something, and the presentation time stamp tells us when we need to display something. So, in this case, our stream might look like this:

   PTS: 1 4 2 3   DTS: 1 2 3 4Stream: I P B B

Generally the PTS and DTS will only differ when the stream we are playing has B frames in it.


B frames are predicted from I and P frames. B frames usually have more errors compared to I and P and hence are not recommended for prediction, though they might be closer in time. There are algorithms in which B is used for prediction but it is from a past B frame and not future B frames.

So in a sequence of I P B1 B2, Decode order is I P B1 B2 and Display order is I B1 B2 P. P is predicted from I, B1 from both I and P, B2 again from I and P.