OpenShot Library | libopenshot  0.2.7
ClipProcessingJobs.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for ClipProcessingJobs 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 #include "ClipProcessingJobs.h"
33 
34 namespace openshot {
35 
36 // Constructor responsible to choose processing type and apply to clip
37 ClipProcessingJobs::ClipProcessingJobs(std::string processingType, std::string processInfoJson) :
38 processingType(processingType), processInfoJson(processInfoJson){
39 }
40 
41 void ClipProcessingJobs::processClip(Clip& clip, std::string json){
42  processInfoJson = json;
43 
44  // Process clip and save processed data
45  if(processingType == "Stabilizer"){
46  t = std::thread(&ClipProcessingJobs::stabilizeClip, this, std::ref(clip), std::ref(this->processingController));
47  }
48  if(processingType == "Tracker"){
49  t = std::thread(&ClipProcessingJobs::trackClip, this, std::ref(clip), std::ref(this->processingController));
50  }
51  if(processingType == "Object Detector"){
52  t = std::thread(&ClipProcessingJobs::detectObjectsClip, this, std::ref(clip), std::ref(this->processingController));
53  }
54 }
55 
56 // Apply object tracking to clip
57 void ClipProcessingJobs::trackClip(Clip& clip, ProcessingController& controller){
58 
59  // Create CVTracker object
60  CVTracker tracker(processInfoJson, controller);
61  // Start tracking
62  tracker.trackClip(clip);
63 
64  // Thread controller. If effect processing is done, save data
65  // Else, kill thread
66  if(controller.ShouldStop()){
67  controller.SetFinished(true);
68  return;
69  }
70  else{
71  // Save stabilization data
72  tracker.SaveTrackedData();
73  // tells to UI that the processing finished
74  controller.SetFinished(true);
75  }
76 
77 }
78 
79 // Apply object detection to clip
80 void ClipProcessingJobs::detectObjectsClip(Clip& clip, ProcessingController& controller){
81  // create CVObjectDetection object
82  CVObjectDetection objDetector(processInfoJson, controller);
83  // Start object detection process
84  objDetector.detectObjectsClip(clip);
85 
86  // Thread controller. If effect processing is done, save data
87  // Else, kill thread
88  if(controller.ShouldStop()){
89  controller.SetFinished(true);
90  return;
91  }
92  else{
93  // Save object detection data
94  objDetector.SaveObjDetectedData();
95  // tells to UI that the processing finished
96  controller.SetFinished(true);
97  }
98 }
99 
100 void ClipProcessingJobs::stabilizeClip(Clip& clip, ProcessingController& controller){
101  // create CVStabilization object
102  CVStabilization stabilizer(processInfoJson, controller);
103  // Start stabilization process
104  stabilizer.stabilizeClip(clip);
105 
106  // Thread controller. If effect processing is done, save data
107  // Else, kill thread
108  if(controller.ShouldStop()){
109  controller.SetFinished(true);
110  return;
111  }
112  else{
113  // Save stabilization data
114  stabilizer.SaveStabilizedData();
115  // tells to UI that the processing finished
116  controller.SetFinished(true);
117  }
118 }
119 
120 // Get processing progress while iterating on the clip
122 
123  return (int)processingController.GetProgress();
124 }
125 
126 // Check if processing finished
128 
129  if(processingController.GetFinished()){
130  t.join();
131  }
132  return processingController.GetFinished();
133 }
134 
135 // stop preprocessing before finishing it
137  processingController.CancelProcessing();
138 }
139 
140 // check if there is an error with the config
142  return processingController.GetError();
143 }
144 
145 // get the error message
147  return processingController.GetErrorMessage();
148 }
149 
150 } // namespace openshot
Header for ClipProcessingJobs class.
This class stabilizes a video frame using optical flow.
The tracker class will receive one bounding box provided by the user and then iterate over the clip f...
Definition: CVTracker.h:89
void processClip(Clip &clip, std::string json)
ClipProcessingJobs(std::string processingType, std::string processInfoJson)
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:109
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47