Add GetMaxTime

This commit is contained in:
FeRD (Frank Dana)
2020-09-02 01:03:06 -04:00
parent f49a795749
commit 41af336d11
2 changed files with 13 additions and 3 deletions

View File

@@ -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();

View File

@@ -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)
{