Andre schrieb: > Hello, > > [...] > > Obviously, the pts values are jumping around and sometimes they are actually > before the dts values, which really is no good ;) > > I think you are setting the pts values wrong. As I understood the reordering of packets AND frames is done completely by libav itself. That's why frames decoded by avcodec_decode_video() may not come from the packet you used for decoding. If the got_picture_ptr is 0 and avcodec_decode_video() did not return an error value then the frame could be successfully decoded but is only buffered because there are other frames that come before this one in presentation time.
For example if the frames are in this order in presentation time: 1 2 3 4 5 6 7 ... I B B P B B P ... av_read_frame will return them in different order because the B frames need the following P frame decoded before them: 1 4 2 3 7 5 6 ... I P B B P B B ... Now if you decode these packets in this order avcodec_decode_video() will set got_picture_ptr to 0 for the second packet (frame nr 4) because it knows that the B frames 2 and 3 come before it in presentation time. So it only buffers this frame. From now on you will have a one-frame-delay for every I and P frame. This is what happens when decoding: call decode for frame 1 => returns decoded frame 1 call decode for frame 4 => decode frame 4, but only buffers it internally call decode for frame 2 => returns decoded frame 2 call decode for frame 3 => returns decoded frame 3 call decode for frame 7 => decodes frame 7, but returns buffered frame 4 and now buffers frame 7 call decode for frame 5 => return decoded frame 5 call decode for frame 6 => return decoded frame 6 ... So if you set the frames pts to the packets one you used frame 4 will get pts of frame 7 and every following P or I frame will get wrong pts values too. I solved this by simply saving the packet's pts if got_picture_ptr is 0 and for every following frame I check if savedPTS<packetPTS. In this case I use the saved pts instead and the packet's pts will be saved then. Be aware that this is just how I understood it. I did not test much if this is really the right way to handle this but it seems to work. Hope someone can confirm this. Regards, Mario _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
