From fc68a123baa977db0b6bf75cdb8eb39e40b3fef4 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 28 May 2022 12:25:50 -0700 Subject: [PATCH] project: reprobe and merge params when file changes are found --- app/codec/ffmpeg/ffmpegdecoder.cpp | 1 - app/node/node.h | 2 + app/node/output/viewer/viewer.cpp | 12 +- app/node/output/viewer/viewer.h | 1 + app/node/project/footage/footage.cpp | 161 ++++++++++++------ app/node/project/footage/footage.h | 6 + .../project/serializer/serializer210528.cpp | 2 + .../project/serializer/serializer210907.cpp | 2 + .../project/serializer/serializer211228.cpp | 2 + .../project/serializer/serializer220403.cpp | 2 + 10 files changed, 133 insertions(+), 58 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index d191efde6..29af60cd6 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -271,7 +271,6 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, const QAtomicIn frame); compatible_pix_fmt = FFmpegUtils::GetCompatiblePixelFormat(static_cast(avstream->codecpar->format)); - qDebug() << "GOT IT FROM FRAME" << compatible_pix_fmt; } // Read second frame diff --git a/app/node/node.h b/app/node/node.h index d123c0e72..f43a4afcc 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -982,6 +982,8 @@ public: InputFlags GetInputFlags(const QString& input) const; void SetInputFlags(const QString &input, const InputFlags &f); + virtual void LoadFinishedEvent(){} + static void SetValueAtTime(const NodeInput &input, const rational &time, const QVariant &value, int track, MultiUndoCommand *command, bool insert_on_all_tracks_if_no_key); static std::list FindPath(Node *from, Node *to, int path_index = 0); diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index 34103e887..50caee988 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -485,6 +485,11 @@ void ViewerOutput::set_parameters_from_footage(const QVector foo } int ViewerOutput::AddStream(Track::Type type, const QVariant& value) +{ + return SetStream(type, value, -1); +} + +int ViewerOutput::SetStream(Track::Type type, const QVariant &value, int index_in) { QString id; @@ -499,8 +504,11 @@ int ViewerOutput::AddStream(Track::Type type, const QVariant& value) } // Add another video/audio param to the array for this stream - int index = InputArraySize(id); - InputArrayAppend(id); + int index = (index_in == -1) ? InputArraySize(id) : index_in; + + if (index >= InputArraySize(id)) { + InputArrayResize(id, index+1); + } SetStandardValue(id, value, index); diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index b0ba3ec8c..c68225df8 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -201,6 +201,7 @@ protected: virtual void InputValueChangedEvent(const QString& input, int element) override; int AddStream(Track::Type type, const QVariant &value); + int SetStream(Track::Type type, const QVariant &value, int index); private: rational last_length_; diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index 2feda5725..4a5e5f0a5 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -43,6 +43,8 @@ const QString Footage::kLoopModeInput = QStringLiteral("loop_in"); Footage::Footage(const QString &filename) : ViewerOutput(false, false), + timestamp_(0), + valid_(false), cancelled_(nullptr) { SetCacheTextures(true); @@ -53,7 +55,9 @@ Footage::Footage(const QString &filename) : Clear(); - set_filename(filename); + if (!filename.isEmpty()) { + set_filename(filename); + } QTimer *check_timer = new QTimer(this); check_timer->setInterval(5000); @@ -76,59 +80,7 @@ void Footage::InputValueChangedEvent(const QString &input, int element) // Reset internal stream cache Clear(); - // Determine if file still exists - QFileInfo info(filename()); - - if (info.exists()) { - // Grab timestamp - set_timestamp(info.lastModified().toMSecsSinceEpoch()); - - // Determine if we've already cached the metadata of this file - QString meta_cache_file = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).filePath(FileFunctions::GetUniqueFileIdentifier(filename())); - - FootageDescription footage_info; - - // Try to load footage info from cache - if (!QFileInfo::exists(meta_cache_file) || !footage_info.Load(meta_cache_file)) { - - // Probe and create cache - QVector decoder_list = Decoder::ReceiveListOfAllDecoders(); - - foreach (DecoderPtr decoder, decoder_list) { - footage_info = decoder->Probe(filename(), cancelled_); - - if (footage_info.IsValid()) { - break; - } - } - - if (!footage_info.Save(meta_cache_file)) { - qWarning() << "Failed to save stream cache, footage will have to be re-probed"; - } - - } - - if (footage_info.IsValid()) { - decoder_ = footage_info.decoder(); - - for (int i=0; ifilename(); + + // In case of failure to load file, set timestamp to a value that will always be invalid so we + // continuously reprobe + set_timestamp(0); + + if (!filename.isEmpty()) { + QFileInfo info(filename); + + if (info.exists()) { + // Grab timestamp + set_timestamp(info.lastModified().toMSecsSinceEpoch()); + + // Determine if we've already cached the metadata of this file + QString meta_cache_file = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).filePath(FileFunctions::GetUniqueFileIdentifier(filename)); + + FootageDescription footage_info; + + // Try to load footage info from cache + if (!QFileInfo::exists(meta_cache_file) || !footage_info.Load(meta_cache_file)) { + + // Probe and create cache + QVector decoder_list = Decoder::ReceiveListOfAllDecoders(); + + foreach (DecoderPtr decoder, decoder_list) { + footage_info = decoder->Probe(filename, cancelled_); + + if (footage_info.IsValid()) { + break; + } + } + + if (!footage_info.Save(meta_cache_file)) { + qWarning() << "Failed to save stream cache, footage will have to be re-probed"; + } + + } + + if (footage_info.IsValid()) { + decoder_ = footage_info.decoder(); + + InputArrayResize(kVideoParamsInput, footage_info.GetVideoStreams().size()); + for (int i=0; iGetVideoParams(i); + if (existing.is_valid()) { + video_stream = MergeVideoStream(video_stream, existing); + } + } + + SetStream(Track::kVideo, QVariant::fromValue(video_stream), i); + } + + InputArrayResize(kAudioParamsInput, footage_info.GetAudioStreams().size()); + for (int i=0; iskipCurrentElement(); } } + + node->LoadFinishedEvent(); } void ProjectSerializer210528::LoadInput(Node *node, QXmlStreamReader *reader, XMLNodeData &xml_node_data) const diff --git a/app/node/project/serializer/serializer210907.cpp b/app/node/project/serializer/serializer210907.cpp index 0ab48339b..edcb86ae3 100644 --- a/app/node/project/serializer/serializer210907.cpp +++ b/app/node/project/serializer/serializer210907.cpp @@ -240,6 +240,8 @@ void ProjectSerializer210907::LoadNode(Node *node, XMLNodeData &xml_node_data, Q reader->skipCurrentElement(); } } + + node->LoadFinishedEvent(); } void ProjectSerializer210907::LoadInput(Node *node, QXmlStreamReader *reader, XMLNodeData &xml_node_data) const diff --git a/app/node/project/serializer/serializer211228.cpp b/app/node/project/serializer/serializer211228.cpp index cbd8cf57f..41254b105 100644 --- a/app/node/project/serializer/serializer211228.cpp +++ b/app/node/project/serializer/serializer211228.cpp @@ -290,6 +290,8 @@ void ProjectSerializer211228::LoadNode(Node *node, XMLNodeData &xml_node_data, Q reader->skipCurrentElement(); } } + + node->LoadFinishedEvent(); } void ProjectSerializer211228::LoadInput(Node *node, QXmlStreamReader *reader, XMLNodeData &xml_node_data) const diff --git a/app/node/project/serializer/serializer220403.cpp b/app/node/project/serializer/serializer220403.cpp index 5a0a39822..2075b6ce8 100644 --- a/app/node/project/serializer/serializer220403.cpp +++ b/app/node/project/serializer/serializer220403.cpp @@ -548,6 +548,8 @@ void ProjectSerializer220403::LoadNode(Node *node, XMLNodeData &xml_node_data, Q reader->skipCurrentElement(); } } + + node->LoadFinishedEvent(); } void ProjectSerializer220403::SaveNode(Node *node, QXmlStreamWriter *writer) const