ffmpeg - 为什么AVFrame中的packet.pts !=frame->pkt_pts?

标签 ffmpeg

尝试通过 ffmpeg 了解一些音频/视频同步问题,我注意到以下内容。运行此代码

while (av_read_frame(formatCtx, &packet) >= 0)
{
   if (packet.stream_index == videoStream)
   {
      avcodec_decode_video2(videoCodecCtx, frame, &got_frame, &packet);
   }

   printf("packet.pts = %d\n", packet.pts);
   printf("frame->pkt_pts", frame->pkt_pts);
}

显示frame->pkt_pts总体上与packet.pts不同,尽管文档声称frame->pkt_pts是

PTS copied from the AVPacket that was decoded to produce this frame

此外,我注意到两者之间的差异很大,正是在音频和视频不同步的地方。

那么,为什么是 packet.pts !=frame->pkt_pts

最佳答案

视频可能有延迟帧,这意味着输入帧和输出帧可能引用不同顺序的单元。例如。在MPEG的情况下,IBP的显示顺序被编码为IPB,并且输入点与输出点不同,并且重新排序在输入点和输出点之间引入延迟。此外,当使用多线程解码时,会在输入和输出之间添加 n_threads - 1 个数据包的额外延迟。在所有这些情况下,pkt.pts!=frame->pkt_pts。对于显示,您应该依赖frame->pkt_pts。

关于ffmpeg - 为什么AVFrame中的packet.pts !=frame->pkt_pts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30563911/

相关文章:

nginx - 无法让 nginx-vod-module 插件工作

android - 使用带有android native c的FFMPEG将视频转换为音频

ffmpeg - 使用 ffmpeg muxer 到 MPEG2TS ,音频流无法在 vlc 播放器中播放

android - FFmpeg 和样本类型

c - 有没有更快的方法通过跳帧来抓取帧?

Android - 在 MediaRecorder、MediaCodec 和 Ffmpeg 之间进行选择

c++ - AVFrame 到 QImage 内存泄漏

python : call ffmpeg command line with subprocess

c# - 如何从 ffmpeg 异步流式输出

ffmpeg 将转码输出的大小限制为 <104857600 字节