[Ffmpeg-devel] Seeking and keyframes

Ronald S. Bultje rbultje
Sat Jun 18 09:39:12 CEST 2005


On Sat, 2005-06-18 at 02:47, Steve Willis wrote:
> video does not have to be "played" in real-time, just stepped through
> frame by frame.
[..]
> I've been looking at the documentation for av_seek_frame(), and I see
> that it seeks to the first keyframe before the given timestamp by
> default. Is there a simple way to change this behavior so it finds the
> previous keyframe and then regenerates the forward intra-frame to
> exactly match the timestamp?

One reason is that this behaviour can easily be mimmiced based on the
current behaviour. For example, in quasi-code:

void my_seek (time)
{
  av_seek (time);
  flag_set (WAIT_FOR_TIME);
  me->last_time = time;
}

data my_get_frame ()
{
  do {
    data = av_decode_video();
  } while (flag_is_set (WAIT_FOR_TIME) &&
           data->time < me->last_time);

  return data;
}

Which you could optimize better by only decoding certain types of frames
(e.g. by using hurry_up) while seeking.

> A final (very beginner) question: why is seeking only to keyframes the 
> default? Is it very inefficient to actually generate the exact frame for 
>   a given timestamp each time a user seeks?

See above; yes. I've played with this in a player (ultimately, this is
useful for video editing purposes), and although it's not long (a few
tenth of a second at worst for normal videos with a keyframe every, say,
5 seconds), it is noticeable to the user.

Ronald

-- 
Ronald S. Bultje <rbultje at ronald.bitfreak.net>





More information about the ffmpeg-devel mailing list