diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-12-07 02:17:34 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-12-08 20:50:53 +0100 |
| commit | 9bd8b3304f35f0b27bf18f2167302f1fd5d3f92b (patch) | |
| tree | a500ed5d7a7247d10a25fdc26f130f3382756183 /src/lib/ffmpeg_decoder.cc | |
| parent | deacb9bae6893f4d40c7b68a098b72549176df7b (diff) | |
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.
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 19 |
1 files changed, 13 insertions, 6 deletions
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. |
