[Libav-user] rewind file

Camera Man i.like.privacy.too at gmail.com
Wed Jun 18 21:45:53 CEST 2014

On 06/18/2014 03:54 PM, Slash wrote:

>  I have tried using av_seek_frame(pFormatCtx, videoStream, 0,
>  AVSEEK_FLAG_ANY) to jump back to the beginning but apparently I
>  didn't get any new decoded data so it is not doing what I need.

You need to flush the decoder context by calling 
avcodec_flush_buffers(your_codeccontext) after calling av_seek. Also, 
make sure that your stream starts with an SPS+PPS pair followed by an 
I-frame. Until you've decoded those, you can't decode any picture. If 
you seek to the beginning of a properly encoded file, they would be 
there; however, if the file is not properly encoded, you seek to the 
middle, or you are using a recorded RTSP stream, they might come later 
or not at all (in RTSP they may arrive in a side channel)

(It is AVCodecContext that references B and P frames, not AVPacket as 
someone suggested).

More information about the Libav-user mailing list