<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.17063" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff><FONT face=Arial size=2>
<DIV>>>2013/12/4 Don Moir <<A
href="mailto:donmoir@comcast.net">donmoir@comcast.net</A>></DIV>
<DIV> </DIV>
<DIV>>>>----- Original Message ----- <BR>>>>From: YIRAN LI
<BR>>>>To: This list is about using libavcodec, libavformat,
libavutil,libavdevice and libavfilter. <BR>>>>Sent: Sunday, December
08, 2013 9:44 PM<BR>>>>Subject: [Libav-user] a question for
av_seek_frame</DIV>
<DIV> </DIV>
<DIV>>>>Hi friends</DIV>
<DIV> </DIV>
<DIV>>>>Here I have a question about av_seek_frame.</DIV>
<DIV> </DIV>
<DIV>>>>For example if I have a video stream of time stamps 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10. and only frame at 0 is a key frame.</DIV>
<DIV> </DIV>
<DIV>>>>if I call av_seek_frame(x,x,5, AVSEEK_FLAG_BACKWARD |
AVSEEK_FLAG_ANY) and then av_read_frame, the first frame I get will be frame 6,
is this correct?</DIV>
<DIV> </DIV>
<DIV>>>>then if I call av_seek_frame(x, x, 5, AVSEEK_FLAG_BACKWARD) and
then av_read_frame, then the first frame I get will be frame 1, is this
correct?</DIV>
<DIV> </DIV>
<DIV>>>>and if both can seek to a frame and first one can get a frame
quicker, in what circumstance should I use the second one?</DIV>
<DIV> </DIV>
<DIV>>>>Thanks</DIV>
<DIV> </DIV>
<DIV>>>Non key frames require the previous key frame in order to be
decoded correctly. So if you skip past the key frame to frame 6, then the
decoded image will most likely be incorrect.</DIV>
<DIV> </DIV>
<DIV>>>While your first example may be quicker, it will not be correct.
Best to stay away from AVSEEK_FLAG_ANY for normal display purposes. Proper
seeking to frame 6 would require a seek to frame 1 and then read and decode to
frame 6. AVSEEK_FLAG_ANY can be useful in some cases but generally not for
normal display.</DIV>
<DIV> </DIV>
<DIV>>So in order to get a correct image, I must not use AVSEEK_FLAG_ANY so
that av_seek_frame by default will seek to a key frame. And I should continue to
read from that point and decode until I get a frame with the timestamp I want.
</DIV>
<DIV> </DIV>
<DIV>Right and this takes some care.</DIV>
<DIV> </DIV>
<DIV>>Do you know if all demuxers can support av_seek_frame() correctly so
that as long as there's a key frame before the position I pass to the function,
they all can correctly seek to that key frame?</DIV>
<DIV> </DIV>
<DIV>Pretty much. You might have a problem with some mpeg files not seeking to
key frame but otherwise works pretty well. You need to be careful about audio
being in sync after a seek for some files as well.</DIV>
<DIV><BR></FONT> </DIV></BODY></HTML>