- int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * time_base);
- av_seek_frame (_format_context, _video_stream, vt, AVSEEK_FLAG_BACKWARD);
+
+ /* If we are doing an accurate seek, our initial shot will be 5 frames (5 being
+ a number plucked from the air) earlier than we want to end up. The loop below
+ will hopefully then step through to where we want to be.
+ */
+ int initial = frame;
+ if (accurate) {
+ initial -= 5;
+ }
+
+ /* Initial seek time in the stream's timebase */
+ int64_t const initial_vt = initial / (_ffmpeg_content->video_frame_rate() * time_base);
+ /* Wanted final seek time in the stream's timebase */
+ int64_t const final_vt = frame / (_ffmpeg_content->video_frame_rate() * time_base);
+
+ av_seek_frame (_format_context, _video_stream, initial_vt, AVSEEK_FLAG_BACKWARD);