C语言 ffmpeg.c 什么是 pts 和 dts ?这个代码块在 ffmpeg.c 中有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6044330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ffmpeg.c what are pts and dts ? what does this code block do in ffmpeg.c?
提问by Aditya P
- In simple terms what are pts and dts values?
- Why are they important while transcoding [decode-encode] videos ?
- 简单来说什么是 pts 和 dts 值?
- 为什么它们在转码 [解码-编码] 视频时很重要?
What does this code bit do in ffmpeg.c, what is its purpose?
这个代码位在ffmpeg.c中有什么作用,它的目的是什么?
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 }
回答by Bart
Those are the decoding time stamp (DTS) and presentation time stamp (PTS). You can find an explanation here inside a tutorial.
这些是解码时间戳 (DTS) 和演示时间戳 (PTS)。您可以在此处的教程中找到解释。
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 BGenerally the PTS and DTS will only differ when the stream we are playing has B frames in it.
假设我们有一部电影,帧显示为:IBB P。现在,我们需要知道 P 中的信息,然后才能显示 B 帧。因此,帧可能会像这样存储:IPB B。这就是为什么我们在每一帧上都有一个解码时间戳和一个呈现时间戳。解码时间戳告诉我们什么时候需要解码某些东西,而呈现时间戳告诉我们什么时候需要显示某些东西。因此,在这种情况下,我们的流可能如下所示:
PTS: 1 4 2 3 DTS: 1 2 3 4 Stream: I P B B通常,PTS 和 DTS 仅在我们正在播放的流中包含 B 帧时才会有所不同。

