saveotio: Make sure all tracks are the same length

This commit is contained in:
Thomas Wilshaw
2021-12-19 16:38:29 +00:00
parent e902507e47
commit b6e6b89461
2 changed files with 24 additions and 3 deletions
+23 -2
View File
@@ -116,7 +116,7 @@ OTIO::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequence)
return otio_timeline;
}
OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track, double sequence_rate)
OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track, double sequence_rate, rational max_track_length)
{
auto otio_track = new OTIO::Track();
@@ -192,6 +192,19 @@ OTIO::Track *SaveOTIOTask::SerializeTrack(Track *track, double sequence_rate)
}
}
// All OTIO tracks must have the same duration so we add a Gap to fill the remaining time
if (otio_track->duration(&es).to_seconds() < max_track_length.toDouble()) {
double time_left = max_track_length.toDouble() - otio_track->duration(&es).to_seconds();
OTIO::Gap* gap = new OTIO::Gap(OTIO::TimeRange(otio_track->duration(&es),
OTIO::RationalTime(time_left, 1.0)));
otio_track->append_child(gap, &es);
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
goto fail;
}
}
return otio_track;
fail:
@@ -204,8 +217,16 @@ bool SaveOTIOTask::SerializeTrackList(TrackList *list, OTIO::Timeline* otio_time
{
OTIO::ErrorStatus es;
rational max_track_length = RATIONAL_MIN;
foreach (Track* track, list->GetTracks()) {
auto otio_track = SerializeTrack(track, sequence_rate);
if (track->track_length() > max_track_length) {
max_track_length = track->track_length();
}
}
foreach (Track* track, list->GetTracks()) {
auto otio_track = SerializeTrack(track, sequence_rate, max_track_length);
if (!otio_track) {
return false;
+1 -1
View File
@@ -44,7 +44,7 @@ protected:
private:
OTIO::Timeline* SerializeTimeline(Sequence* sequence);
OTIO::Track* SerializeTrack(Track* track, double sequence_rate);
OTIO::Track* SerializeTrack(Track* track, double sequence_rate, rational max_track_length);
bool SerializeTrackList(TrackList* list, OTIO::Timeline *otio_timeline, double sequence_rate);