OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
Frame.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_FRAME_H
14#define OPENSHOT_FRAME_H
15
16#ifdef USE_OPENCV
17 #define int64 opencv_broken_int
18 #define uint64 opencv_broken_uint
19 #include <opencv2/imgproc/imgproc.hpp>
20 #undef uint64
21 #undef int64
22#endif
23
24#include <memory>
25#include <mutex>
26
27#include "ChannelLayouts.h"
28#include "Enums.h"
29#include "Fraction.h"
30
31#include <QColor>
32#include <QImage>
33
34class QApplication;
35
36namespace juce {
37 template <typename Type> class AudioBuffer;
38}
39
40namespace openshot
41{
42 class AudioBufferSource;
43 class AudioResampler;
89 class Frame
90 {
91 private:
92 std::shared_ptr<QImage> image;
93 std::shared_ptr<QImage> wave_image;
94
95 std::shared_ptr<QApplication> previewApp;
96 std::recursive_mutex addingImageMutex;
97 std::recursive_mutex addingAudioMutex;
98 openshot::Fraction pixel_ratio;
99 int channels;
100 ChannelLayout channel_layout;
101 int width;
102 int height;
103 int sample_rate;
104 std::string color;
105 int64_t max_audio_sample;
106 bool audio_is_increasing;
107
108#ifdef USE_OPENCV
109 cv::Mat imagecv;
110#endif
111
113 int constrain(int color_value);
114
115 public:
116 std::shared_ptr<juce::AudioBuffer<float>> audio;
117 int64_t number;
121
122
124 Frame();
125
127 Frame(int64_t number, int width, int height, std::string color);
128
130 Frame(int64_t number, int samples, int channels);
131
133 Frame(int64_t number, int width, int height, std::string color, int samples, int channels);
134
136 Frame ( const Frame &other );
137
139 Frame& operator= (const Frame& other);
140
142 virtual ~Frame();
143
145 void AddColor(int new_width, int new_height, std::string new_color);
146
148 void AddColor(const QColor& new_color);
149
151 void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_);
152
154 void AddImage(std::shared_ptr<QImage> new_image);
155
157 void AddImage(std::shared_ptr<QImage> new_image, bool only_odd_lines);
158
160 void AddAudio(bool replaceSamples, int destChannel, int destStartSample, const float* source, int numSamples, float gainToApplyToSource);
161
163 void AddAudioSilence(int numSamples);
164
166 void ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain, float final_gain);
167
171
172 // Set the channel layout of audio samples (i.e. mono, stereo, 5 point surround, etc...)
173 void ChannelsLayout(openshot::ChannelLayout new_channel_layout) { channel_layout = new_channel_layout; };
174
176 void ClearWaveform();
177
179 void DeepCopy(const Frame& other);
180
182 void Display();
183
185 void DisplayWaveform();
186
188 float GetAudioSample(int channel, int sample, int magnitude_range);
189
191 float* GetAudioSamples(int channel);
192
194 float* GetInterleavedAudioSamples(int* sample_count);
195
198
201
203
205 int64_t GetBytes();
206
208 std::shared_ptr<QImage> GetImage();
209
211 openshot::Fraction GetPixelRatio() { return pixel_ratio; };
212
214 const unsigned char* GetPixels();
215
217 const unsigned char* GetPixels(int row);
218
220 bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold);
221
223 int GetHeight();
224
226 int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels);
227
229 static int GetSamplesPerFrame(int64_t frame_number, openshot::Fraction fps, int sample_rate, int channels);
230
232 std::shared_ptr<QImage> GetWaveform(int width, int height, int Red, int Green, int Blue, int Alpha);
233
235 const unsigned char* GetWaveformPixels(int width, int height, int Red, int Green, int Blue, int Alpha);
236
238 int GetWidth();
239
241 void ResizeAudio(int channels, int length, int sample_rate, openshot::ChannelLayout channel_layout);
242
244 int SampleRate();
245
247 void SampleRate(int orig_sample_rate) { sample_rate = orig_sample_rate; };
248
250 void SetAudioDirection(bool is_increasing);
251
253 void Save(std::string path, float scale, std::string format="PNG", int quality=100);
254
256 void SetFrameNumber(int64_t number);
257
259 void SetPixelRatio(int num, int den);
260
265 void Thumbnail(std::string path, int new_width, int new_height, std::string mask_path, std::string overlay_path,
266 std::string background_color, bool ignore_aspect, std::string format="png", int quality=100,
267 float rotate=0.0, ScaleType scale_mode=SCALE_FIT);
268
270 void Play();
271
272#ifdef USE_OPENCV
274 cv::Mat Qimage2mat( std::shared_ptr<QImage>& qimage);
275
277 std::shared_ptr<QImage> Mat2Qimage(cv::Mat img);
278
280 cv::Mat GetImageCV();
281
283 void SetImageCV(cv::Mat _image);
284#endif
285 };
286
287}
288
289#endif
Header file for ChannelLayout class.
Header file for TextReader class.
Header file for Fraction class.
This class represents a fraction.
Definition Fraction.h:30
This class represents a single frame of video (i.e. image & audio data)
Definition Frame.h:90
Frame & operator=(const Frame &other)
Assignment operator.
Definition Frame.cpp:78
std::shared_ptr< juce::AudioBuffer< float > > audio
Definition Frame.h:116
std::shared_ptr< QImage > Mat2Qimage(cv::Mat img)
Convert OpenCV Mat to QImage.
Definition Frame.cpp:910
void AddColor(int new_width, int new_height, std::string new_color)
Add (or replace) pixel data to the frame (based on a solid color)
Definition Frame.cpp:691
const unsigned char * GetPixels()
Get pixel data (as packets)
Definition Frame.cpp:399
void SetAudioDirection(bool is_increasing)
Set the direction of the audio buffer of this frame.
Definition Frame.cpp:820
std::shared_ptr< QImage > GetWaveform(int width, int height, int Red, int Green, int Blue, int Alpha)
Get an audio waveform image.
Definition Frame.cpp:161
void Save(std::string path, float scale, std::string format="PNG", int quality=100)
Save the frame image to the specified path. The image format can be BMP, JPG, JPEG,...
Definition Frame.cpp:517
void Display()
Display the frame image to the screen (primarily used for debugging reasons)
Definition Frame.cpp:122
int GetAudioChannelsCount()
Get number of audio channels.
Definition Frame.cpp:360
cv::Mat Qimage2mat(std::shared_ptr< QImage > &qimage)
Convert Qimage to Mat.
Definition Frame.cpp:885
bool has_image_data
This frame has been loaded with pixel data.
Definition Frame.h:120
int GetWidth()
Get height of image.
Definition Frame.cpp:498
openshot::Fraction GetPixelRatio()
Set Pixel Aspect Ratio.
Definition Frame.h:211
int SampleRate()
Get the original sample rate of this frame's audio data.
Definition Frame.cpp:504
void ResizeAudio(int channels, int length, int sample_rate, openshot::ChannelLayout channel_layout)
Resize audio container to hold more (or less) samples and channels.
Definition Frame.cpp:806
void DeepCopy(const Frame &other)
Copy data and pointers from another Frame instance.
Definition Frame.cpp:87
cv::Mat GetImageCV()
Get pointer to OpenCV Mat image object.
Definition Frame.cpp:896
void ClearWaveform()
Clear the waveform image (and deallocate its memory)
Definition Frame.cpp:253
void Play()
Play audio samples for this frame.
Definition Frame.cpp:932
void Thumbnail(std::string path, int new_width, int new_height, std::string mask_path, std::string overlay_path, std::string background_color, bool ignore_aspect, std::string format="png", int quality=100, float rotate=0.0, ScaleType scale_mode=SCALE_FIT)
Definition Frame.cpp:545
void SampleRate(int orig_sample_rate)
Set the original sample rate of this frame's audio data.
Definition Frame.h:247
float * GetInterleavedAudioSamples(int *sample_count)
Get an array of sample data (all channels interleaved together), using any sample rate.
Definition Frame.cpp:326
bool has_audio_data
This frame has been loaded with audio data.
Definition Frame.h:119
int64_t GetBytes()
Get the size in bytes of this frame (rough estimate)
Definition Frame.cpp:382
openshot::ChannelLayout ChannelsLayout()
Definition Frame.cpp:510
void AddAudioSilence(int numSamples)
Add audio silence.
Definition Frame.cpp:1003
void DisplayWaveform()
Display the wave form.
Definition Frame.cpp:270
bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold)
Check a specific pixel color value (returns True/False)
Definition Frame.cpp:423
float * GetAudioSamples(int channel)
Get an array of sample data (and optional reverse the sample values)
Definition Frame.cpp:316
float GetAudioSample(int channel, int sample, int magnitude_range)
Get magnitude of range of samples (if channel is -1, return average of all channels for that sample)
Definition Frame.cpp:303
virtual ~Frame()
Destructor.
Definition Frame.cpp:112
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
Definition Frame.cpp:486
std::shared_ptr< QImage > GetImage()
Get pointer to Qt QImage image object.
Definition Frame.cpp:872
double capture_timestamp
Optional source capture timestamp in seconds for live capture frames.
Definition Frame.h:118
void ChannelsLayout(openshot::ChannelLayout new_channel_layout)
Definition Frame.h:173
Frame()
Constructor - blank frame.
Definition Frame.cpp:59
void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_)
Add (or replace) pixel data to the frame.
Definition Frame.cpp:714
void ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain, float final_gain)
Apply gain ramp (i.e. fading volume)
Definition Frame.cpp:863
int GetAudioSamplesCount()
Get number of audio samples.
Definition Frame.cpp:370
void AddAudio(bool replaceSamples, int destChannel, int destStartSample, const float *source, int numSamples, float gainToApplyToSource)
Add audio samples to a specific channel.
Definition Frame.cpp:832
const unsigned char * GetWaveformPixels(int width, int height, int Red, int Green, int Blue, int Alpha)
Get an audio waveform image pixels.
Definition Frame.cpp:260
int GetHeight()
Get height of image.
Definition Frame.cpp:492
void SetPixelRatio(int num, int den)
Set Pixel Aspect Ratio.
Definition Frame.cpp:445
void SetFrameNumber(int64_t number)
Set frame number.
Definition Frame.cpp:452
juce::AudioBuffer< float > * GetAudioSampleBuffer()
Definition Frame.cpp:376
int64_t number
This is the frame number (starting at 1)
Definition Frame.h:117
void SetImageCV(cv::Mat _image)
Set pointer to OpenCV image object.
Definition Frame.cpp:924
This namespace is the default namespace for all code in the openshot library.
ScaleType
This enumeration determines how clips are scaled to fit their parent container.
Definition Enums.h:36
@ SCALE_FIT
Scale the clip until either height or width fills the canvas (with no cropping)
Definition Enums.h:38
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...