MediaCodec 的 presentationTimeUs 有什么用?

What is the use of presentationTimeUs for MediaCodec?

queueInputBuffer (int index, int offset, int size, long presentationTimeUs, int flags)中presentationTimeUs的官方定义如下:

The presentation timestamp in microseconds for this buffer. This is normally the media time at which this buffer should be presented (rendered).

如果由应用决定何时显示解码图像,为什么解码器需要这个?我为 presentationTimeUs 尝试了一些任意数字,它们似乎对解码没有任何影响。例如,如果我将 presentationTimeUs 的原始值加倍,则视频的解码方式和速度似乎与原始视频完全相同。

有人能解释一下吗?

decoder 出于多种原因需要知道输入缓冲区的 timestamps

首先,如果流有B-frames,那么缓冲区的重新排序和分配正确的timestamps到缓冲区是由decoder。因此,当输入缓冲区收到 timestamps 时,它会排队等待重新排序。

其次,如果用例类似于Android-TV,实际上有tunneled video playbacktimestampvideo decoder 隧道 底层 HW 块进行同步和渲染。

最后,如果数据包或帧有任何丢失,如果 decoder 观察到 [=11 中的突然跳跃,它可能会执行某种隐藏=] 没有调用冲洗。这不是一个标准,而是一些解码器的高级功能。

在传统情况下,正如您所指出的,同步由播放器引擎执行,其中 decoder 应将输入缓冲区时间戳反映到输出缓冲区。