OpenShot Library | libopenshot 0.2.7
Stabilizer.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Header file for Stabilizer effect class
4 * @author Jonathan Thomas <jonathan@openshot.org>
5 * @author Brenno Caldato <brenno.caldato@outlook.com>
6 *
7 * @ref License
8 */
9
10/* LICENSE
11 *
12 * Copyright (c) 2008-2019 OpenShot Studios, LLC
13 * <http://www.openshotstudios.com/>. This file is part of
14 * OpenShot Library (libopenshot), an open-source project dedicated to
15 * delivering high quality video editing and animation solutions to the
16 * world. For more information visit <http://www.openshot.org/>.
17 *
18 * OpenShot Library (libopenshot) is free software: you can redistribute it
19 * and/or modify it under the terms of the GNU Lesser General Public License
20 * as published by the Free Software Foundation, either version 3 of the
21 * License, or (at your option) any later version.
22 *
23 * OpenShot Library (libopenshot) is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
30 */
31
32#ifndef OPENSHOT_STABILIZER_EFFECT_H
33#define OPENSHOT_STABILIZER_EFFECT_H
34
35#include "../EffectBase.h"
36
37#include <cmath>
38#include <stdio.h>
39#include <memory>
40#include "../Color.h"
41#include "../Json.h"
42#include "../KeyFrame.h"
43#include "protobuf_messages/stabilizedata.pb.h"
44
45// Store the relative transformation parameters between consecutive frames
47{
49 EffectTransformParam(double _dx, double _dy, double _da) {
50 dx = _dx;
51 dy = _dy;
52 da = _da;
53 }
54
55 double dx;
56 double dy;
57 double da; // angle
58};
59
60// Stores the global camera trajectory for one frame
62{
64 EffectCamTrajectory(double _x, double _y, double _a) {
65 x = _x;
66 y = _y;
67 a = _a;
68 }
69
70 double x;
71 double y;
72 double a; // angle
73};
74
75
76namespace openshot
77{
78
79 /**
80 * @brief This class stabilizes a video clip to remove undesired shaking and jitter.
81 *
82 * Adding stabilization is useful to increase video quality overall, since it removes
83 * from subtle to harsh unexpected camera movements.
84 */
85 class Stabilizer : public EffectBase
86 {
87 private:
88 /// Init effect settings
89 void init_effect_details();
90 std::string protobuf_data_path;
91 Keyframe zoom;
92
93 public:
94 std::string teste;
95 std::map <size_t,EffectCamTrajectory> trajectoryData; // Save camera trajectory data
96 std::map <size_t,EffectTransformParam> transformationData; // Save transormation data
97
98 Stabilizer();
99
100 Stabilizer(std::string clipTrackerDataPath);
101
102 /// @brief This method is required for all derived classes of EffectBase, and returns a
103 /// modified openshot::Frame object
104 ///
105 /// The frame object is passed into this method, and a frame_number is passed in which
106 /// tells the effect which settings to use from its keyframes (starting at 1).
107 ///
108 /// @returns The modified openshot::Frame object
109 /// @param frame The frame object that needs the effect applied to it
110 /// @param frame_number The frame number (starting at 1) of the effect on the timeline.
111 std::shared_ptr<Frame> GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) override;
112
113 std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override {
114 return GetFrame(std::make_shared<openshot::Frame>(), frame_number);
115 };
116
117 /// Load protobuf data file
118 bool LoadStabilizedData(std::string inputFilePath);
119
120 // Get and Set JSON methods
121 std::string Json() const override; ///< Generate JSON string of this object
122 void SetJson(const std::string value) override; ///< Load JSON string into this object
123 Json::Value JsonValue() const override; ///< Generate Json::Value for this object
124 void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object
125
126 /// Get all properties for a specific frame (perfect for a UI to display the current state
127 /// of all properties at any time)
128 std::string PropertiesJSON(int64_t requested_frame) const override;
129 };
130
131}
132
133#endif
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:71
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:72
This class stabilizes a video clip to remove undesired shaking and jitter.
Definition: Stabilizer.h:86
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Stabilizer.cpp:180
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: Stabilizer.h:113
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number) override
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
Definition: Stabilizer.cpp:79
std::map< size_t, EffectTransformParam > transformationData
Definition: Stabilizer.h:96
std::string teste
Definition: Stabilizer.h:94
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Stabilizer.cpp:229
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Stabilizer.cpp:193
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Stabilizer.cpp:210
std::map< size_t, EffectCamTrajectory > trajectoryData
Definition: Stabilizer.h:95
bool LoadStabilizedData(std::string inputFilePath)
Load protobuf data file.
Definition: Stabilizer.cpp:122
std::string Json() const override
Generate JSON string of this object.
Definition: Stabilizer.cpp:173
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47
EffectCamTrajectory(double _x, double _y, double _a)
Definition: Stabilizer.h:64
EffectTransformParam(double _dx, double _dy, double _da)
Definition: Stabilizer.h:49