Skip to content

Commit

Permalink
Solved FPS bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Nov 13, 2020
1 parent 34aabcc commit 940840c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
31 changes: 16 additions & 15 deletions src/KeyFrameBBox.cpp
Expand Up @@ -279,19 +279,19 @@ void KeyFrameBBox::RemoveScale(int64_t frame_number) {

BBox KeyFrameBBox::GetValue(int64_t frame_number){
double time = this->FrameNToTime(frame_number, this->TimeScale);

auto it = BoxVec.lower_bound(time);

if (it == BoxVec.end()){
BBox resp;
return resp;
}

if (it->first == time){
if ((it->first == time) || (it == BoxVec.begin())){
BBox res = it->second;
res.cx += this->delta_x.GetValue(time);
res.cy += this->delta_y.GetValue(time);
res.height += this->scale_y.GetValue(time);
res.width += this->scale_x.GetValue(time);
res.cx += this->delta_x.GetValue(it->first);
res.cy += this->delta_y.GetValue(it->first);
res.height += this->scale_y.GetValue(it->first);
res.width += this->scale_x.GetValue(it->first);

return res;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ BBox KeyFrameBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right,
Point p2_right(t2, right.cy, openshot::InterpolationType::LINEAR);

Point p2 = InterpolateBetween(p2_left, p2_right, target, 0.01);

Point p3_left(t1, left.height, openshot::InterpolationType::LINEAR);
Point p3_right(t2, right.height, openshot::InterpolationType::LINEAR);

Expand All @@ -334,8 +334,8 @@ BBox KeyFrameBBox::InterpolateBoxes(double t1, double t2, BBox left, BBox right,
Point p4_right(t2, right.width, openshot::InterpolationType::LINEAR);

Point p4 = InterpolateBetween(p4_left, p4_right, target, 0.01);

BBox ans(p1.co.Y, p2.co.Y, p3.co.Y, p4.co.Y);
BBox ans(p1.co.Y, p2.co.Y, p4.co.Y, p3.co.Y);

return ans;
}
Expand All @@ -351,7 +351,7 @@ Fraction KeyFrameBBox::GetBaseFPS(){
}

double KeyFrameBBox::FrameNToTime(int64_t frame_number, double time_scale){
double time = ((double) frame_number) * this->BaseFps.Reciprocal().ToDouble() * time_scale;
double time = ((double) frame_number) * this->BaseFps.Reciprocal().ToDouble() * (1.0 / time_scale);

return time;
}
Expand Down Expand Up @@ -381,13 +381,13 @@ Json::Value KeyFrameBBox::JsonValue() {
root["boxes"] = Json::Value(Json::arrayValue);

// loop through points
/*for (auto const& x : BoxVec){
for (auto const& x : BoxVec){
Json::Value elem;
elem["key"] = x.first;
elem["val"] = x.second.JsonValue();
root["boxes"].append(elem);
}
*/


root["delta_x"] = delta_x.JsonValue();
root["delta_y"] = delta_y.JsonValue();
Expand Down Expand Up @@ -443,9 +443,10 @@ void KeyFrameBBox::SetJsonValue(const Json::Value root) {
BaseFps.den = (int) root["BaseFPS"]["den"].asInt();
}
if (!root["TimeScale"].isNull()) {
this->TimeScale = (double) root["TimeScale"].asDouble();
double scale = (double) root["TimeScale"].asDouble();
this->ScalePoints(scale);
}
/*

if (!root["boxes"].isNull()){
// loop through points
for (const auto existing_point : root["boxes"]) {
Expand All @@ -456,6 +457,6 @@ void KeyFrameBBox::SetJsonValue(const Json::Value root) {
BoxVec.insert({existing_point["key"].asDouble(), box});
}
}
*/

return;
}
16 changes: 12 additions & 4 deletions src/effects/Tracker.cpp
Expand Up @@ -69,6 +69,7 @@ void Tracker::init_effect_details()
info.has_audio = false;
info.has_video = true;

this->TimeScale = 1.0;
}

// This method is required for all derived classes of EffectBase, and returns a
Expand Down Expand Up @@ -144,8 +145,10 @@ bool Tracker::LoadTrackedData(std::string inputFilePath){

// Assign data to tracker map
//trackedDataById[id] = EffectFrameData(id, rotation, x1, y1, x2, y2);
trackedData.AddBox(id, x1, y1, (x2-x1), (y2-y1));
trackedData.AddRotation(id, rotation);
if ((x1 >= 0.0) && (y1 >= 0.0) && (x2 >= 0.0) && (y2 >= 0.0)){
trackedData.AddBox(id, x1, y1, (x2-x1), (y2-y1));
trackedData.AddRotation(id, rotation);
}
}

// Show the time stamp from the last update in tracker data file
Expand Down Expand Up @@ -180,7 +183,7 @@ Json::Value Tracker::JsonValue() const {
root["protobuf_data_path"] = protobuf_data_path;
root["BaseFPS"]["num"] = BaseFPS.num;
root["BaseFPS"]["den"] = BaseFPS.den;

root["TimeScale"] = this->TimeScale;
// return JsonValue
return root;
}
Expand Down Expand Up @@ -215,8 +218,13 @@ void Tracker::SetJsonValue(const Json::Value root) {
BaseFPS.den = (int) root["BaseFPS"]["den"].asInt();
}

if (!root["TimeScale"].isNull()){
TimeScale = (double) root["TimeScale"].asDouble();
}

trackedData.SetBaseFPS(this->BaseFPS);

trackedData.ScalePoints(TimeScale);

// Set data from Json (if key is found)
if (!root["protobuf_data_path"].isNull()){
protobuf_data_path = (root["protobuf_data_path"].asString());
Expand Down
1 change: 1 addition & 0 deletions src/effects/Tracker.h
Expand Up @@ -92,6 +92,7 @@ namespace openshot
void init_effect_details();
std::string protobuf_data_path;
Fraction BaseFPS;
double TimeScale;
public:

std::map<int, EffectFrameData> trackedDataById; // Save object tracking box data
Expand Down

0 comments on commit 940840c

Please sign in to comment.