Loading...
Searching...
No Matches
Frame.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_FRAME_H
#define OPENSHOT_FRAME_H
#ifdef USE_OPENCV
#define int64 opencv_broken_int
#define uint64 opencv_broken_uint
#include <opencv2/imgproc/imgproc.hpp>
#undef uint64
#undef int64
#endif
#include <memory>
#include <mutex>
#include "ChannelLayouts.h"
#include "Fraction.h"
#include <QColor>
#include <QImage>
class QApplication;
namespace juce {
template <typename Type> class AudioBuffer;
}
namespace openshot
{
class AudioBufferSource;
class AudioResampler;
class Frame
{
private:
std::shared_ptr<QImage> image;
std::shared_ptr<QImage> wave_image;
std::shared_ptr<QApplication> previewApp;
std::recursive_mutex addingImageMutex;
std::recursive_mutex addingAudioMutex;
openshot::Fraction pixel_ratio;
int channels;
ChannelLayout channel_layout;
int width;
int height;
int sample_rate;
std::string color;
int64_t max_audio_sample;
bool audio_is_increasing;
#ifdef USE_OPENCV
cv::Mat imagecv;
#endif
int constrain(int color_value);
public:
std::shared_ptr<juce::AudioBuffer<float>> audio;
int64_t number;
bool has_audio_data;
bool has_image_data;
Frame();
Frame(int64_t number, int width, int height, std::string color);
Frame(int64_t number, int samples, int channels);
Frame(int64_t number, int width, int height, std::string color, int samples, int channels);
Frame ( const Frame &other );
Frame& operator= (const Frame& other);
virtual ~Frame();
void AddColor(int new_width, int new_height, std::string new_color);
void AddColor(const QColor& new_color);
void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_);
void AddImage(std::shared_ptr<QImage> new_image);
void AddImage(std::shared_ptr<QImage> new_image, bool only_odd_lines);
void AddAudio(bool replaceSamples, int destChannel, int destStartSample, const float* source, int numSamples, float gainToApplyToSource);
void AddAudioSilence(int numSamples);
void ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain, float final_gain);
openshot::ChannelLayout ChannelsLayout();
// Set the channel layout of audio samples (i.e. mono, stereo, 5 point surround, etc...)
void ChannelsLayout(openshot::ChannelLayout new_channel_layout) { channel_layout = new_channel_layout; };
void ClearWaveform();
void DeepCopy(const Frame& other);
void Display();
void DisplayWaveform();
float GetAudioSample(int channel, int sample, int magnitude_range);
float* GetAudioSamples(int channel);
float* GetInterleavedAudioSamples(int* sample_count);
int GetAudioChannelsCount();
int GetAudioSamplesCount();
juce::AudioBuffer<float> *GetAudioSampleBuffer();
int64_t GetBytes();
std::shared_ptr<QImage> GetImage();
openshot::Fraction GetPixelRatio() { return pixel_ratio; };
const unsigned char* GetPixels();
const unsigned char* GetPixels(int row);
bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold);
int GetHeight();
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels);
static int GetSamplesPerFrame(int64_t frame_number, openshot::Fraction fps, int sample_rate, int channels);
std::shared_ptr<QImage> GetWaveform(int width, int height, int Red, int Green, int Blue, int Alpha);
const unsigned char* GetWaveformPixels(int width, int height, int Red, int Green, int Blue, int Alpha);
int GetWidth();
void ResizeAudio(int channels, int length, int sample_rate, openshot::ChannelLayout channel_layout);
int SampleRate();
void SampleRate(int orig_sample_rate) { sample_rate = orig_sample_rate; };
void SetAudioDirection(bool is_increasing);
void Save(std::string path, float scale, std::string format="PNG", int quality=100);
void SetFrameNumber(int64_t number);
void SetPixelRatio(int num, int den);
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);
void Play();
#ifdef USE_OPENCV
cv::Mat Qimage2mat( std::shared_ptr<QImage>& qimage);
std::shared_ptr<QImage> Mat2Qimage(cv::Mat img);
cv::Mat GetImageCV();
void SetImageCV(cv::Mat _image);
#endif
};
}
#endif
ChannelLayouts.h
Header file for ChannelLayout class.
path
path
Definition FFmpegWriter.cpp:1468
Fraction.h
Header file for Fraction class.
juce::AudioBuffer
Definition Frame.h:36
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30
openshot::Frame
This class represents a single frame of video (i.e. image & audio data).
Definition Frame.h:89
openshot::Frame::operator=
Frame & operator=(const Frame &other)
Assignment operator.
Definition Frame.cpp:77
openshot::Frame::audio
std::shared_ptr< juce::AudioBuffer< float > > audio
Definition Frame.h:115
openshot::Frame::Mat2Qimage
std::shared_ptr< QImage > Mat2Qimage(cv::Mat img)
Convert OpenCV Mat to QImage.
Definition Frame.cpp:896
openshot::Frame::AddColor
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:677
openshot::Frame::GetPixels
const unsigned char * GetPixels()
Get pixel data (as packets).
Definition Frame.cpp:397
openshot::Frame::SetAudioDirection
void SetAudioDirection(bool is_increasing)
Set the direction of the audio buffer of this frame.
Definition Frame.cpp:806
openshot::Frame::GetWaveform
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:159
openshot::Frame::Save
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:515
openshot::Frame::Display
void Display()
Display the frame image to the screen (primarily used for debugging reasons).
Definition Frame.cpp:120
openshot::Frame::GetAudioChannelsCount
int GetAudioChannelsCount()
Get number of audio channels.
Definition Frame.cpp:358
openshot::Frame::Qimage2mat
cv::Mat Qimage2mat(std::shared_ptr< QImage > &qimage)
Convert Qimage to Mat.
Definition Frame.cpp:871
openshot::Frame::has_image_data
bool has_image_data
This frame has been loaded with pixel data.
Definition Frame.h:118
openshot::Frame::GetWidth
int GetWidth()
Get height of image.
Definition Frame.cpp:496
openshot::Frame::GetPixelRatio
openshot::Fraction GetPixelRatio()
Set Pixel Aspect Ratio.
Definition Frame.h:209
openshot::Frame::SampleRate
int SampleRate()
Get the original sample rate of this frame's audio data.
Definition Frame.cpp:502
openshot::Frame::ResizeAudio
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:792
openshot::Frame::DeepCopy
void DeepCopy(const Frame &other)
Copy data and pointers from another Frame instance.
Definition Frame.cpp:86
openshot::Frame::GetImageCV
cv::Mat GetImageCV()
Get pointer to OpenCV Mat image object.
Definition Frame.cpp:882
openshot::Frame::ClearWaveform
void ClearWaveform()
Clear the waveform image (and deallocate its memory).
Definition Frame.cpp:251
openshot::Frame::Play
void Play()
Play audio samples for this frame.
Definition Frame.cpp:918
openshot::Frame::SampleRate
void SampleRate(int orig_sample_rate)
Set the original sample rate of this frame's audio data.
Definition Frame.h:245
openshot::Frame::GetInterleavedAudioSamples
float * GetInterleavedAudioSamples(int *sample_count)
Get an array of sample data (all channels interleaved together), using any sample rate.
Definition Frame.cpp:324
openshot::Frame::has_audio_data
bool has_audio_data
This frame has been loaded with audio data.
Definition Frame.h:117
openshot::Frame::GetBytes
int64_t GetBytes()
Get the size in bytes of this frame (rough estimate).
Definition Frame.cpp:380
openshot::Frame::ChannelsLayout
openshot::ChannelLayout ChannelsLayout()
Definition Frame.cpp:508
openshot::Frame::AddAudioSilence
void AddAudioSilence(int numSamples)
Add audio silence.
Definition Frame.cpp:989
openshot::Frame::Thumbnail
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)
Definition Frame.cpp:543
openshot::Frame::DisplayWaveform
void DisplayWaveform()
Display the wave form.
Definition Frame.cpp:268
openshot::Frame::CheckPixel
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:421
openshot::Frame::GetAudioSamples
float * GetAudioSamples(int channel)
Get an array of sample data (and optional reverse the sample values).
Definition Frame.cpp:314
openshot::Frame::GetAudioSample
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:301
openshot::Frame::~Frame
virtual ~Frame()
Destructor.
Definition Frame.cpp:110
openshot::Frame::GetSamplesPerFrame
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:484
openshot::Frame::GetImage
std::shared_ptr< QImage > GetImage()
Get pointer to Qt QImage image object.
Definition Frame.cpp:858
openshot::Frame::ChannelsLayout
void ChannelsLayout(openshot::ChannelLayout new_channel_layout)
Definition Frame.h:171
openshot::Frame::Frame
Frame()
Constructor - blank frame.
Definition Frame.cpp:58
openshot::Frame::AddImage
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:700
openshot::Frame::ApplyGainRamp
void ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain, float final_gain)
Apply gain ramp (i.e. fading volume).
Definition Frame.cpp:849
openshot::Frame::GetAudioSamplesCount
int GetAudioSamplesCount()
Get number of audio samples.
Definition Frame.cpp:368
openshot::Frame::AddAudio
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:818
openshot::Frame::GetWaveformPixels
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:258
openshot::Frame::GetHeight
int GetHeight()
Get height of image.
Definition Frame.cpp:490
openshot::Frame::SetPixelRatio
void SetPixelRatio(int num, int den)
Set Pixel Aspect Ratio.
Definition Frame.cpp:443
openshot::Frame::SetFrameNumber
void SetFrameNumber(int64_t number)
Set frame number.
Definition Frame.cpp:450
openshot::Frame::GetAudioSampleBuffer
juce::AudioBuffer< float > * GetAudioSampleBuffer()
Definition Frame.cpp:374
openshot::Frame::number
int64_t number
This is the frame number (starting at 1).
Definition Frame.h:116
openshot::Frame::SetImageCV
void SetImageCV(cv::Mat _image)
Set pointer to OpenCV image object.
Definition Frame.cpp:910
juce
Definition Robotization.h:29
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::ChannelLayout
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
Definition ChannelLayouts.h:29