Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a case when seek keyframe goes to eof #82

Merged
merged 1 commit into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/decord/runtime/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace runtime {
class NDArray {
public:
// pts of the frame
int pts=0;
int pts=-1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will pts be checked by NextFrameImpl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, NextFrameImpl currently does not check this value. This value is checked in CheckKeyFrame to detect eof pattern.

BTW, how about using AV_NOPTS_VALUE constant as the init value of pts, instead of this -1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually fine with -1, introducing AV_NOPTS_VALUE to runtime lib will add an extra dependency in the core modules.

// internal container type
struct Container;
/*! \brief default constructor */
Expand Down
10 changes: 10 additions & 0 deletions src/video/video_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down