finalized very, very basic OTIO support

Ironed out various project and footage loading issues, and a single
cache invalidation issue.
This commit is contained in:
itsmattkc
2020-10-23 01:26:17 +11:00
parent 9613730ee8
commit bc60c74562
32 changed files with 473 additions and 301 deletions
+2 -1
View File
@@ -15,7 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if(OpenTimelineIO_FOUND)
add_subdirectory(exportotio)
add_subdirectory(loadotio)
add_subdirectory(saveotio)
endif()
add_subdirectory(import)
+6 -19
View File
@@ -83,7 +83,8 @@ void ProjectImportTask::Import(Folder *folder, QFileInfoList import, int &counte
// Strip out "." and ".." (for some reason QDir::NoDotAndDotDot doesn't work with entryInfoList, so we have to
// check manually)
for (int i=0;i<entry_list.size();i++) {
if (entry_list.at(i).fileName() == "." || entry_list.at(i).fileName() == "..") {
if (entry_list.at(i).fileName() == QStringLiteral(".")
|| entry_list.at(i).fileName() == QStringLiteral("..")) {
entry_list.removeAt(i);
i--;
}
@@ -109,26 +110,12 @@ void ProjectImportTask::Import(Folder *folder, QFileInfoList import, int &counte
} else {
QString file_path = file_info.absoluteFilePath();
// FIXME: Probe will fail if a project isn't set because ImageStream and its derivatives
// try to connect to the project's ColorManager instance
ItemPtr item = Decoder::ProbeMedia(file_path, &IsCancelled());
FootagePtr item = Decoder::ProbeMedia(model_->project(), file_info.absoluteFilePath(),
&IsCancelled());
if (item) {
// Setup metadata
item->set_name(file_info.fileName());
item->set_project(model_->project());
if (item->type() == Item::kFootage) {
FootagePtr footage = std::static_pointer_cast<Footage>(item);
footage->set_filename(file_path);
footage->set_timestamp(file_info.lastModified().toMSecsSinceEpoch());
// See if this footage is an image sequence
ValidateImageSequence(footage, import, i);
}
// See if this footage is an image sequence
ValidateImageSequence(item, import, i);
// Create undoable command that adds the items to the model
new ProjectViewModel::AddItemCommand(model_,
+2
View File
@@ -18,5 +18,7 @@ set(OLIVE_SOURCES
${OLIVE_SOURCES}
task/project/load/load.h
task/project/load/load.cpp
task/project/load/loadbasetask.h
task/project/load/loadbasetask.cpp
PARENT_SCOPE
)
+4 -5
View File
@@ -30,14 +30,13 @@
OLIVE_NAMESPACE_ENTER
ProjectLoadTask::ProjectLoadTask(const QString &filename) :
filename_(filename)
ProjectLoadBaseTask(filename)
{
SetTitle(tr("Loading '%1'").arg(filename));
}
bool ProjectLoadTask::Run()
{
QFile project_file(filename_);
QFile project_file(GetFilename());
if (project_file.open(QFile::ReadOnly | QFile::Text)) {
QXmlStreamReader reader(&project_file);
@@ -62,7 +61,7 @@ bool ProjectLoadTask::Run()
} else if (reader.name() == QStringLiteral("project")) {
project_ = std::make_shared<Project>();
project_->set_filename(filename_);
project_->set_filename(GetFilename());
project_->Load(&reader, &layout_info_, &IsCancelled());
@@ -95,7 +94,7 @@ bool ProjectLoadTask::Run()
}
} else {
SetError(tr("Failed to read file \"%1\" for reading.").arg(filename_));
SetError(tr("Failed to read file \"%1\" for reading.").arg(GetFilename()));
return false;
}
}
+2 -32
View File
@@ -21,50 +21,20 @@
#ifndef PROJECTLOADMANAGER_H
#define PROJECTLOADMANAGER_H
#include "project/project.h"
#include "task/task.h"
#include "loadbasetask.h"
#include "window/mainwindow/mainwindowlayoutinfo.h"
OLIVE_NAMESPACE_ENTER
class ProjectLoadTask : public Task
class ProjectLoadTask : public ProjectLoadBaseTask
{
Q_OBJECT
public:
ProjectLoadTask(const QString& filename);
ProjectPtr GetLoadedProject() const
{
return project_;
}
MainWindowLayoutInfo GetLoadedLayout() const
{
return layout_info_;
}
/**
* @brief Returns the filename the project was saved as, but not necessarily where it is now
*
* May help for resolving relative paths.
*/
const QString& GetFilenameProjectWasSavedAs() const
{
return project_saved_url_;
}
protected:
virtual bool Run() override;
private:
ProjectPtr project_;
MainWindowLayoutInfo layout_info_;
QString project_saved_url_;
QString filename_;
};
OLIVE_NAMESPACE_EXIT
+32
View File
@@ -0,0 +1,32 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "loadbasetask.h"
OLIVE_NAMESPACE_ENTER
ProjectLoadBaseTask::ProjectLoadBaseTask(const QString &filename) :
project_(nullptr),
filename_(filename)
{
SetTitle(tr("Loading '%1'").arg(filename));
}
OLIVE_NAMESPACE_EXIT
+74
View File
@@ -0,0 +1,74 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef PROJECTLOADBASETASK_H
#define PROJECTLOADBASETASK_H
#include "project/project.h"
#include "task/task.h"
OLIVE_NAMESPACE_ENTER
class ProjectLoadBaseTask : public Task
{
Q_OBJECT
public:
ProjectLoadBaseTask(const QString& filename);
ProjectPtr GetLoadedProject() const
{
return project_;
}
MainWindowLayoutInfo GetLoadedLayout() const
{
return layout_info_;
}
/**
* @brief Returns the filename the project was saved as, but not necessarily where it is now
*
* May help for resolving relative paths.
*/
const QString& GetFilenameProjectWasSavedAs() const
{
return project_saved_url_;
}
const QString& GetFilename() const
{
return filename_;
}
protected:
ProjectPtr project_;
MainWindowLayoutInfo layout_info_;
QString project_saved_url_;
private:
QString filename_;
};
OLIVE_NAMESPACE_EXIT
#endif // LOADBASETASK_H
@@ -16,7 +16,7 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
task/project/exportotio/exportotiotask.h
task/project/exportotio/exportotiotask.cpp
task/project/loadotio/loadotio.h
task/project/loadotio/loadotio.cpp
PARENT_SCOPE
)
+212
View File
@@ -0,0 +1,212 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "loadotio.h"
#include <opentimelineio/clip.h>
#include <opentimelineio/externalReference.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/serializableCollection.h>
#include <opentimelineio/timeline.h>
#include <QFileInfo>
#include "node/block/clip/clip.h"
#include "node/block/gap/gap.h"
#include "node/input/media/audio/audio.h"
#include "node/input/media/video/video.h"
#include "project/item/folder/folder.h"
#include "project/item/sequence/sequence.h"
#define OTIO opentimelineio::v1_0
OLIVE_NAMESPACE_ENTER
LoadOTIOTask::LoadOTIOTask(const QString& s) :
ProjectLoadBaseTask(s)
{
}
bool LoadOTIOTask::Run()
{
OTIO::ErrorStatus es;
auto root = OTIO::SerializableObjectWithMetadata::from_json_file(GetFilename().toStdString(), &es);
if (es != OTIO::ErrorStatus::OK) {
SetError(tr("Failed to load OpenTimelineIO from file \"%1\"").arg(GetFilename()));
return false;
}
project_ = std::make_shared<Project>();
project_->set_filename(GetFilename());
std::vector<OTIO::Timeline*> timelines;
if (root->schema_name() == "SerializableCollection") {
// This is a number of timelines
std::vector<OTIO::SerializableObject::Retainer<OTIO::SerializableObject>>& root_children = static_cast<OTIO::SerializableCollection*>(root)->children();
timelines.resize(root_children.size());
for (size_t j=0; j<root_children.size(); j++) {
timelines[j] = static_cast<OTIO::Timeline*>(root_children[j].value);
}
} else if (root->schema_name() == "Timeline") {
// This is a single timeline
timelines.push_back(static_cast<OTIO::Timeline*>(root));
} else {
// Unknown root, we don't know what to do with this
SetError(tr("Unknown OpenTimelineIO root element"));
return false;
}
// Keep track of imported footage
QMap<QString, FootagePtr> imported_footage;
foreach (auto timeline, timelines) {
SequencePtr sequence = std::make_shared<Sequence>();
sequence->set_name(QString::fromStdString(timeline->name()));
project_->root()->add_child(sequence);
ViewerOutput* seq_viewer = sequence->viewer_output();
// FIXME: As far as I know, OTIO doesn't store video/audio parameters?
sequence->set_default_parameters();
for (auto c : timeline->tracks()->children()) {
auto otio_track = static_cast<OTIO::Track*>(c.value);
// Create a new track
TrackOutput* track = nullptr;
// Determine what kind of track it is
if (otio_track->kind() == "Video") {
track = seq_viewer->track_list(Timeline::kTrackTypeVideo)->AddTrack();
if (seq_viewer->track_list(Timeline::kTrackTypeVideo)->GetTrackCount() == 1) {
// If this is the first track, connect it to the viewer
NodeParam::ConnectEdge(track->output(), seq_viewer->texture_input());
}
} else if (otio_track->kind() == "Audio") {
track = seq_viewer->track_list(Timeline::kTrackTypeAudio)->AddTrack();
if (seq_viewer->track_list(Timeline::kTrackTypeAudio)->GetTrackCount() == 1) {
// If this is the first track, connect it to the viewer
NodeParam::ConnectEdge(track->output(), seq_viewer->samples_input());
}
} else {
qWarning() << "Found unknown track type:" << otio_track->kind().c_str();
continue;
}
// Get clips from track
auto clip_map = otio_track->children();
if (es != OTIO::ErrorStatus::OK) {
SetError(tr("Failed to load clip"));
return false;
}
for (auto otio_block_retainer : clip_map) {
auto otio_block = otio_block_retainer.value;
Block* block = nullptr;
if (otio_block->schema_name() == "Clip") {
block = new ClipBlock();
} else if (otio_block->schema_name() == "Gap") {
block = new GapBlock();
} else {
// We don't know what this is yet, just create a gap for now so that *something* is there
qWarning() << "Found unknown block type:" << otio_block->schema_name().c_str();
block = new GapBlock();
}
block->SetLabel(QString::fromStdString(otio_block->name()));
rational start_time = rational::fromDouble(static_cast<OTIO::Item*>(otio_block)->source_range()->start_time().to_seconds());
rational duration = rational::fromDouble(static_cast<OTIO::Item*>(otio_block)->source_range()->duration().to_seconds());
block->set_media_in(start_time);
block->set_length_and_media_out(duration);
sequence->AddNode(block);
track->AppendBlock(block);
if (otio_block->schema_name() == "Clip") {
auto otio_clip = static_cast<OTIO::Clip*>(otio_block);
if (otio_clip->media_reference()->schema_name() == "ExternalReference") {
// Link footage
QString footage_url = QString::fromStdString(static_cast<OTIO::ExternalReference*>(otio_clip->media_reference())->target_url());
FootagePtr probed_item;
if (imported_footage.contains(footage_url)) {
probed_item = imported_footage.value(footage_url);
} else {
probed_item = Decoder::ProbeMedia(project_.get(), footage_url, &IsCancelled());
imported_footage.insert(footage_url, probed_item);
project_->root()->add_child(probed_item);
}
if (probed_item && probed_item->type() == Item::kFootage) {
MediaInput* media;
if (track->track_type() == Timeline::kTrackTypeVideo) {
media = new VideoInput();
media->SetFootage(probed_item->get_first_stream_of_type(Stream::kVideo));
} else {
media = new AudioInput();
media->SetFootage(probed_item->get_first_stream_of_type(Stream::kAudio));
}
sequence->AddNode(media);
NodeParam::ConnectEdge(media->output(), static_cast<ClipBlock*>(block)->texture_input());
} else {
// FIXME: Add to some kind of list that we couldn't find it
}
}
}
}
}
sequence->moveToThread(qApp->thread());
}
// Ugly hack to move footage streams to main thread
/*foreach (ItemPtr item, imported_footage) {
if (item && item->type() == Item::kFootage) {
foreach (StreamPtr stream, std::static_pointer_cast<Footage>(item)->streams()) {
stream->moveToThread(qApp->thread());
}
}
}*/
project_->moveToThread(qApp->thread());
return true;
}
OLIVE_NAMESPACE_EXIT
+42
View File
@@ -0,0 +1,42 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OTIODECODER_H
#define OTIODECODER_H
#include "project/project.h"
#include "task/project/load/loadbasetask.h"
OLIVE_NAMESPACE_ENTER
class LoadOTIOTask : public ProjectLoadBaseTask
{
Q_OBJECT
public:
LoadOTIOTask(const QString& filename);
protected:
virtual bool Run() override;
};
OLIVE_NAMESPACE_EXIT
#endif // OTIODECODER_H
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
task/project/saveotio/saveotio.h
task/project/saveotio/saveotio.cpp
PARENT_SCOPE
)
@@ -18,7 +18,7 @@
***/
#include "exportotiotask.h"
#include "saveotio.h"
#include <opentimelineio/clip.h>
#include <opentimelineio/externalReference.h>
@@ -31,14 +31,13 @@
OLIVE_NAMESPACE_ENTER
ExportOTIOTask::ExportOTIOTask(ProjectPtr project, const QString &filename) :
project_(project),
filename_(filename)
SaveOTIOTask::SaveOTIOTask(ProjectPtr project) :
project_(project)
{
SetTitle(tr("Exporting project to OpenTimelineIO"));
}
bool ExportOTIOTask::Run()
bool SaveOTIOTask::Run()
{
QList<ItemPtr> sequences = project_->get_items_of_type(Item::kSequence);
@@ -75,12 +74,12 @@ bool ExportOTIOTask::Run()
if (serialized.size() == 1) {
// Serialize timeline on its own
auto t = serialized.front();
t->to_json_file(filename_.toStdString(), &es);
t->to_json_file(project_->filename().toStdString(), &es);
t->possibly_delete();
} else {
// Serialize all into a SerializableCollection
auto collection = new opentimelineio::v1_0::SerializableCollection("Sequences", serialized);
collection->to_json_file(filename_.toStdString(), &es);
collection->to_json_file(project_->filename().toStdString(), &es);
collection->possibly_delete();
// Delete all existing timelines
@@ -92,7 +91,7 @@ bool ExportOTIOTask::Run()
return (es == opentimelineio::v1_0::ErrorStatus::OK);
}
opentimelineio::v1_0::Timeline *ExportOTIOTask::SerializeTimeline(SequencePtr sequence)
opentimelineio::v1_0::Timeline *SaveOTIOTask::SerializeTimeline(SequencePtr sequence)
{
auto otio_timeline = new opentimelineio::v1_0::Timeline(sequence->name().toStdString());
@@ -105,7 +104,7 @@ opentimelineio::v1_0::Timeline *ExportOTIOTask::SerializeTimeline(SequencePtr se
return otio_timeline;
}
opentimelineio::v1_0::Track *ExportOTIOTask::SerializeTrack(TrackOutput *track)
opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(TrackOutput *track)
{
auto otio_track = new opentimelineio::v1_0::Track();
@@ -185,7 +184,7 @@ fail:
return nullptr;
}
bool ExportOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Timeline* otio_timeline)
bool SaveOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Timeline* otio_timeline)
{
opentimelineio::v1_0::ErrorStatus es;
@@ -29,11 +29,11 @@
OLIVE_NAMESPACE_ENTER
class ExportOTIOTask : public Task
class SaveOTIOTask : public Task
{
Q_OBJECT
public:
ExportOTIOTask(ProjectPtr project, const QString& filename);
SaveOTIOTask(ProjectPtr project);
protected:
virtual bool Run() override;
@@ -47,8 +47,6 @@ private:
ProjectPtr project_;
QString filename_;
};
OLIVE_NAMESPACE_EXIT