From 2172cf784ca2d7497c0abca4994b28cdb860b6ec Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Wed, 11 Nov 2020 21:53:44 +0000 Subject: [PATCH] Rational: conversion to opentime take framerate Add a frame rate option to the conversion to opentime rationals as otio generaly expects rationals to be in the form value/framerate. Also add a check to make sure the rational is not in the form 0/0 as this can cause errors with OTIO. --- app/common/rational.cpp | 6 ++++-- app/common/rational.h | 3 ++- app/task/project/saveotio/saveotio.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/common/rational.cpp b/app/common/rational.cpp index 2160e3f0e..ff44bbd89 100644 --- a/app/common/rational.cpp +++ b/app/common/rational.cpp @@ -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 diff --git a/app/common/rational.h b/app/common/rational.h index 358ea9697..8074c9b07 100644 --- a/app/common/rational.h +++ b/app/common/rational.h @@ -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 diff --git a/app/task/project/saveotio/saveotio.cpp b/app/task/project/saveotio/saveotio.cpp index 0fdb91b61..890d11dfd 100644 --- a/app/task/project/saveotio/saveotio.cpp +++ b/app/task/project/saveotio/saveotio.cpp @@ -144,8 +144,8 @@ opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(TrackOutput *track) } case Block::kGap: { - otio_block = new opentimelineio::v1_0::Gap( - opentimelineio::v1_0::TimeRange(block->in().toRationalTime(), block->length().toRationalTime()), + otio_block = new opentimelineio::v1_0::Gap(opentimelineio::v1_0::TimeRange(block->in().toRationalTime(), + block->length().toRationalTime()), block->GetLabel().toStdString() ); break;