Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

ffmpeg

  • In simple terms what are pts and dts values?
  • Why are they important while transcoding [decode-encode] videos ?

What does this code bit do in ffmpeg.c , what is its purpose?

01562    ist->next_pts = ist->pts = picture.best_effort_timestamp; 01563    if (ist->st->codec->time_base.num != 0) { 01564        int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; 01565        ist->next_pts += ((int64_t)AV_TIME_BASE * 01566                         ist->st->codec->time_base.num * ticks) / 01567                         ist->st->codec->time_base.den; 01568    } 
like image 217
Aditya P Avatar asked May 18 '11 12:05

Aditya P


People also ask

What is dts and pts?

The DTS decides when a frame has to be decoded, while the PTS describes when a frame has to be presented. This difference becomes important when using B-frames, which are frames that can have references to frames in the past, but also to frames in the future.

What is Ffmpeg DTS?

The PTS (Presentation Time Stamp) or DTS (Decode Time Stamp) is the time stamp of the packet being received and these will be different for each packet in the stream so will not be a fixed value.


1 Answers

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 4 Stream: I P B B 

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

like image 144
Bart Avatar answered Sep 20 '22 04:09

Bart