OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
ClipProcessingJobs.cpp
Go to the documentation of this file.
1
10// Copyright (c) 2008-2019 OpenShot Studios, LLC
11//
12// SPDX-License-Identifier: LGPL-3.0-or-later
13
14#include "ClipProcessingJobs.h"
15
16namespace openshot {
17
18// Constructor responsible to choose processing type and apply to clip
19ClipProcessingJobs::ClipProcessingJobs(std::string processingType, std::string processInfoJson) :
20processingType(processingType), processInfoJson(processInfoJson){
21}
22
23std::string ClipProcessingJobs::ValidateONNXModel(std::string modelPath){
24#ifdef USE_OPENCV
26#else
27 return "OpenShot was not compiled with OpenCV support.";
28#endif
29}
30
31std::shared_ptr<Frame> ClipProcessingJobs::PreviewObjectMask(std::string processInfoJson, std::shared_ptr<Frame> frame){
32#ifdef USE_OPENCV
33 ProcessingController controller;
34 CVObjectMask objectMask(processInfoJson, controller);
35 return objectMask.PreviewSeedMask(frame);
36#else
37 (void)processInfoJson;
38 (void)frame;
39 return std::shared_ptr<Frame>();
40#endif
41}
42
43void ClipProcessingJobs::processClip(Clip& clip, std::string json){
44 processInfoJson = json;
45
46 // Process clip and save processed data
47 if(processingType == "Stabilizer"){
48 t = std::thread(&ClipProcessingJobs::stabilizeClip, this, std::ref(clip), std::ref(this->processingController));
49 }
50 if(processingType == "Tracker"){
51 t = std::thread(&ClipProcessingJobs::trackClip, this, std::ref(clip), std::ref(this->processingController));
52 }
53 if(processingType == "ObjectDetection"){
54 t = std::thread(&ClipProcessingJobs::detectObjectsClip, this, std::ref(clip), std::ref(this->processingController));
55 }
56 if(processingType == "ObjectMask"){
57 t = std::thread(&ClipProcessingJobs::maskObjectClip, this, std::ref(clip), std::ref(this->processingController));
58 }
59}
60
61// Apply object tracking to clip
62void ClipProcessingJobs::trackClip(Clip& clip, ProcessingController& controller){
63
64 // Create CVTracker object
65 CVTracker tracker(processInfoJson, controller);
66 // Start tracking
67 tracker.trackClip(clip);
68
69 // Thread controller. If effect processing is done, save data
70 // Else, kill thread
71 if(controller.ShouldStop()){
72 controller.SetFinished(true);
73 return;
74 }
75 else{
76 // Save stabilization data
77 tracker.SaveTrackedData();
78 // tells to UI that the processing finished
79 controller.SetFinished(true);
80 }
81
82}
83
84// Apply object detection to clip
85void ClipProcessingJobs::detectObjectsClip(Clip& clip, ProcessingController& controller){
86 // create CVObjectDetection object
87 CVObjectDetection objDetector(processInfoJson, controller);
88 // Start object detection process
89 objDetector.detectObjectsClip(clip);
90
91 // Thread controller. If effect processing is done, save data
92 // Else, kill thread
93 if(controller.ShouldStop()){
94 controller.SetFinished(true);
95 return;
96 }
97 else{
98 // Save object detection data
99 objDetector.SaveObjDetectedData();
100 // tells to UI that the processing finished
101 controller.SetFinished(true);
102 }
103}
104
105// Apply object segmentation mask to clip
106void ClipProcessingJobs::maskObjectClip(Clip& clip, ProcessingController& controller){
107 CVObjectMask objectMask(processInfoJson, controller);
108 objectMask.maskClip(clip);
109
110 if(controller.ShouldStop()){
111 controller.SetFinished(true);
112 return;
113 }
114 else{
115 objectMask.SaveObjMaskData();
116 controller.SetFinished(true);
117 }
118}
119
120void ClipProcessingJobs::stabilizeClip(Clip& clip, ProcessingController& controller){
121 // create CVStabilization object
122 CVStabilization stabilizer(processInfoJson, controller);
123 // Start stabilization process
124 stabilizer.stabilizeClip(clip);
125
126 // Thread controller. If effect processing is done, save data
127 // Else, kill thread
128 if(controller.ShouldStop()){
129 controller.SetFinished(true);
130 return;
131 }
132 else{
133 // Save stabilization data
134 stabilizer.SaveStabilizedData();
135 // tells to UI that the processing finished
136 controller.SetFinished(true);
137 }
138}
139
140// Get processing progress while iterating on the clip
142
143 return (int)processingController.GetProgress();
144}
145
146// Check if processing finished
148
149 if(processingController.GetFinished()){
150 t.join();
151 }
152 return processingController.GetFinished();
153}
154
155// stop preprocessing before finishing it
157 processingController.CancelProcessing();
158}
159
160// check if there is an error with the config
162 return processingController.GetError();
163}
164
165// get the error message
167 return processingController.GetErrorMessage();
168}
169
170} // namespace openshot
Header for ClipProcessingJobs class.
This class stabilizes a video frame using optical flow.
static std::string ValidateONNXModel(std::string modelPath)
Preprocess a clip into EfficientSAM/Cutie object masks stored in the object-detection protobuf format...
std::shared_ptr< Frame > PreviewSeedMask(std::shared_ptr< Frame > frame)
The tracker class will receive one bounding box provided by the user and then iterate over the clip f...
Definition CVTracker.h:75
void processClip(Clip &clip, std::string json)
static std::shared_ptr< Frame > PreviewObjectMask(std::string processInfoJson, std::shared_ptr< Frame > frame)
ClipProcessingJobs(std::string processingType, std::string processInfoJson)
static std::string ValidateONNXModel(std::string modelPath)
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
This namespace is the default namespace for all code in the openshot library.