Merge branch 'otio_improvments' of https://github.com/ThomasWilshaw/olive into ThomasWilshaw-otio_improvments
This commit is contained in:
@@ -38,6 +38,7 @@ set(OLIVE_SOURCES
|
||||
common/functiontimer.h
|
||||
common/lerp.h
|
||||
common/memorypool.cpp
|
||||
common/otioutils.h
|
||||
common/memorypool.h
|
||||
common/ocioutils.cpp
|
||||
common/ocioutils.h
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/***
|
||||
|
||||
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 OTIOUTILS_H
|
||||
#define OTIOUTILS_H
|
||||
|
||||
#ifdef USE_OTIO
|
||||
#include <opentimelineio/version.h>
|
||||
namespace OTIO = opentimelineio::OPENTIMELINEIO_VERSION;
|
||||
#endif
|
||||
|
||||
#endif // OTIOUTILS
|
||||
@@ -103,10 +103,12 @@ AVRational rational::toAVRational() const
|
||||
}
|
||||
|
||||
#ifdef USE_OTIO
|
||||
opentime::RationalTime rational::toRationalTime() const
|
||||
opentime::RationalTime rational::toRationalTime(double framerate) const
|
||||
{
|
||||
// Is this the best way of doing this?
|
||||
return opentime::RationalTime::from_seconds(toDouble());
|
||||
// Olive can store rationals as 0/0 which causes errors in OTIO
|
||||
opentime::RationalTime time = opentime::RationalTime(numer_, denom_ == 0 ? 1 : denom_);
|
||||
return time.rescaled_to(framerate);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ public:
|
||||
AVRational toAVRational() const;
|
||||
|
||||
#ifdef USE_OTIO
|
||||
opentime::RationalTime toRationalTime() const;
|
||||
// Convert Olive ratioanls to opentime rationals with the given framerate (defaults to 24)
|
||||
opentime::RationalTime toRationalTime(double framerate = 24) const;
|
||||
#endif
|
||||
|
||||
// Produce "flipped" version
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
#include "node/project/sequence/sequence.h"
|
||||
#include "widget/timelinewidget/timelineundo.h"
|
||||
|
||||
#define OTIO opentimelineio::v1_0
|
||||
|
||||
namespace olive {
|
||||
|
||||
LoadOTIOTask::LoadOTIOTask(const QString& s) :
|
||||
@@ -243,4 +241,4 @@ bool LoadOTIOTask::Run()
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // USE_OTIO
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#ifdef USE_OTIO
|
||||
|
||||
#include "common/otioutils.h"
|
||||
#include "node/project/project.h"
|
||||
#include "task/project/load/loadbasetask.h"
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <opentimelineio/externalReference.h>
|
||||
#include <opentimelineio/gap.h>
|
||||
#include <opentimelineio/serializableCollection.h>
|
||||
#include <opentimelineio/serializableObject.h>
|
||||
#include <opentimelineio/transition.h>
|
||||
|
||||
#include "node/block/transition/transition.h"
|
||||
@@ -48,7 +49,7 @@ bool SaveOTIOTask::Run()
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<opentimelineio::v1_0::SerializableObject*> serialized;
|
||||
std::vector<OTIO::SerializableObject*> serialized;
|
||||
|
||||
foreach (Sequence* seq, sequences) {
|
||||
auto otio_timeline = SerializeTimeline(seq);
|
||||
@@ -69,7 +70,7 @@ bool SaveOTIOTask::Run()
|
||||
}
|
||||
}
|
||||
|
||||
opentimelineio::v1_0::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
if (serialized.size() == 1) {
|
||||
// Serialize timeline on its own
|
||||
@@ -78,7 +79,7 @@ bool SaveOTIOTask::Run()
|
||||
t->possibly_delete();
|
||||
} else {
|
||||
// Serialize all into a SerializableCollection
|
||||
auto collection = new opentimelineio::v1_0::SerializableCollection("Sequences", serialized);
|
||||
auto collection = new OTIO::SerializableCollection("Sequences", serialized);
|
||||
collection->to_json_file(project_->filename().toStdString(), &es);
|
||||
collection->possibly_delete();
|
||||
|
||||
@@ -88,12 +89,16 @@ bool SaveOTIOTask::Run()
|
||||
}
|
||||
}
|
||||
|
||||
return (es == opentimelineio::v1_0::ErrorStatus::OK);
|
||||
return (es == OTIO::ErrorStatus::OK);
|
||||
}
|
||||
|
||||
opentimelineio::v1_0::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequence)
|
||||
OTIO::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequence)
|
||||
{
|
||||
auto otio_timeline = new opentimelineio::v1_0::Timeline(sequence->GetLabel().toStdString());
|
||||
auto otio_timeline = new OTIO::Timeline(sequence->GetLabel().toStdString());
|
||||
// Retainers clean themselves up when the final user is removed
|
||||
OTIO::Timeline::Retainer<OTIO::Timeline>* timeline_retainer = new OTIO::Timeline::Retainer<OTIO::Timeline>(otio_timeline);
|
||||
// Suppress unused variable warning
|
||||
Q_UNUSED(timeline_retainer);
|
||||
|
||||
if (!SerializeTrackList(sequence->track_list(Track::kVideo), otio_timeline)
|
||||
|| !SerializeTrackList(sequence->track_list(Track::kAudio), otio_timeline)) {
|
||||
@@ -104,11 +109,11 @@ opentimelineio::v1_0::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequen
|
||||
return otio_timeline;
|
||||
}
|
||||
|
||||
opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
{
|
||||
auto otio_track = new opentimelineio::v1_0::Track();
|
||||
auto otio_track = new OTIO::Track();
|
||||
|
||||
opentimelineio::v1_0::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
switch (track->type()) {
|
||||
case Track::kVideo:
|
||||
@@ -123,19 +128,19 @@ opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
}
|
||||
|
||||
foreach (Block* block, track->Blocks()) {
|
||||
opentimelineio::v1_0::Composable* otio_block = nullptr;
|
||||
OTIO::Composable* otio_block = nullptr;
|
||||
|
||||
switch (block->type()) {
|
||||
case Block::kClip:
|
||||
{
|
||||
auto otio_clip = new opentimelineio::v1_0::Clip(block->GetLabel().toStdString());
|
||||
auto otio_clip = new OTIO::Clip(block->GetLabel().toStdString());
|
||||
|
||||
otio_clip->set_source_range(opentimelineio::v1_0::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()));
|
||||
otio_clip->set_source_range(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()));
|
||||
|
||||
QVector<Footage*> media_nodes = block->FindInputNodes<Footage>();
|
||||
if (!media_nodes.isEmpty()) {
|
||||
auto media_ref = new opentimelineio::v1_0::ExternalReference(media_nodes.first()->filename().toStdString());
|
||||
auto media_ref = new OTIO::ExternalReference(media_nodes.first()->filename().toStdString());
|
||||
otio_clip->set_media_reference(media_ref);
|
||||
}
|
||||
|
||||
@@ -144,22 +149,22 @@ opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
}
|
||||
case Block::kGap:
|
||||
{
|
||||
otio_block = new opentimelineio::v1_0::Gap(
|
||||
opentimelineio::v1_0::TimeRange(block->in().toRationalTime(), block->length().toRationalTime()),
|
||||
block->GetLabel().toStdString()
|
||||
);
|
||||
otio_block = new OTIO::Gap(OTIO::TimeRange(block->in().toRationalTime(),
|
||||
block->length().toRationalTime()),
|
||||
block->GetLabel().toStdString()
|
||||
);
|
||||
break;
|
||||
}
|
||||
case Block::kTransition:
|
||||
{
|
||||
auto otio_transition = new opentimelineio::v1_0::Transition(block->GetLabel().toStdString());
|
||||
auto otio_transition = new OTIO::Transition(block->GetLabel().toStdString());
|
||||
|
||||
TransitionBlock* our_transition = static_cast<TransitionBlock*>(block);
|
||||
|
||||
otio_transition->set_in_offset(our_transition->in_offset().toRationalTime());
|
||||
otio_transition->set_out_offset(our_transition->out_offset().toRationalTime());
|
||||
|
||||
otio_block = new opentimelineio::v1_0::Transition();
|
||||
otio_block = new OTIO::Transition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +176,7 @@ opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(Track *track)
|
||||
|
||||
otio_track->append_child(otio_block, &es);
|
||||
|
||||
if (es != opentimelineio::v1_0::ErrorStatus::OK) {
|
||||
if (es != OTIO::ErrorStatus::OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -184,9 +189,9 @@ fail:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SaveOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Timeline* otio_timeline)
|
||||
bool SaveOTIOTask::SerializeTrackList(TrackList *list, OTIO::Timeline* otio_timeline)
|
||||
{
|
||||
opentimelineio::v1_0::ErrorStatus es;
|
||||
OTIO::ErrorStatus es;
|
||||
|
||||
foreach (Track* track, list->GetTracks()) {
|
||||
auto otio_track = SerializeTrack(track);
|
||||
@@ -197,7 +202,7 @@ bool SaveOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Tim
|
||||
|
||||
otio_timeline->tracks()->append_child(otio_track, &es);
|
||||
|
||||
if (es != opentimelineio::v1_0::ErrorStatus::OK) {
|
||||
if (es != OTIO::ErrorStatus::OK) {
|
||||
otio_track->possibly_delete();
|
||||
return false;
|
||||
}
|
||||
@@ -208,4 +213,4 @@ bool SaveOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Tim
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // USE_OTIO
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <opentimelineio/timeline.h>
|
||||
#include <opentimelineio/track.h>
|
||||
|
||||
#include "common/otioutils.h"
|
||||
#include "node/project/project.h"
|
||||
#include "task/task.h"
|
||||
|
||||
@@ -41,11 +42,11 @@ protected:
|
||||
virtual bool Run() override;
|
||||
|
||||
private:
|
||||
opentimelineio::v1_0::Timeline* SerializeTimeline(Sequence* sequence);
|
||||
OTIO::Timeline* SerializeTimeline(Sequence* sequence);
|
||||
|
||||
opentimelineio::v1_0::Track* SerializeTrack(Track* track);
|
||||
OTIO::Track* SerializeTrack(Track* track);
|
||||
|
||||
bool SerializeTrackList(TrackList* list, opentimelineio::v1_0::Timeline *otio_timeline);
|
||||
bool SerializeTrackList(TrackList* list, OTIO::Timeline *otio_timeline);
|
||||
|
||||
Project* project_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user