[Bf-blender-cvs] [8529458cc74] blender-v3.3-release: Fix T95683: FFmpeg seeking is broken

Richard Antalik noreply at git.blender.org
Thu Jan 12 22:26:57 CET 2023


Commit: 8529458cc74578e5944f52371f3d86edebcc7c78
Author: Richard Antalik
Date:   Wed Oct 12 20:00:20 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB8529458cc74578e5944f52371f3d86edebcc7c78

Fix T95683: FFmpeg seeking is broken

According to information I gathered, ffmpeg seeks internally using DTS
values instead of PTS. In some files DTS and PTS values are offset and
ffmpeg fails to seek correctly to keyframe located before requested PTS.

This issue become evident after hardcoded preseek of 25 frames was
removed and effort went into more precise seeking to improve
performance. It was thought, that this is bug in ffmpeg code, but
after reading some discussions, I don't think it is considered as such
by their developers, see below:
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-March/226354.html
https://trac.ffmpeg.org/ticket/1189

Best solution seems to be to add small preseek value possibly at
detriment of performance, so 3 frames of preseek are applied. Number 3
was chosen experimentally.

Performance impact seems to be insignificant with this change.

Reviewed By: zeddb

Differential Revision: https://developer.blender.org/D15847

===================================================================

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

===================================================================

diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 52ed68a1ff3..f59a96cd564 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -1094,12 +1094,14 @@ static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
 
 static int64_t ffmpeg_get_seek_pts(struct anim *anim, int64_t pts_to_search)
 {
-  /* Step back half a frame position to make sure that we get the requested
-   * frame and not the one after it. This is a workaround as ffmpeg will
-   * sometimes not seek to a frame after the requested pts even if
-   * AVSEEK_FLAG_BACKWARD is specified.
+  /* FFmpeg seeks internally using DTS values instead of PTS. In some files DTS and PTS values are
+   * offset and sometimes ffmpeg fails to take this into account when seeking.
+   * Therefore we need to seek backwards a certain offset to make sure the frame we want is in
+   * front of us. It is not possible to determine the exact needed offset, this value is determined
+   * experimentally. Note: Too big offset can impact performance. Current 3 frame offset has no
+   * measurable impact.
    */
-  return pts_to_search - (ffmpeg_steps_per_frame_get(anim) / 2);
+  return pts_to_search - (ffmpeg_steps_per_frame_get(anim) * 3);
 }
 
 /* This gives us an estimate of which pts our requested frame will have.



More information about the Bf-blender-cvs mailing list