On Fri, 23 Jan 2009 04:15:21 -0500, Bogdan Coanda  
<[email protected]> wrote:
> I'm currently working on a project decoding mpeg2ts streams, and my  
> problem is if can anyone explain to me why the PTS and DTS values
> seem to be inverted - each packet returned to me by avcodec_decode_video
> has the DTS in increasing order, but the PTS in every third packet is
> out of order.

This confused the heck out of me when I was first learning libav.  The key  
is to realize that the PTS of the packet you give to the decoder is NOT  
the PTS of the frame it hands back to you.  You hand the packets to it in  
DTS order, and it hands the frames to you in PTS order.

So then how can you know when to display the frame?  If you look into  
ffplay, you will see a trick where a custom frame allocation function is  
used, and the PTS of the current packet is read out of a global variable  
and attached to the '->opaque' of the frame.  Then later when the frame  
comes out of the decoder the PTS is retrieved from that pointer.  To avoid  
the global variable, you can use the ->opaque of the AVFormatContext  
(which is accessible in the allocation function).

Also: because of this lag where frames are not returned right away, at the  
end of the stream you might need to call decode a few times with an empty  
packet in order to get all the frames out.  (i.e. many people find a "bug"  
where the last frame doesn't get returned.  Its not actually a bug, just  
the way frames are passed back from the decoder.)


-- 
Michael Conrad
IntelliTree Solutions llc.
513-552-6362
[email protected]
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to