From 9bd8b3304f35f0b27bf18f2167302f1fd5d3f92b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Dec 2025 02:17:34 +0100 Subject: Try AVSEEK_FLAG_ANY if _BACKWARD fails. We usually want to do _BACKWARD as this should seek to the keyframe before the seek position. On some files this fails, and then it seems that _ANY is a good next thing to try. --- src/lib/ffmpeg_decoder.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index ebbc242e3..c70733c4c 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -431,12 +431,19 @@ FFmpegDecoder::seek (ContentTime time, bool accurate) if (u < ContentTime ()) { u = ContentTime (); } - av_seek_frame ( - _format_context, - stream.get(), - u.seconds() / av_q2d (_format_context->streams[stream.get()]->time_base), - AVSEEK_FLAG_BACKWARD - ); + + auto seek = [&](int flag) { + return av_seek_frame( + _format_context, + stream.get(), + u.seconds() / av_q2d (_format_context->streams[stream.get()]->time_base), + flag + ); + }; + + if (seek(AVSEEK_FLAG_BACKWARD) < 0) { + DCPOMATIC_ASSERT(seek(AVSEEK_FLAG_ANY) >= 0); + }; /* Force re-creation of filter graphs to reset them, to make sure they don't have any pre-seek frames. -- cgit v1.2.3