From 41af336d11a8827965624c19c272e4bb6610aa62 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 2 Sep 2020 01:03:06 -0400 Subject: [PATCH] Add GetMaxTime --- include/Timeline.h | 2 ++ src/Timeline.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/Timeline.h b/include/Timeline.h index 900f05b7..a7111380 100644 --- a/include/Timeline.h +++ b/include/Timeline.h @@ -265,6 +265,8 @@ namespace openshot { /// Look up a timeline effect by ID openshot::EffectBase* GetEffect(const std::string& id); + /// Look up the end time of the latest timeline element + double GetMaxTime(); /// Look up the end frame number of the latest element on the timeline int64_t GetMaxFrame(); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 993326f7..58ccb5ad 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -299,9 +299,10 @@ openshot::EffectBase* Timeline::GetClipEffect(const std::string& id) return nullptr; } -int64_t Timeline::GetMaxFrame() { - int64_t last_clip = 1; - int64_t last_effect = 1; +// Compute the end time of the latest timeline element +double Timeline::GetMaxTime() { + double last_clip = 0.0; + double last_effect = 0.0; if (!clips.empty()) { const auto max_clip = std::max_element( @@ -316,6 +317,13 @@ int64_t Timeline::GetMaxFrame() { return std::max(last_clip, last_effect); } +// Compute the highest frame# based on the latest time and FPS +int64_t Timeline::GetMaxFrame() { + double fps = info.fps.ToDouble(); + auto max_time = GetMaxTime(); + return std::round(max_time * fps) + 1; +} + // Apply a FrameMapper to a clip which matches the settings of this timeline void Timeline::apply_mapper_to_clip(Clip* clip) {