[Libav-user] understanding AVPackets and AVFrames

Alina lifshits alina at vicon.co.il
Wed Dec 10 09:50:17 CET 2014

I am decoding h264 live stream (I-Frames & P-Frames only) and the FF_THREAD_FRAME flag is turned off to keep small latency.
In my app I need to know exactly when an AVPacket is decoded and produces an AVFrame. To do so I am using the AVFrame.pkt_pts and AVFrame.pkt_dts fields to find the AVPacket this frame was produced of. Most of the time everything works as expected. Each AVPacket input produces AVFrame output and the fields are matching. But I do have a stream when the behavior is different:
The first frame: AVPacket1  à  AVFrame1 and all is OK. The resulting AVFrame1.ptk_pts == AVPacket1.pts and AVFrame1.ptk_dts == AVPacket1.dts and the produced frame is an I_FRAME.
The second frame: AVPacket2  à  AVFrame2. The resulting AVFrame2.pkt_dts == AVPacket2.dts BUT AVFrame2.pkt_pts != AVPacket2.pts, instead AVFrame2.pkt_pts == AVPacket1.pts!!!! and the produced frame is again an I_FRAME.  The is unexpected, the second frame should be a P-FRAME (according to the h264 stream) and now I cannot tell for sure that the second AVFrame2 was produced from AVPacker2. Was it? Or the decoder returns twice the same frame?
My main questions is if using the pkt_pts & pkt_dts is the right solution for me? Is there a most reliable way to do it?
Many thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141210/71783503/attachment.html>

More information about the Libav-user mailing list