Loading...
Searching...
No Matches
Clip.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_CLIP_H
#define OPENSHOT_CLIP_H
#ifdef USE_OPENCV
#define int64 opencv_broken_int
#define uint64 opencv_broken_uint
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#undef uint64
#undef int64
#endif
#include <memory>
#include <string>
#include "AudioLocation.h"
#include "ClipBase.h"
#include "ReaderBase.h"
#include "Color.h"
#include "Enums.h"
#include "EffectBase.h"
#include "EffectInfo.h"
#include "KeyFrame.h"
#include "TrackedObjectBase.h"
namespace openshot {
class AudioResampler;
class EffectInfo;
class Frame;
struct CompareClipEffects{
bool operator()( openshot::EffectBase* lhs, openshot::EffectBase* rhs){
if( lhs->Layer() < rhs->Layer() ) return true;
if( lhs->Layer() == rhs->Layer() && lhs->Position() < rhs->Position() ) return true;
if( lhs->Layer() == rhs->Layer() && lhs->Position() == rhs->Position() && lhs->Order() > rhs->Order() ) return true;
return false;
}};
class Clip : public openshot::ClipBase, public openshot::ReaderBase {
protected:
std::recursive_mutex getFrameMutex;
AudioLocation previous_location;
void init_settings();
void init_reader_settings();
void init_reader_rotation();
private:
bool waveform;
std::list<openshot::EffectBase*> effects;
bool is_open;
std::string parentObjectId;
std::shared_ptr<openshot::TrackedObjectBase> parentTrackedObject;
openshot::Clip* parentClipObject;
CacheMemory final_cache;
// Audio resampler (if time mapping)
openshot::AudioResampler *resampler;
// File Reader object
openshot::ReaderBase* reader;
openshot::ReaderBase* allocated_reader;
int64_t adjust_frame_number_minimum(int64_t frame_number);
void apply_effects(std::shared_ptr<openshot::Frame> frame);
void apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame);
void apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame);
int64_t adjust_timeline_framenumber(int64_t clip_frame_number);
QTransform get_transform(std::shared_ptr<Frame> frame, int width, int height);
std::string get_file_extension(std::string path);
std::shared_ptr<openshot::Frame> GetOrCreateFrame(int64_t number, bool enable_time=true);
void apply_timemapping(std::shared_ptr<openshot::Frame> frame);
bool isEqual(double a, double b);
void sort_effects();
void reverse_buffer(juce::AudioBuffer<float>* buffer);
public:
openshot::GravityType gravity;
openshot::ScaleType scale;
openshot::AnchorType anchor;
openshot::FrameDisplayType display;
openshot::VolumeMixType mixing;
#ifdef USE_OPENCV
bool COMPILED_WITH_CV = true;
#else
bool COMPILED_WITH_CV = false;
#endif
Clip();
Clip(std::string path);
Clip(openshot::ReaderBase* new_reader);
virtual ~Clip();
openshot::CacheMemory* GetCache() override { return &final_cache; };
bool IsOpen() override { return is_open; };
std::string GetAttachedId() const { return parentObjectId; };
void SetAttachedId(std::string value) { parentObjectId = value; };
void AttachToObject(std::string object_id);
void SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject);
void SetAttachedClip(Clip* clipObject);
std::shared_ptr<openshot::TrackedObjectBase> GetAttachedObject() const { return parentTrackedObject; };
Clip* GetAttachedClip() const { return parentClipObject; };
std::string Name() override { return "Clip"; };
void AddEffect(openshot::EffectBase* effect);
void Close() override;
std::list<openshot::EffectBase*> Effects() { return effects; };
openshot::EffectBase* GetEffect(const std::string& id);
std::shared_ptr<openshot::Frame> GetFrame(int64_t clip_frame_number) override;
std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> background_frame, int64_t clip_frame_number) override;
std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> background_frame, int64_t clip_frame_number, openshot::TimelineInfoStruct* options);
void Open() override;
void Reader(openshot::ReaderBase* new_reader);
openshot::ReaderBase* Reader();
// Override End() position (in seconds) of clip (trim end of video)
float End() const override;
void End(float value) override;
openshot::TimelineBase* ParentTimeline() override { return timeline; }
void ParentTimeline(openshot::TimelineBase* new_timeline) override;
// Get and Set JSON methods
std::string Json() const override;
void SetJson(const std::string value) override;
Json::Value JsonValue() const override;
void SetJsonValue(const Json::Value root) override;
std::string PropertiesJSON(int64_t requested_frame) const override;
void RemoveEffect(openshot::EffectBase* effect);
// Waveform property
bool Waveform() { return waveform; }
void Waveform(bool value) { waveform = value; }
// Scale, Location, and Alpha curves
openshot::Keyframe scale_x;
openshot::Keyframe scale_y;
openshot::Keyframe location_x;
openshot::Keyframe location_y;
openshot::Keyframe alpha;
// Rotation and Shear curves (origin point (x,y) is adjustable for both rotation and shear)
openshot::Keyframe rotation;
openshot::Keyframe shear_x;
openshot::Keyframe shear_y;
openshot::Keyframe origin_x;
openshot::Keyframe origin_y;
// Time and Volume curves
openshot::Keyframe time;
openshot::Keyframe volume;
openshot::Color wave_color;
// Perspective curves
openshot::Keyframe perspective_c1_x;
openshot::Keyframe perspective_c1_y;
openshot::Keyframe perspective_c2_x;
openshot::Keyframe perspective_c2_y;
openshot::Keyframe perspective_c3_x;
openshot::Keyframe perspective_c3_y;
openshot::Keyframe perspective_c4_x;
openshot::Keyframe perspective_c4_y;
// Audio channel filter and mappings
openshot::Keyframe channel_filter;
openshot::Keyframe channel_mapping;
// Override has_video and has_audio properties of clip (and their readers)
openshot::Keyframe has_audio;
openshot::Keyframe has_video;
};
} // namespace
#endif // OPENSHOT_CLIP_H
AudioLocation.h
Header file for AudioLocation class.
ClipBase.h
Header file for ClipBase class.
Color.h
Header file for Color class.
EffectBase.h
Header file for EffectBase class.
EffectInfo.h
Header file for the EffectInfo class.
Enums.h
Header file for TextReader class.
path
path
Definition FFmpegWriter.cpp:1515
KeyFrame.h
Header file for the Keyframe class.
ReaderBase.h
Header file for ReaderBase class.
TrackedObjectBase.h
Header file for the TrackedObjectBase class.
juce::AudioBuffer
Definition Frame.h:38
openshot::AudioResampler
This class is used to resample audio data for many sequential frames.
Definition AudioResampler.h:30
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition CacheMemory.h:29
openshot::ClipBase
This abstract class is the base class, used by all clips in libopenshot.
Definition ClipBase.h:33
openshot::ClipBase::Layer
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition ClipBase.h:87
openshot::ClipBase::timeline
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition ClipBase.h:41
openshot::ClipBase::Position
float Position() const
Get position on timeline (in seconds)
Definition ClipBase.h:86
openshot::Clip
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
openshot::Clip::SetAttachedObject
void SetAttachedObject(std::shared_ptr< openshot::TrackedObjectBase > trackedObject)
Set the pointer to the trackedObject this clip is attached to.
Definition Clip.cpp:262
openshot::Clip::scale_x
openshot::Keyframe scale_x
Curve representing the horizontal scaling in percent (0 to 1)
Definition Clip.h:298
openshot::Clip::location_y
openshot::Keyframe location_y
Curve representing the relative Y position in percent based on the gravity (-1 to 1)
Definition Clip.h:301
openshot::Clip::shear_x
openshot::Keyframe shear_x
Curve representing X shear angle in degrees (-45.0=left, 45.0=right)
Definition Clip.h:306
openshot::Clip::perspective_c4_x
openshot::Keyframe perspective_c4_x
Curves representing X for coordinate 4.
Definition Clip.h:325
openshot::Clip::anchor
openshot::AnchorType anchor
The anchor determines what parent a clip should snap to.
Definition Clip.h:167
openshot::Clip::mixing
openshot::VolumeMixType mixing
What strategy should be followed when mixing audio with other clips.
Definition Clip.h:169
openshot::Clip::Open
void Open() override
Open the internal reader.
Definition Clip.cpp:318
openshot::Clip::GetAttachedObject
std::shared_ptr< openshot::TrackedObjectBase > GetAttachedObject() const
Return a pointer to the trackedObject this clip is attached to.
Definition Clip.h:210
openshot::Clip::GetAttachedId
std::string GetAttachedId() const
Get and set the object id that this clip is attached to.
Definition Clip.h:198
openshot::Clip::rotation
openshot::Keyframe rotation
Curve representing the rotation (0 to 360)
Definition Clip.h:305
openshot::Clip::channel_filter
openshot::Keyframe channel_filter
A number representing an audio channel to filter (clears all other channels)
Definition Clip.h:329
openshot::Clip::display
openshot::FrameDisplayType display
The format to display the frame number (if any)
Definition Clip.h:168
openshot::Clip::init_reader_rotation
void init_reader_rotation()
Update default rotation from reader.
Definition Clip.cpp:115
openshot::Clip::Clip
Clip()
Default Constructor.
Definition Clip.cpp:135
openshot::Clip::perspective_c1_x
openshot::Keyframe perspective_c1_x
Curves representing X for coordinate 1.
Definition Clip.h:319
openshot::Clip::AttachToObject
void AttachToObject(std::string object_id)
Attach clip to Tracked Object or to another Clip.
Definition Clip.cpp:241
openshot::Clip::Json
std::string Json() const override
Generate JSON string of this object.
Definition Clip.cpp:735
openshot::Clip::GetEffect
openshot::EffectBase * GetEffect(const std::string &id)
Look up an effect by ID.
Definition Clip.cpp:470
openshot::Clip::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition Clip.cpp:962
openshot::Clip::GetCache
openshot::CacheMemory * GetCache() override
Get the cache object (always return NULL for this reader)
Definition Clip.h:192
openshot::Clip::alpha
openshot::Keyframe alpha
Curve representing the alpha (1 to 0)
Definition Clip.h:302
openshot::Clip::has_audio
openshot::Keyframe has_audio
An optional override to determine if this clip has audio (-1=undefined, 0=no, 1=yes)
Definition Clip.h:333
openshot::Clip::perspective_c3_x
openshot::Keyframe perspective_c3_x
Curves representing X for coordinate 3.
Definition Clip.h:323
openshot::Clip::init_reader_settings
void init_reader_settings()
Init reader info details.
Definition Clip.cpp:101
openshot::Clip::perspective_c1_y
openshot::Keyframe perspective_c1_y
Curves representing Y for coordinate 1.
Definition Clip.h:320
openshot::Clip::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition Clip.cpp:889
openshot::Clip::SetAttachedClip
void SetAttachedClip(Clip *clipObject)
Set the pointer to the clip this clip is attached to.
Definition Clip.cpp:267
openshot::Clip::ParentTimeline
openshot::TimelineBase * ParentTimeline() override
Get the associated Timeline pointer (if any)
Definition Clip.h:276
openshot::Clip::perspective_c4_y
openshot::Keyframe perspective_c4_y
Curves representing Y for coordinate 4.
Definition Clip.h:326
openshot::Clip::time
openshot::Keyframe time
Curve representing the frames over time to play (used for speed and direction of video)
Definition Clip.h:312
openshot::Clip::Waveform
bool Waveform()
Get the waveform property of this clip.
Definition Clip.h:294
openshot::Clip::gravity
openshot::GravityType gravity
The gravity of a clip determines where it snaps to its parent.
Definition Clip.h:165
openshot::Clip::Effects
std::list< openshot::EffectBase * > Effects()
Return the list of effects on the timeline.
Definition Clip.h:225
openshot::Clip::previous_location
AudioLocation previous_location
Previous time-mapped audio location.
Definition Clip.h:95
openshot::Clip::perspective_c3_y
openshot::Keyframe perspective_c3_y
Curves representing Y for coordinate 3.
Definition Clip.h:324
openshot::Clip::AddEffect
void AddEffect(openshot::EffectBase *effect)
Add an effect to the clip.
Definition Clip.cpp:1150
openshot::Clip::Close
void Close() override
Close the internal reader.
Definition Clip.cpp:339
openshot::Clip::Waveform
void Waveform(bool value)
Set the waveform property of this clip.
Definition Clip.h:295
openshot::Clip::~Clip
virtual ~Clip()
Destructor.
Definition Clip.cpp:221
openshot::Clip::perspective_c2_y
openshot::Keyframe perspective_c2_y
Curves representing Y for coordinate 2.
Definition Clip.h:322
openshot::Clip::volume
openshot::Keyframe volume
Curve representing the volume (0 to 1)
Definition Clip.h:313
openshot::Clip::shear_y
openshot::Keyframe shear_y
Curve representing Y shear angle in degrees (-45.0=down, 45.0=up)
Definition Clip.h:307
openshot::Clip::GetAttachedClip
Clip * GetAttachedClip() const
Return a pointer to the clip this clip is attached to.
Definition Clip.h:212
openshot::Clip::scale_y
openshot::Keyframe scale_y
Curve representing the vertical scaling in percent (0 to 1)
Definition Clip.h:299
openshot::Clip::End
float End() const override
Get end position (in seconds) of clip (trim end of video), which can be affected by the time curve.
Definition Clip.cpp:354
openshot::Clip::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t clip_frame_number) override
Get an openshot::Frame object for a specific frame number of this clip. The image size and number of ...
Definition Clip.cpp:389
openshot::Clip::Name
std::string Name() override
Return the type name of the class.
Definition Clip.h:215
openshot::Clip::Reader
openshot::ReaderBase * Reader()
Get the current reader.
Definition Clip.cpp:308
openshot::Clip::RemoveEffect
void RemoveEffect(openshot::EffectBase *effect)
Remove an effect from the clip.
Definition Clip.cpp:1197
openshot::Clip::SetAttachedId
void SetAttachedId(std::string value)
Set id of the object id that this clip is attached to.
Definition Clip.h:200
openshot::Clip::channel_mapping
openshot::Keyframe channel_mapping
A number representing an audio channel to output (only works when filtering a channel)
Definition Clip.h:330
openshot::Clip::has_video
openshot::Keyframe has_video
An optional override to determine if this clip has video (-1=undefined, 0=no, 1=yes)
Definition Clip.h:334
openshot::Clip::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition Clip.cpp:742
openshot::Clip::COMPILED_WITH_CV
bool COMPILED_WITH_CV
Definition Clip.h:172
openshot::Clip::wave_color
openshot::Color wave_color
Curve representing the color of the audio wave form.
Definition Clip.h:316
openshot::Clip::init_settings
void init_settings()
Init default settings for a clip.
Definition Clip.cpp:36
openshot::Clip::perspective_c2_x
openshot::Keyframe perspective_c2_x
Curves representing X for coordinate 2.
Definition Clip.h:321
openshot::Clip::scale
openshot::ScaleType scale
The scale determines how a clip should be resized to fit its parent.
Definition Clip.h:166
openshot::Clip::location_x
openshot::Keyframe location_x
Curve representing the relative X position in percent based on the gravity (-1 to 1)
Definition Clip.h:300
openshot::Clip::origin_x
openshot::Keyframe origin_x
Curve representing X origin point (0.0=0% (left), 1.0=100% (right))
Definition Clip.h:308
openshot::Clip::getFrameMutex
std::recursive_mutex getFrameMutex
Mutex for multiple threads.
Definition Clip.h:92
openshot::Clip::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition Clip.cpp:945
openshot::Clip::origin_y
openshot::Keyframe origin_y
Curve representing Y origin point (0.0=0% (top), 1.0=100% (bottom))
Definition Clip.h:309
openshot::Clip::IsOpen
bool IsOpen() override
Determine if reader is open or closed.
Definition Clip.h:195
openshot::Color
This class represents a color (used on the timeline and clips)
Definition Color.h:27
openshot::EffectBase
This abstract class is the base class, used by all effects in libopenshot.
Definition EffectBase.h:53
openshot::EffectBase::Order
int Order() const
Get the order that this effect should be executed.
Definition EffectBase.h:112
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition KeyFrame.h:53
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition ReaderBase.h:76
openshot::TimelineBase
This class represents a timeline (used for building generic timeline implementations)
Definition TimelineBase.h:40
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::AnchorType
AnchorType
This enumeration determines what parent a clip should be aligned to.
Definition Enums.h:45
openshot::GravityType
GravityType
This enumeration determines how clips are aligned to their parent container.
Definition Enums.h:22
openshot::ScaleType
ScaleType
This enumeration determines how clips are scaled to fit their parent container.
Definition Enums.h:36
openshot::VolumeMixType
VolumeMixType
This enumeration determines the strategy when mixing audio with other clips.
Definition Enums.h:61
openshot::FrameDisplayType
FrameDisplayType
This enumeration determines the display format of the clip's frame number (if any)....
Definition Enums.h:52
openshot::AudioLocation
This struct holds the associated video frame and starting sample # for an audio packet.
Definition AudioLocation.h:25
openshot::CompareClipEffects
Definition Clip.h:48
openshot::CompareClipEffects::operator()
bool operator()(openshot::EffectBase *lhs, openshot::EffectBase *rhs)
Definition Clip.h:49
openshot::TimelineInfoStruct
This struct contains info about the current Timeline clip instance.
Definition TimelineBase.h:33