diff --git a/include/decord/runtime/ndarray.h b/include/decord/runtime/ndarray.h index 8910f82a..33adba1f 100644 --- a/include/decord/runtime/ndarray.h +++ b/include/decord/runtime/ndarray.h @@ -37,7 +37,7 @@ namespace runtime { class NDArray { public: // pts of the frame - int pts=-1; + int64_t pts=-1; // internal container type struct Container; /*! \brief default constructor */ diff --git a/src/video/video_reader.cc b/src/video/video_reader.cc index af4858d2..b6fc6b3b 100644 --- a/src/video/video_reader.cc +++ b/src/video/video_reader.cc @@ -644,10 +644,25 @@ void VideoReader::SkipFramesImpl(int64_t num) auto pts = FramesToPTS(frame_pos); decoder_->SuggestDiscardPTS(pts); + + int64_t pop_retries = 0; + const int64_t MAX_POP_RETRIES_PER_FRAME = 10000; + int64_t initial_num = num; + while (num > 0) { PushNext(); ret = decoder_->Pop(&frame); - if (!ret) continue; + if (!ret) { + pop_retries++; + if (pop_retries > MAX_POP_RETRIES_PER_FRAME) { + LOG(INFO) << "[" << filename_ << "] Failed to skip frames effectively at frame " << curr_frame_ + << ". Decoder did not respond after " << MAX_POP_RETRIES_PER_FRAME + << " attempts. Video might be corrupted or seeking failed. Aborting skip operation." + << " Attempted to skip " << initial_num << " frames, skipped " << (initial_num - num) << "."; + break; + } + continue; + } ++curr_frame_; // LOG(INFO) << "skip: " << num; --num;