[Libav-user] How to seek to a given frame?

Mark McKay mark at kitfox.com
Wed May 8 20:52:53 EEST 2019


I'm trying to create a video player with the ability to seek whereever
I want. I'm having some trouble with av_seek_frame(), which seems to
keep returning the first keyframe after the timestamp I'm looking for:


int timestamp = av_rescale_q(timeMs, AV_TIME_BASE_Q, 


pFormatCtx->streams[videoStream]->time_base);
  int err =
av_seek_frame(pFormatCtx, videoStream, timestamp, 0);

Unfortunately, if
it puts me at a position /after/ the frame where I'm seeking, I have
already passed the frame I want and can't scan forward to find it. I've
also tried seeking with AVSEEK_FLAG_ANY, but this it not returning
frames with valid data. I'm guessing that you need to jump to the
correct keyframe and then scan forward so that the frame buffers are
built correctly.

I'm also considering scanning the entire video when I
first load it to build an index of packet information. AVSEEK_FLAG_BYTE
looks like it could be useful to jump directly to the packet I want -
however, I don't know where to find the byte value I would need to pass
to the seek function.

How can I scan to the frame that I
want?

Cheers,
Mark

---
http://www.kitfox.com
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190508/5444ae05/attachment.html>


More information about the Libav-user mailing list