Why package_pts! = Frame-> pkt_pts in AVFrame?

Trying to understand some issues with audio / video sync via ffmpeg, I noticed the following. Executing this code

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);
}

      

shows that frame-> pkt_pts is generally different from packet.pts, despite the documentation claiming frame-> pkt_pts is

PTS copied from AVPacket that was decoded to create this frame

In addition, I noticed that the difference between them is great precisely in those places where the audio and video are not synchronized.

So why packet.pts != frame->pkt_pts

?

+3


source to share


1 answer


Video can have delayed frames, which means that the input frame and the output frame may refer to devices ordered differently. For example. in the case of MPEG, the display order of the IBP is encoded as IPB, and the input pulses differ from the output, and the reordering introduces a delay between input and output points. In addition, when using multi-threaded decoding, an additional delay of n_threads - 1 packet is added between input and output. In all these cases, pkt.pts! = Frame-> pkt_pts. You must rely on frame-> pkt_pts for display.



+5


source







All Articles