Skip to content

Commit

Permalink
Tracker effect and export video fixes
Browse files Browse the repository at this point in the history
Fixed bug that made Openshot crash if two or more Tracker effects were added to the same video.
Fixed bug that made the clips to be incorrectly attached to tracked objects in the exported video.
  • Loading branch information
BrennoCaldato committed Jan 18, 2021
1 parent b08e65f commit cb61f91
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
45 changes: 26 additions & 19 deletions src/Clip.cpp
Expand Up @@ -248,19 +248,21 @@ Clip::~Clip()
void Clip::AttachToTracker(std::string tracked_id)
{
// Search for the tracked object on the timeline
Timeline *parentTimeline = (Timeline *) ParentTimeline();
Timeline* parentTimeline = (Timeline *) ParentTimeline();

// Create a smart pointer to the tracked object from the timeline
std::shared_ptr<openshot::TrackedObjectBase> trackedObject = parentTimeline->GetTrackedObject(tracked_id);

// Check for valid tracked object
if (trackedObject){
SetAttachedObject(trackedObject);
return;
}
else{
return;
// Check if the clip has a parent timeline
if (parentTimeline){

// Create a smart pointer to the tracked object from the timeline
std::shared_ptr<openshot::TrackedObjectBase> trackedObject = parentTimeline->GetTrackedObject(tracked_id);

// Check for valid tracked object
if (trackedObject){
SetAttachedObject(trackedObject);
}

}
return;
}

// Set the pointer to the trackedObject this clip is attached to
Expand Down Expand Up @@ -1138,17 +1140,22 @@ void Clip::AddEffect(EffectBase* effect)

Timeline* parentTimeline = (Timeline *) ParentTimeline();

// Downcast effect as Tracker
Tracker* tracker = (Tracker *) effect;
// Check if this clip has a parent timeline
if (parentTimeline){

// Get tracked data from the Tracker effect
std::shared_ptr<openshot::TrackedObjectBBox> trackedData = tracker->trackedData;
// Downcast effect as Tracker
Tracker* tracker = (Tracker *) effect;

// Set tracked data parent clip to this
trackedData->ParentClip(this);
// Get tracked data from the Tracker effect
std::shared_ptr<openshot::TrackedObjectBBox> trackedData = tracker->trackedData;

// Add tracked data to the timeline
parentTimeline->AddTrackedObject(trackedData);
// Set tracked data parent clip to this
trackedData->ParentClip(this);

// Add tracked data to the timeline
parentTimeline->AddTrackedObject(trackedData);

}
}

// Clear cache
Expand Down
7 changes: 7 additions & 0 deletions src/Timeline.cpp
Expand Up @@ -1071,6 +1071,13 @@ void Timeline::SetJsonValue(const Json::Value root) {
// Create Clip
Clip *c = new Clip();

// When a clip is attached to an object, it searches for the object
// on it's parent timeline. Setting the parent timeline of the clip here
// allows attaching it to an object when exporting the project (because)
// the exporter script initializes the clip and it's effects
// before setting it's parent timeline.
c->ParentTimeline(this);

// Load Json into Clip
c->SetJsonValue(existing_clip);

Expand Down
2 changes: 1 addition & 1 deletion src/TrackedObjectBBox.cpp
Expand Up @@ -475,7 +475,7 @@ std::map<std::string, float> TrackedObjectBBox::GetParentClipProperties(int64_t
// Calculate parentClip's frame number
long parentClip_start_position = round( parentClip->Position() * parentClip->info.fps.ToDouble() ) + 1;
long parentClip_start_frame = ( parentClip->Start() * parentClip->info.fps.ToDouble() ) + 1;
float parentClip_frame_number = frame_number - parentClip_start_position + parentClip_start_frame;
float parentClip_frame_number = round(frame_number - parentClip_start_position) + parentClip_start_frame;

// Get parentClip's Keyframes
float parentClip_location_x = parentClip->location_x.GetValue(parentClip_frame_number);
Expand Down
8 changes: 4 additions & 4 deletions src/TrackedObjectBBox.h
Expand Up @@ -214,10 +214,10 @@ namespace openshot
void clear();

/// Get and Set JSON methods
std::string Json() const; ///< Generate JSON string of this object
Json::Value JsonValue() const; ///< Generate Json::Value for this object
void SetJson(const std::string value); ///< Load JSON string into this object
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
std::string Json() const override; ///< Generate JSON string of this object
Json::Value JsonValue() const override; ///< Generate Json::Value for this object
void SetJson(const std::string value) override; ///< Load JSON string into this object
void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object

/// Get all properties for a specific frame (perfect for a UI to display the current state
/// of all properties at any time)
Expand Down

0 comments on commit cb61f91

Please sign in to comment.