OpenShot Library | libopenshot  0.3.0
Clip.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CLIP_H
14 #define OPENSHOT_CLIP_H
15 
16 #ifdef USE_OPENCV
17  #define int64 opencv_broken_int
18  #define uint64 opencv_broken_uint
19  #include <opencv2/opencv.hpp>
20  #include <opencv2/core.hpp>
21  #undef uint64
22  #undef int64
23 
24 #endif
25 
26 #include <memory>
27 #include <string>
28 
29 #include "ClipBase.h"
30 #include "ReaderBase.h"
31 
32 #include "Color.h"
33 #include "Enums.h"
34 #include "EffectBase.h"
35 #include "EffectInfo.h"
36 #include "KeyFrame.h"
37 #include "TrackedObjectBase.h"
38 
39 #include <QImage>
40 
41 namespace openshot {
42  class AudioResampler;
43  class EffectInfo;
44  class Frame;
45 
51  if( lhs->Layer() < rhs->Layer() ) return true;
52  if( lhs->Layer() == rhs->Layer() && lhs->Position() < rhs->Position() ) return true;
53  if( lhs->Layer() == rhs->Layer() && lhs->Position() == rhs->Position() && lhs->Order() > rhs->Order() ) return true;
54  return false;
55  }};
56 
90  class Clip : public openshot::ClipBase, public openshot::ReaderBase {
91  protected:
93  std::recursive_mutex getFrameMutex;
94 
96  void init_settings();
97 
99  void init_reader_settings();
100 
102  void init_reader_rotation();
103 
104  private:
105  bool waveform;
106  std::list<openshot::EffectBase*> effects;
107  bool is_open;
108  std::string parentObjectId;
109  std::shared_ptr<openshot::TrackedObjectBase> parentTrackedObject;
110  openshot::Clip* parentClipObject;
111 
112 
113  // Audio resampler (if time mapping)
114  openshot::AudioResampler *resampler;
115 
116  // File Reader object
117  openshot::ReaderBase* reader;
118 
121  openshot::ReaderBase* allocated_reader;
122 
124  int64_t adjust_frame_number_minimum(int64_t frame_number);
125 
127  void apply_effects(std::shared_ptr<openshot::Frame> frame);
128 
130  void apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage> background_canvas);
131 
133  QTransform get_transform(std::shared_ptr<Frame> frame, int width, int height);
134 
136  std::string get_file_extension(std::string path);
137 
139  std::shared_ptr<openshot::Frame> GetOrCreateFrame(int64_t number);
140 
142  void get_time_mapped_frame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number);
143 
145  bool isEqual(double a, double b);
146 
148  void sort_effects();
149 
151  void reverse_buffer(juce::AudioBuffer<float>* buffer);
152 
153 
154  public:
160 
161  #ifdef USE_OPENCV
162  bool COMPILED_WITH_CV = true;
163  #else
164  bool COMPILED_WITH_CV = false;
165  #endif
166 
168  Clip();
169 
172  Clip(std::string path);
173 
176  Clip(openshot::ReaderBase* new_reader);
177 
179  virtual ~Clip();
180 
182  openshot::CacheMemory* GetCache() override { return NULL; };
183 
185  bool IsOpen() override { return is_open; };
186 
188  std::string GetAttachedId() const { return parentObjectId; };
190  void SetAttachedId(std::string value) { parentObjectId = value; };
191 
193  void AttachToObject(std::string object_id);
194 
196  void SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject);
198  void SetAttachedClip(Clip* clipObject);
200  std::shared_ptr<openshot::TrackedObjectBase> GetAttachedObject() const { return parentTrackedObject; };
202  Clip* GetAttachedClip() const { return parentClipObject; };
203 
205  std::string Name() override { return "Clip"; };
206 
209  void AddEffect(openshot::EffectBase* effect);
210 
212  void Close() override;
213 
215  std::list<openshot::EffectBase*> Effects() { return effects; };
216 
218  openshot::EffectBase* GetEffect(const std::string& id);
219 
225  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override;
226 
237  std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> background_frame, int64_t frame_number) override;
238 
251  std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> background_frame, int64_t frame_number, openshot::TimelineInfoStruct* options);
252 
254  void Open() override;
255 
258  void Reader(openshot::ReaderBase* new_reader);
259 
261  openshot::ReaderBase* Reader();
262 
263  // Override End() position (in seconds) of clip (trim end of video)
264  float End() const override;
265  void End(float value) override;
266 
267  // Get and Set JSON methods
268  std::string Json() const override;
269  void SetJson(const std::string value) override;
270  Json::Value JsonValue() const override;
271  void SetJsonValue(const Json::Value root) override;
272 
275  std::string PropertiesJSON(int64_t requested_frame) const override;
276 
279  void RemoveEffect(openshot::EffectBase* effect);
280 
281  // Waveform property
282  bool Waveform() { return waveform; }
283  void Waveform(bool value) { waveform = value; }
284 
285  // Scale, Location, and Alpha curves
291 
292  // Rotation and Shear curves (origin point (x,y) is adjustable for both rotation and shear)
298 
299  // Time and Volume curves
302 
305 
306  // Perspective curves
315 
316  // Audio channel filter and mappings
319 
320  // Override has_video and has_audio properties of clip (and their readers)
323  };
324 } // namespace
325 
326 #endif // OPENSHOT_CLIP_H
std::string GetAttachedId() const
Get and set the object id that this clip is attached to.
Definition: Clip.h:188
Header file for ClipBase class.
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:52
openshot::Keyframe perspective_c4_y
Curves representing Y for coordinate 4.
Definition: Clip.h:314
openshot::Keyframe time
Curve representing the frames over time to play (used for speed and direction of video) ...
Definition: Clip.h:300
openshot::Color wave_color
Curve representing the color of the audio wave form.
Definition: Clip.h:304
openshot::Keyframe has_video
An optional override to determine if this clip has video (-1=undefined, 0=no, 1=yes) ...
Definition: Clip.h:322
openshot::Keyframe perspective_c3_x
Curves representing X for coordinate 3.
Definition: Clip.h:311
Header file for ReaderBase class.
openshot::Keyframe location_y
Curve representing the relative Y position in percent based on the gravity (-1 to 1) ...
Definition: Clip.h:289
bool operator()(openshot::EffectBase *lhs, openshot::EffectBase *rhs)
Definition: Clip.h:50
VolumeMixType
This enumeration determines the strategy when mixing audio with other clips.
Definition: Enums.h:60
This struct contains info about the current Timeline clip instance.
Definition: TimelineBase.h:32
openshot::GravityType gravity
The gravity of a clip determines where it snaps to its parent.
Definition: Clip.h:155
ScaleType
This enumeration determines how clips are scaled to fit their parent container.
Definition: Enums.h:35
Clip * GetAttachedClip() const
Return a pointer to the clip this clip is attached to.
Definition: Clip.h:202
openshot::Keyframe scale_x
Curve representing the horizontal scaling in percent (0 to 1)
Definition: Clip.h:286
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
openshot::FrameDisplayType display
The format to display the frame number (if any)
Definition: Clip.h:158
openshot::Keyframe volume
Curve representing the volume (0 to 1)
Definition: Clip.h:301
openshot::Keyframe scale_y
Curve representing the vertical scaling in percent (0 to 1)
Definition: Clip.h:287
Header file for the Keyframe class.
std::string Name() override
Return the type name of the class.
Definition: Clip.h:205
openshot::Keyframe shear_x
Curve representing X shear angle in degrees (-45.0=left, 45.0=right)
Definition: Clip.h:294
std::shared_ptr< openshot::TrackedObjectBase > GetAttachedObject() const
Return a pointer to the trackedObject this clip is attached to.
Definition: Clip.h:200
void SetAttachedId(std::string value)
Set id of the object id that this clip is attached to.
Definition: Clip.h:190
std::list< openshot::EffectBase * > Effects()
Return the list of effects on the timeline.
Definition: Clip.h:215
This class represents a clip (used to arrange readers on the timeline)
Definition: Clip.h:90
bool Waveform()
Get the waveform property of this clip.
Definition: Clip.h:282
openshot::Keyframe channel_filter
A number representing an audio channel to filter (clears all other channels)
Definition: Clip.h:317
openshot::Keyframe alpha
Curve representing the alpha (1 to 0)
Definition: Clip.h:290
FrameDisplayType
This enumeration determines the display format of the clip&#39;s frame number (if any). Useful for debugging.
Definition: Enums.h:51
openshot::Keyframe rotation
Curve representing the rotation (0 to 360)
Definition: Clip.h:293
openshot::Keyframe perspective_c1_x
Curves representing X for coordinate 1.
Definition: Clip.h:307
openshot::Keyframe has_audio
An optional override to determine if this clip has audio (-1=undefined, 0=no, 1=yes) ...
Definition: Clip.h:321
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:33
openshot::Keyframe perspective_c4_x
Curves representing X for coordinate 4.
Definition: Clip.h:313
openshot::Keyframe perspective_c1_y
Curves representing Y for coordinate 1.
Definition: Clip.h:308
openshot::Keyframe origin_y
Curve representing Y origin point (0.0=0% (top), 1.0=100% (bottom))
Definition: Clip.h:297
openshot::Keyframe origin_x
Curve representing X origin point (0.0=0% (left), 1.0=100% (right))
Definition: Clip.h:296
openshot::Keyframe channel_mapping
A number representing an audio channel to output (only works when filtering a channel) ...
Definition: Clip.h:318
openshot::Keyframe perspective_c2_x
Curves representing X for coordinate 2.
Definition: Clip.h:309
openshot::Keyframe perspective_c3_y
Curves representing Y for coordinate 3.
Definition: Clip.h:312
int Order() const
Get the order that this effect should be executed.
Definition: EffectBase.h:112
Header file for Color class.
AnchorType
This enumeration determines what parent a clip should be aligned to.
Definition: Enums.h:44
bool IsOpen() override
Determine if reader is open or closed.
Definition: Clip.h:185
This class represents a color (used on the timeline and clips)
Definition: Color.h:27
Header file for TextReader class.
openshot::CacheMemory * GetCache() override
Get the cache object (always return NULL for this reader)
Definition: Clip.h:182
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
Header file for EffectBase class.
std::recursive_mutex getFrameMutex
Mutex for multiple threads.
Definition: Clip.h:93
openshot::ScaleType scale
The scale determines how a clip should be resized to fit its parent.
Definition: Clip.h:156
openshot::Keyframe shear_y
Curve representing Y shear angle in degrees (-45.0=down, 45.0=up)
Definition: Clip.h:295
openshot::Keyframe location_x
Curve representing the relative X position in percent based on the gravity (-1 to 1) ...
Definition: Clip.h:288
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:86
Header file for the TrackedObjectBase class.
Header file for the EffectInfo class.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
Definition: KeyFrame.h:54
void Waveform(bool value)
Set the waveform property of this clip.
Definition: Clip.h:283
openshot::VolumeMixType mixing
What strategy should be followed when mixing audio with other clips.
Definition: Clip.h:159
openshot::AnchorType anchor
The anchor determines what parent a clip should snap to.
Definition: Clip.h:157
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:29
GravityType
This enumeration determines how clips are aligned to their parent container.
Definition: Enums.h:21
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:87
openshot::Keyframe perspective_c2_y
Curves representing Y for coordinate 2.
Definition: Clip.h:310
This class is used to resample audio data for many sequential frames.