Skip to content
Open
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/video_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class VideoReaderInterface {

DECORD_DLL VideoReaderPtr GetVideoReader(std::string fname, DLContext ctx,
int width=-1, int height=-1, int nb_thread=0,
int io_type=kNormal);
int io_type=kNormal, std::string fault_tol="-1");

/**
* \brief Interface of VideoLoader, pure virtual class
Expand Down
21 changes: 13 additions & 8 deletions src/video/nvcodec/cuda_decoder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@ CUVideoDecoderImpl& CUVideoDecoderImpl::operator=(CUVideoDecoderImpl&& other) {

int CUVideoDecoderImpl::Initialize(CUVIDEOFORMAT* format) {
if (initialized_) {
if ((format->codec != decoder_info_.CodecType) ||
(format->coded_width != decoder_info_.ulWidth) ||
(format->coded_height != decoder_info_.ulHeight) ||
(format->chroma_format != decoder_info_.ChromaFormat)) {
std::cerr << "Encountered a dynamic video format change.\n";
return 0;
if ((format->codec == decoder_info_.CodecType) &&
(format->coded_width == decoder_info_.ulWidth) &&
(format->coded_height == decoder_info_.ulHeight) &&
(format->chroma_format == decoder_info_.ChromaFormat))
{
return 1;
}
else //When the video format changes, reinitialize the decoder and continue to decode
{
CHECK_CUDA_CALL(cuvidDestroyDecoder(decoder_));
std::cerr << "Encountered a dynamic video format change.\n";
std::cerr << "Reinitialize the decoder\n";
}
}
return 1;
}


// DLOG(INFO) << "Hardware Decoder Input Information" << std::endl
Expand Down
13 changes: 11 additions & 2 deletions src/video/video_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ int64_t VideoReader::GetFrameCount() const {
int64_t cnt = fmt_ctx_->streams[actv_stm_idx_]->nb_frames;
if (cnt < 1) {
AVStream *stm = fmt_ctx_->streams[actv_stm_idx_];
// many formats do not provide accurate frame count, use duration and FPS to approximate
cnt = static_cast<double>(stm->avg_frame_rate.num) / stm->avg_frame_rate.den * fmt_ctx_->duration / AV_TIME_BASE;
if(stm->avg_frame_rate.den == 0) //Reset the total frame count to 0
cnt = 0;
else
// many formats do not provide accurate frame count, use duration and FPS to approximate
cnt = static_cast<double>(stm->avg_frame_rate.num) / stm->avg_frame_rate.den * fmt_ctx_->duration / AV_TIME_BASE;
}
if (cnt < 1) {
cnt = 0;
LOG(FATAL) << "[" << filename_ << "] Failed to measure duration/frame-count due to broken metadata.";
}
return cnt;
Expand Down Expand Up @@ -597,10 +601,15 @@ bool VideoReader::CheckKeyFrame()
decoder_->Start();
bool ret = false;
int64_t cf = curr_frame_;
int i = 0;
while (!ret)
{
PushNext();
ret = decoder_->Pop(&frame);
i++;
if(i > 60){ // This is going to loop indefinitely when parse some corrupted video
break;
}
}

if (eof_ && frame.pts == -1){
Expand Down