From f2c4e4a1afa61507564fb50c5889d46b97e8c1f9 Mon Sep 17 00:00:00 2001 From: lizz Date: Thu, 16 Jul 2020 00:28:07 +0800 Subject: [PATCH] Fix a case when seek keyframe goes to eof Signed-off-by: lizz --- include/decord/runtime/ndarray.h | 2 +- src/video/video_reader.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/decord/runtime/ndarray.h b/include/decord/runtime/ndarray.h index 7dece08..1b17a98 100644 --- a/include/decord/runtime/ndarray.h +++ b/include/decord/runtime/ndarray.h @@ -35,7 +35,7 @@ namespace runtime { class NDArray { public: // pts of the frame - int pts=0; + int 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 15d2657..bee09a4 100644 --- a/src/video/video_reader.cc +++ b/src/video/video_reader.cc @@ -549,6 +549,16 @@ bool VideoReader::CheckKeyFrame() ret = decoder_->Pop(&frame); } + if (eof_ && frame.pts == -1){ + // wrongly jumpped to the end of file + curr_frame_ = GetFrameCount(); + return false; + } + + if(frame.pts == -1){ + LOG(FATAL) << "Error seeking keyframe: " << curr_frame_ << " with total frames: " << GetFrameCount(); + } + // find the real current frame after decoding auto iter = pts_frame_map_.find(frame.pts); if (iter != pts_frame_map_.end())