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