[Libav-user] How to skip some useless B frames after using av_seek_frame for a video h264 encoded?

人间之表 logo at mad.moe
Sat Apr 4 13:15:54 CEST 2015


Suppose the frames are like this(in order of pts): I BBB P BBB P [B]BB P
Now I want to skip to [B] as fast as possible.
There is one I frame and two P frames required to be put into the decoder.
How to skip the 6 B frames before [B]?
What I have tried, is to check the packets to see whether they are useless. Once I find it is the packet of a B frame, I have 2 choices.
1)free the packet and go to read a packet from av_read_frame to continue the loop
2)free the packet and put it into the "avcodec_decode_video2", try to get a frame. And then , continue the loop


These two both don't work well. The target frame [B] I got is destroyed.


The way I check whether the packet is of a B frame is like this:
There is a "last_pframe" to declare the pts of the last P(or I) frame which has been put into the "avcodec_decode_video2". Get a packet, and check if packet.pts>last_pframe. If it is true, it is a packet from a new P frame. Else, it is a B frame and consider to skip it. Because a P frame is always followed by the B frames in the order of dts. For an experimental video with 25 frames, the judgement is as what I want. 


How to skip some useless B frames in the right way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150404/c7aedb17/attachment.html>


More information about the Libav-user mailing list