Page MenuHome

FFmpeg: Fix seeking not returning the correct frame when not using TC index
ClosedPublic

Authored by Sebastian Parborg (zeddb) on Jun 4 2021, 12:27 AM.

Details

Summary

Fixed the logic for seeking in ffmpeg video files.
The main fix is that we now apply a small offset in ffmpeg_get_seek_pos to make sure we don't get the frame in front of the seek position when seeking backward.

The rest of the changes is general cleanup and untangling code.


This incorperates the changes from: D10644
So it can be closed if this is merged.

Diff Detail

Event Timeline

Sebastian Parborg (zeddb) requested review of this revision.Jun 4 2021, 12:27 AM
Sebastian Parborg (zeddb) created this revision.

I have found issue with footage that was working before. Easy to reproduce by seeking manually frame by frame backwards when you can clearly see image will jump.
F10158179

This footage has rigid scheme IBBPBBPBBPBBPBBPBBPBBPBBPBBPBB so I don't think this is due to any variablity of file, haven't checked where in code this fails yet.

source/blender/imbuf/intern/anim_movie.c
1326–1332

To change decoding like this you have to do more changes.

Currently anim contains 2 frames

  • One is processed into ImBuf and it has PTS of anim->last_pts. This is current frame
  • One is in anim->pFrameComplete, unprocessed, but decoded. PTS corresponds to anim->next_pts

Above is condition that checks ffmpeg_pts_matches_last_frame(anim, pts_to_search) but with decoding scheme changed like this anim->last_pts and anim->next_pts should be same, but this is not changed and will result in error.

I can check by pressing Ctrl+R in VSE and it will produce issues

source/blender/imbuf/intern/anim_movie.c
1241

I am pretty sure that AVPacket->pts may not be the same as AVFrame->pts. In fact it rarely is.
Double check me on that, though.

I think, that seeking portion is fine. Not sure about change to current frame "double bufferring". If I understand it correctly, it is needed only for ffmpeg_pts_matches_last_frame to check if some frames are actually dropped from stream.
Will see if I can get file or create one myself to demonstrate the problem. We are talking edge cases here though...

source/blender/imbuf/intern/anim_movie.c
1155

Did you find necessary to increase this offset? Such change probably won't hurt too much, I am just curious.

Sebastian Parborg (zeddb) marked 2 inline comments as done.

Updated so it now should properly detect when we can reuse the current frame in memory.

Sebastian Parborg (zeddb) marked an inline comment as done.Jun 5 2021, 2:04 AM
Sebastian Parborg (zeddb) retitled this revision from Fix seeking in the the VSE when not using a proxy to FFmpeg: Fix seeking not returning the correct frame when not using TC index.Jun 5 2021, 2:14 AM
Sebastian Parborg (zeddb) edited the summary of this revision. (Show Details)
Sebastian Parborg (zeddb) edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Jun 5 2021, 2:36 AM