20#include "stabilizedata.pb.h"
22#include <google/protobuf/util/time_util.h>
26using google::protobuf::util::TimeUtil;
29Stabilizer::Stabilizer(std::string clipStabilizedDataPath):protobuf_data_path(clipStabilizedDataPath)
32 init_effect_details();
41 init_effect_details();
45void Stabilizer::init_effect_details()
54 info.
description =
"Stabilize video clip to remove undesired shaking and jitter.";
57 protobuf_data_path =
"";
67 cv::Mat frame_image = frame->GetImageCV();
70 if(!frame_image.empty()){
75 float zoom_value = zoom.
GetValue(frame_number);
78 cv::Mat T(2,3,CV_64F);
90 cv::Mat frame_stabilized;
91 cv::warpAffine(frame_image, frame_stabilized, T, frame_image.size());
94 cv::Mat T_scale = cv::getRotationMatrix2D(cv::Point2f(frame_stabilized.cols/2, frame_stabilized.rows/2), 0, zoom_value);
95 cv::warpAffine(frame_stabilized, frame_stabilized, T_scale, frame_stabilized.size());
96 frame_image = frame_stabilized;
101 frame->SetImageCV(frame_image);
109 pb_stabilize::Stabilization stabilizationMessage;
112 std::fstream input(inputFilePath, ios::in | ios::binary);
113 if (!stabilizationMessage.ParseFromIstream(&input)) {
114 std::cerr <<
"Failed to parse protobuf message." << std::endl;
123 for (
size_t i = 0; i < stabilizationMessage.frame_size(); i++) {
126 const pb_stabilize::Frame& pbFrameData = stabilizationMessage.frame(i);
129 size_t id = pbFrameData.id();
132 float x = pbFrameData.x();
133 float y = pbFrameData.y();
134 float a = pbFrameData.a();
140 float dx = pbFrameData.dx();
141 float dy = pbFrameData.dy();
142 float da = pbFrameData.da();
149 google::protobuf::ShutdownProtobufLibrary();
169 root[
"protobuf_data_path"] = protobuf_data_path;
186 catch (
const std::exception& e)
189 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
200 if (!root[
"protobuf_data_path"].isNull()){
201 protobuf_data_path = (root[
"protobuf_data_path"].asString());
204 std::cout<<
"Invalid protobuf data path";
205 protobuf_data_path =
"";
208 if(!root[
"zoom"].isNull())
217 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
218 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
220 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
221 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
222 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
224 root[
"zoom"] =
add_property_json(
"Zoom", zoom.
GetValue(requested_frame),
"float",
"", &zoom, 0.0, 2.0,
false, requested_frame);
230 return root.toStyledString();
Header file for all Exception classes.
Header file for Stabilizer effect class.
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
std::string Id() const
Get the Id of this clip object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
float Position() const
Get position on timeline (in seconds)
std::string id
ID Property for all derived Clip and Effect classes.
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Exception for invalid JSON.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
double GetValue(int64_t index) const
Get the value at a specific index.
Json::Value JsonValue() const
Generate Json::Value for this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
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...
std::map< size_t, EffectTransformParam > transformationData
std::string PropertiesJSON(int64_t requested_frame) const override
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.
std::map< size_t, EffectCamTrajectory > trajectoryData
bool LoadStabilizedData(std::string inputFilePath)
Load protobuf data file.
std::string Json() const override
Generate JSON string of this object.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this effect manipulates the image of a frame.
std::string parent_effect_id
Id of the parent effect (if there is one)
bool has_audio
Determines if this effect manipulates the audio of a frame.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
std::string description
The description of this effect and what it does.