[Libav-user] use AVPacket.pts with av_seek_frame()

Alexandre Millette amillett at matrox.com
Mon Jul 16 15:45:25 CEST 2012

Hi Fabio.
I can't say I have much experience with av_seek_frame(), but since no 
one else answered you, I might as well try to help.

 > Every time a read a packet I can see its position
 > in the timeframe with AVPacket.pts.
 > Now I am struggling with the seek functionality.

So you are first reading the entire video and storing the pts value for 
later use?
Because if you have the AVPacket, then you have the encoded frame. The 
only use of av_seek_frame with pts would be to go back to a packet that 
you previously read but have since lost.

 > av_seek_frame(pFormatCtx, videoStream, pts, backwardFlag)

What exactly do you mean when you say that it doesn't work? Does an 
exception occur? Does the current frame change at all?
av_seek_frame will only move the position of the file reader, meaning 
that you have to read the packet again and the decode it.

Also be careful with pts... the doc specifies that it is a timestamp in 
AVStream->time_base units, but some tutorials (like 
http://dranger.com/ffmpeg/tutorial07.html ) suggest that this timestamp 
should be multiplied by AV_TIME_BASE.

I guess a bit more code would be better if you wish for more help.

Alex M

More information about the Libav-user mailing list