Page MenuHome

Fix T86944: Incorrect seeking in some movies
ClosedPublic

Authored by Richard Antalik (ISS) on Mar 29 2021, 6:49 AM.

Details

Summary

av_seek_frame() failed to seek to nearest I-frame. This seems to be
a bug or not implemented feature in FFmpeg. Looks like same issue as
ticket https://trac.ffmpeg.org/ticket/1607 on ffmpeg tracker.

If seeking is done using format specific function (read_seek2)
field of AVInputFormat is set, see av_seek_frame(), use
av_seek_frame() function. Otherwise use wrapper that actively searches
for I-frame packet.

Searching is flexible and tries to do minimum amount of work. Currently
it is limited to equivalent of 25 frames, which may not be enough for
some files, but there may be files with no I-frames at all, so it is
best to keep this limit as low as possible. Previously this problem was
masked by preseek, which was hard-coded to 25 frames. This was removed
in rB88604b79b7d1.

If this approach would be unnecessary for some formats, in worst case
file would be seeked 2 times which is very fast, so there will be no
visible impact on performance.

I have split function ffmpeg_seek_and_decode, looking back I could probably kept it as is. So I can revert that change.

Diff Detail

Repository
rB Blender

Event Timeline

Richard Antalik (ISS) requested review of this revision.Mar 29 2021, 6:49 AM
Richard Antalik (ISS) edited the summary of this revision. (Show Details)Mar 29 2021, 6:54 AM

Remove refactoring changes, patch is more readable.

Richard Antalik (ISS) edited the summary of this revision. (Show Details)Mar 29 2021, 8:00 AM

I would trust you to figure out FFmpeg usage (as in, can not review this part of the logic). The code looks OK.

This revision is now accepted and ready to land.Mar 29 2021, 10:36 AM
  • Found issue with some frames still missed, but resolved it with small initial offset. Added this to comment as well. I was considering removing this seek loop completely, but when I printed resulted seek offsets, they were usually in range of 1-15 frames, which is much better than seeking full 25 frames and having to decode unnecessary frames.