From ce3efa18184c49f4621415378a2522c404502949 Mon Sep 17 00:00:00 2001 From: shashidhar Date: Mon, 14 Feb 2022 10:50:16 +0530 Subject: [PATCH] seek fail workaround --- src/video/video_reader.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/video_reader.cc b/src/video/video_reader.cc index af4858d..b8bef31 100644 --- a/src/video/video_reader.cc +++ b/src/video/video_reader.cc @@ -309,7 +309,14 @@ bool VideoReader::Seek(int64_t pos) { // final try if all above seek fails ret = av_seek_frame(fmt_ctx_.get(), actv_stm_idx_, pos, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_FRAME); } - if (ret < 0) LOG(WARNING) << "Failed to seek file to position: " << pos; + if (ret < 0) { + // final try if all above seek fails + pos = pos + 1; + ts = FrameToPTS(pos); + ret = av_seek_frame(fmt_ctx_.get(), actv_stm_idx_, ts, AVSEEK_FLAG_BACKWARD); + LOG(WARNING) << "Seek pos:" << pos << " Seek Pts: " << ts << " Curr Frame: " << curr_frame_ << " Stream index:" << actv_stm_idx_; + } + if (ret < 0) LOG(WARNING) << "Failed to seek file to position: " << pos << " Ret val:" << ret; decoder_->Start(); if (ret >= 0) { curr_frame_ = pos;