Loading...
Searching...
No Matches
ClipProcessingJobs.cpp
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "ClipProcessingJobs.h"
namespace openshot {
// Constructor responsible to choose processing type and apply to clip
ClipProcessingJobs::ClipProcessingJobs(std::string processingType, std::string processInfoJson) :
processingType(processingType), processInfoJson(processInfoJson){
}
void ClipProcessingJobs::processClip(Clip& clip, std::string json){
processInfoJson = json;
// Process clip and save processed data
if(processingType == "Stabilizer"){
t = std::thread(&ClipProcessingJobs::stabilizeClip, this, std::ref(clip), std::ref(this->processingController));
}
if(processingType == "Tracker"){
t = std::thread(&ClipProcessingJobs::trackClip, this, std::ref(clip), std::ref(this->processingController));
}
if(processingType == "ObjectDetection"){
t = std::thread(&ClipProcessingJobs::detectObjectsClip, this, std::ref(clip), std::ref(this->processingController));
}
}
// Apply object tracking to clip
void ClipProcessingJobs::trackClip(Clip& clip, ProcessingController& controller){
// Create CVTracker object
CVTracker tracker(processInfoJson, controller);
// Start tracking
tracker.trackClip(clip);
// Thread controller. If effect processing is done, save data
// Else, kill thread
if(controller.ShouldStop()){
controller.SetFinished(true);
return;
}
else{
// Save stabilization data
tracker.SaveTrackedData();
// tells to UI that the processing finished
controller.SetFinished(true);
}
}
// Apply object detection to clip
void ClipProcessingJobs::detectObjectsClip(Clip& clip, ProcessingController& controller){
// create CVObjectDetection object
CVObjectDetection objDetector(processInfoJson, controller);
// Start object detection process
objDetector.detectObjectsClip(clip);
// Thread controller. If effect processing is done, save data
// Else, kill thread
if(controller.ShouldStop()){
controller.SetFinished(true);
return;
}
else{
// Save object detection data
objDetector.SaveObjDetectedData();
// tells to UI that the processing finished
controller.SetFinished(true);
}
}
void ClipProcessingJobs::stabilizeClip(Clip& clip, ProcessingController& controller){
// create CVStabilization object
CVStabilization stabilizer(processInfoJson, controller);
// Start stabilization process
stabilizer.stabilizeClip(clip);
// Thread controller. If effect processing is done, save data
// Else, kill thread
if(controller.ShouldStop()){
controller.SetFinished(true);
return;
}
else{
// Save stabilization data
stabilizer.SaveStabilizedData();
// tells to UI that the processing finished
controller.SetFinished(true);
}
}
// Get processing progress while iterating on the clip
int ClipProcessingJobs::GetProgress(){
return (int)processingController.GetProgress();
}
// Check if processing finished
bool ClipProcessingJobs::IsDone(){
if(processingController.GetFinished()){
t.join();
}
return processingController.GetFinished();
}
// stop preprocessing before finishing it
void ClipProcessingJobs::CancelProcessing(){
processingController.CancelProcessing();
}
// check if there is an error with the config
bool ClipProcessingJobs::GetError(){
return processingController.GetError();
}
// get the error message
std::string ClipProcessingJobs::GetErrorMessage(){
return processingController.GetErrorMessage();
}
} // namespace openshot
ClipProcessingJobs.h
Header for ClipProcessingJobs class.
CVStabilization
This class stabilizes a video frame using optical flow.
Definition CVStabilization.h:75
ProcessingController
Definition ProcessingController.h:20
ProcessingController::ShouldStop
bool ShouldStop()
Definition ProcessingController.h:68
ProcessingController::CancelProcessing
void CancelProcessing()
Definition ProcessingController.h:63
ProcessingController::GetError
bool GetError()
Definition ProcessingController.h:80
ProcessingController::GetErrorMessage
std::string GetErrorMessage()
Definition ProcessingController.h:86
ProcessingController::GetFinished
int GetFinished()
Definition ProcessingController.h:41
ProcessingController::SetFinished
void SetFinished(bool f)
Definition ProcessingController.h:47
ProcessingController::GetProgress
int GetProgress()
Definition ProcessingController.h:57
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
openshot::ClipProcessingJobs::processClip
void processClip(Clip &clip, std::string json)
Definition ClipProcessingJobs.cpp:23
openshot::ClipProcessingJobs::IsDone
bool IsDone()
Definition ClipProcessingJobs.cpp:109
openshot::ClipProcessingJobs::ClipProcessingJobs
ClipProcessingJobs(std::string processingType, std::string processInfoJson)
Definition ClipProcessingJobs.cpp:19
openshot::ClipProcessingJobs::GetProgress
int GetProgress()
Definition ClipProcessingJobs.cpp:103
openshot::ClipProcessingJobs::GetError
bool GetError()
Definition ClipProcessingJobs.cpp:123
openshot::ClipProcessingJobs::CancelProcessing
void CancelProcessing()
Definition ClipProcessingJobs.cpp:118
openshot::ClipProcessingJobs::GetErrorMessage
std::string GetErrorMessage()
Definition ClipProcessingJobs.cpp:128
openshot::Clip
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29