4

I'm working on implementing accurate seeking using ffmpeg and libav (using the C libraries, not the command line ffmpeg tool).

From what I understand, the only way to get accurate seeking is to seek to the nearest (earlier) keyframe, and then decode packets until the desired timestamp is reached. I've got that working using av_seek_frame and the AVSEEK_FLAG_BACKWARD flag.

Now, I know that there's no way around this, due to how video is encoded with I, P and B frames.

But what I'm looking for is a way to tell ffmpeg to skip the memory allocation and the data copy – via a flag to avcodec_receive_frame, maybe, or another function entirely. Is there a way to indicate "I don't care about the actual frame data, I just need the decoder to process this packet"?

My overarching goal is to make seeking as fast as possible, so any other suggestions along those lines would be welcome too.

Dave Ceddia
  • 1,480
  • 2
  • 17
  • 24
  • 4
    Try setting `AV_PKT_FLAG_DISCARD` on the packet. This should avoid the decoder output being relayed. However, the ffmpeg tool itself inserts a trim filter to drop frames till the seek point. – Gyan Oct 03 '21 at 07:37
  • Generally, you should avoid accurate seeking if possible and use keyframe seek for best performance. In your case, I would try to just use avcodec_send_packet without the avcodec_receive_frame. I have not try it so I'm not sure if that would work. – SuRGeoNix Oct 03 '21 at 08:26

0 Answers0