From 5bcb42648895f4dee7b1fe836de7372b484d4b83 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 19 Nov 2022 17:36:16 -0800 Subject: [PATCH] ffmpeg: ensure duration detection responds to cancel action --- app/codec/ffmpeg/ffmpegdecoder.cpp | 7 +++++-- app/node/project/footage/footage.cpp | 6 ++++-- app/task/project/import/import.cpp | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 4981f1119..5e2bdddbe 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -315,6 +315,9 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, CancelAtom *can int64_t footage_duration = fmt_ctx->duration; bool duration_guessed_from_bitrate = (fmt_ctx->duration_estimation_method == AVFMT_DURATION_FROM_BITRATE); + if (duration_guessed_from_bitrate) { + qWarning() << "Unreliable duration detected - we will manually determine it ourselves (this may take some time)"; + } // Dump it into the Footage object for (unsigned int i=0;inb_streams;i++) { @@ -383,7 +386,7 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, CancelAtom *can do { new_dur = frame->best_effort_timestamp; - } while (instance.GetFrame(pkt, frame) >= 0); + } while (instance.GetFrame(pkt, frame) >= 0 && (!cancelled || !cancelled->IsCancelled())); avstream->duration = new_dur; @@ -447,7 +450,7 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, CancelAtom *can do { new_dur = frame->best_effort_timestamp; - } while (instance.GetFrame(pkt, frame) >= 0); + } while (instance.GetFrame(pkt, frame) >= 0 && (!cancelled || !cancelled->IsCancelled())); avstream->duration = new_dur; diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index 96428f345..f99ea8bc5 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -474,8 +474,10 @@ void Footage::Reprobe() } } - if (!footage_info.Save(meta_cache_file)) { - qWarning() << "Failed to save stream cache, footage will have to be re-probed"; + if (!cancelled_ || !cancelled_->HeardCancel()) { + if (!footage_info.Save(meta_cache_file)) { + qWarning() << "Failed to save stream cache, footage will have to be re-probed"; + } } } diff --git a/app/task/project/import/import.cpp b/app/task/project/import/import.cpp index b13be24fb..91572757b 100644 --- a/app/task/project/import/import.cpp +++ b/app/task/project/import/import.cpp @@ -106,10 +106,15 @@ void ProjectImportTask::Import(Folder *folder, QFileInfoList import, int &counte } else { - Footage* footage = new Footage(file_info.absoluteFilePath()); + Footage* footage = new Footage(); + footage->SetCancelPointer(this->GetCancelAtom()); + + footage->set_filename(file_info.absoluteFilePath()); footage->SetLabel(file_info.fileName()); + footage->SetCancelPointer(nullptr); + if (footage->IsValid()) { // See if this footage is an image sequence ValidateImageSequence(footage, import, i);