OpenShot Library | libopenshot
0.2.5
|
This class represents a single frame of video (i.e. image & audio data) More...
#include <Frame.h>
Public Member Functions | |
void | AddAudio (bool replaceSamples, int destChannel, int destStartSample, const float *source, int numSamples, float gainToApplyToSource) |
Add audio samples to a specific channel. More... | |
void | AddAudioSilence (int numSamples) |
Add audio silence. More... | |
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) More... | |
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. More... | |
void | AddImage (std::shared_ptr< QImage > new_image) |
Add (or replace) pixel data to the frame. More... | |
void | AddImage (std::shared_ptr< QImage > new_image, bool only_odd_lines) |
Add (or replace) pixel data to the frame (for only the odd or even lines) More... | |
void | AddMagickImage (std::shared_ptr< Magick::Image > new_image) |
Add (or replace) pixel data to the frame from an ImageMagick Image. More... | |
void | ApplyGainRamp (int destChannel, int destStartSample, int numSamples, float initial_gain, float final_gain) |
Apply gain ramp (i.e. fading volume) More... | |
openshot::ChannelLayout | ChannelsLayout () |
void | ChannelsLayout (openshot::ChannelLayout new_channel_layout) |
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) More... | |
void | ClearWaveform () |
Clear the waveform image (and deallocate its memory) More... | |
void | DeepCopy (const Frame &other) |
Copy data and pointers from another Frame instance. More... | |
void | Display () |
Display the frame image to the screen (primarily used for debugging reasons) More... | |
void | DisplayWaveform () |
Display the wave form. More... | |
Frame () | |
Constructor - blank frame (300x200 blank image, 48kHz audio silence) More... | |
Frame (const Frame &other) | |
Copy constructor. More... | |
Frame (int64_t number, int samples, int channels) | |
Constructor - audio only (300x200 blank image) More... | |
Frame (int64_t number, int width, int height, std::string color) | |
Constructor - image only (48kHz audio silence) More... | |
Frame (int64_t number, int width, int height, std::string color, int samples, int channels) | |
Constructor - image & audio. More... | |
int | GetAudioChannelsCount () |
Get number of audio channels. More... | |
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) More... | |
juce::AudioSampleBuffer * | GetAudioSampleBuffer () |
float * | GetAudioSamples (int channel) |
Get an array of sample data. More... | |
int | GetAudioSamplesCount () |
Get number of audio samples. More... | |
int64_t | GetBytes () |
Get the size in bytes of this frame (rough estimate) More... | |
int | GetHeight () |
Get height of image. More... | |
std::shared_ptr< QImage > | GetImage () |
Get pointer to Qt QImage image object. More... | |
float * | GetInterleavedAudioSamples (int new_sample_rate, openshot::AudioResampler *resampler, int *sample_count) |
Get an array of sample data (all channels interleaved together), using any sample rate. More... | |
std::shared_ptr< Magick::Image > | GetMagickImage () |
Get pointer to ImageMagick image object. More... | |
openshot::Fraction | GetPixelRatio () |
Set Pixel Aspect Ratio. More... | |
const unsigned char * | GetPixels () |
Get pixel data (as packets) More... | |
const unsigned char * | GetPixels (int row) |
Get pixel data (for only a single scan-line) More... | |
float * | GetPlanarAudioSamples (int new_sample_rate, openshot::AudioResampler *resampler, int *sample_count) |
int | GetSamplesPerFrame (openshot::Fraction fps, int sample_rate, int channels) |
Calculate the # of samples per video frame (for the current frame number) More... | |
std::shared_ptr< QImage > | GetWaveform (int width, int height, int Red, int Green, int Blue, int Alpha) |
Get an audio waveform image. More... | |
const unsigned char * | GetWaveformPixels (int width, int height, int Red, int Green, int Blue, int Alpha) |
Get an audio waveform image pixels. More... | |
int | GetWidth () |
Get height of image. More... | |
Frame & | operator= (const Frame &other) |
Assignment operator. More... | |
void | Play () |
Play audio samples for this frame. More... | |
void | ResizeAudio (int channels, int length, int sample_rate, openshot::ChannelLayout channel_layout) |
Resize audio container to hold more (or less) samples and channels. More... | |
int | SampleRate () |
Get the original sample rate of this frame's audio data. More... | |
void | SampleRate (int orig_sample_rate) |
Set the original sample rate of this frame's audio data. More... | |
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, PNG, PPM, XBM, XPM. More... | |
void | SetFrameNumber (int64_t number) |
Set frame number. More... | |
void | SetPixelRatio (int num, int den) |
Set Pixel Aspect Ratio. More... | |
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) |
virtual | ~Frame () |
Destructor. More... | |
Static Public Member Functions | |
static void | cleanUpBuffer (void *info) |
Clean up buffer after QImage is deleted. More... | |
static int | GetSamplesPerFrame (int64_t frame_number, openshot::Fraction fps, int sample_rate, int channels) |
Calculate the # of samples per video frame (for a specific frame number and frame rate) More... | |
Public Attributes | |
bool | has_audio_data |
This frame has been loaded with audio data. More... | |
bool | has_image_data |
This frame has been loaded with pixel data. More... | |
int64_t | number |
This is the frame number (starting at 1) More... | |
This class represents a single frame of video (i.e. image & audio data)
FileReaders (such as FFmpegReader) use instances of this class to store the individual frames of video, which include both the image data (i.e. pixels) and audio samples. An openshot::Frame also has many debug methods, such as the ability to display the image (using X11), play the audio samples (using JUCE), or display the audio waveform as an image.
FileWriters (such as FFmpegWriter) use instances of this class to create new video files, image files, or video streams. So, think of these openshot::Frame instances as the smallest unit of work in a video editor.
There are many ways to create an instance of an openshot::Frame:
Frame::Frame | ( | ) |
Frame::Frame | ( | int64_t | number, |
int | width, | ||
int | height, | ||
std::string | color | ||
) |
Frame::Frame | ( | int64_t | number, |
int | samples, | ||
int | channels | ||
) |
Frame::Frame | ( | int64_t | number, |
int | width, | ||
int | height, | ||
std::string | color, | ||
int | samples, | ||
int | channels | ||
) |
void Frame::AddAudio | ( | bool | replaceSamples, |
int | destChannel, | ||
int | destStartSample, | ||
const float * | source, | ||
int | numSamples, | ||
float | gainToApplyToSource = 1.0f |
||
) |
Add audio samples to a specific channel.
Definition at line 874 of file Frame.cpp.
Referenced by openshot::CacheDisk::GetFrame(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), and openshot::FrameMapper::ResampleMappedAudio().
void Frame::AddAudioSilence | ( | int | numSamples | ) |
Add audio silence.
Definition at line 1056 of file Frame.cpp.
Referenced by openshot::Timeline::GetFrame().
void Frame::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 at line 733 of file Frame.cpp.
Referenced by openshot::Timeline::GetFrame(), GetImage(), GetMagickImage(), GetPixels(), and openshot::ChunkWriter::WriteFrame().
void Frame::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 at line 754 of file Frame.cpp.
Referenced by AddImage(), openshot::CacheDisk::GetFrame(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), openshot::QtHtmlReader::GetFrame(), openshot::QtImageReader::GetFrame(), openshot::QtTextReader::GetFrame(), and openshot::Deinterlace::GetFrame().
void Frame::AddImage | ( | std::shared_ptr< QImage > | new_image | ) |
void Frame::AddImage | ( | std::shared_ptr< QImage > | new_image, |
bool | only_odd_lines | ||
) |
void Frame::AddMagickImage | ( | std::shared_ptr< Magick::Image > | new_image | ) |
Add (or replace) pixel data to the frame from an ImageMagick Image.
Use realloc for fast memory allocation. TODO: consider locking the buffer for mt safety
Definition at line 949 of file Frame.cpp.
Referenced by openshot::ImageReader::GetFrame(), and openshot::TextReader::GetFrame().
void Frame::ApplyGainRamp | ( | int | destChannel, |
int | destStartSample, | ||
int | numSamples, | ||
float | initial_gain = 0.0f , |
||
float | final_gain = 1.0f |
||
) |
ChannelLayout Frame::ChannelsLayout | ( | ) |
Channel Layout of audio samples. A frame needs to keep track of this, since Writers do not always know the original channel layout of a frame's audio samples (i.e. mono, stereo, 5 point surround, etc...)
Definition at line 571 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), openshot::Timeline::GetFrame(), and openshot::FrameMapper::ResampleMappedAudio().
|
inline |
bool Frame::CheckPixel | ( | int | row, |
int | col, | ||
int | red, | ||
int | green, | ||
int | blue, | ||
int | alpha, | ||
int | threshold | ||
) |
|
static |
Clean up buffer after QImage is deleted.
Definition at line 1045 of file Frame.cpp.
Referenced by AddImage(), and AddMagickImage().
void Frame::ClearWaveform | ( | ) |
Clear the waveform image (and deallocate its memory)
Definition at line 271 of file Frame.cpp.
Referenced by DisplayWaveform(), and GetWaveform().
void Frame::DeepCopy | ( | const Frame & | other | ) |
Copy data and pointers from another Frame instance.
Definition at line 105 of file Frame.cpp.
Referenced by Frame(), and operator=().
void Frame::Display | ( | ) |
int Frame::GetAudioChannelsCount | ( | ) |
Get number of audio channels.
Definition at line 432 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), and openshot::FrameMapper::ResampleMappedAudio().
float Frame::GetAudioSample | ( | int | channel, |
int | sample, | ||
int | magnitude_range | ||
) |
float * Frame::GetAudioSamples | ( | int | channel | ) |
Get an array of sample data.
Definition at line 334 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), openshot::Clip::GetFrame(), and openshot::FrameMapper::GetFrame().
int Frame::GetAudioSamplesCount | ( | ) |
Get number of audio samples.
Definition at line 442 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), GetInterleavedAudioSamples(), GetPlanarAudioSamples(), GetWaveform(), Play(), and openshot::FrameMapper::ResampleMappedAudio().
int64_t Frame::GetBytes | ( | ) |
int Frame::GetHeight | ( | ) |
Get height of image.
Definition at line 553 of file Frame.cpp.
Referenced by DeckLinkOutputDelegate::WriteFrame().
std::shared_ptr< QImage > Frame::GetImage | ( | ) |
Get pointer to Qt QImage image object.
Definition at line 913 of file Frame.cpp.
Referenced by Display(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), openshot::Bars::GetFrame(), openshot::Blur::GetFrame(), openshot::Brightness::GetFrame(), openshot::ChromaKey::GetFrame(), openshot::ColorShift::GetFrame(), openshot::Crop::GetFrame(), openshot::Deinterlace::GetFrame(), openshot::Hue::GetFrame(), openshot::Mask::GetFrame(), openshot::Negate::GetFrame(), openshot::Pixelate::GetFrame(), openshot::Saturation::GetFrame(), openshot::Shift::GetFrame(), openshot::Wave::GetFrame(), openshot::RendererBase::paint(), Save(), and Thumbnail().
float * Frame::GetInterleavedAudioSamples | ( | int | new_sample_rate, |
openshot::AudioResampler * | resampler, | ||
int * | sample_count | ||
) |
Get an array of sample data (all channels interleaved together), using any sample rate.
Definition at line 387 of file Frame.cpp.
Referenced by openshot::FrameMapper::ResampleMappedAudio().
std::shared_ptr< Magick::Image > Frame::GetMagickImage | ( | ) |
Get pointer to ImageMagick image object.
Definition at line 925 of file Frame.cpp.
Referenced by openshot::ImageWriter::WriteFrame().
|
inline |
Set Pixel Aspect Ratio.
Definition at line 235 of file Frame.h.
Referenced by openshot::ImageWriter::WriteFrame().
const unsigned char * Frame::GetPixels | ( | ) |
const unsigned char * Frame::GetPixels | ( | int | row | ) |
float * Frame::GetPlanarAudioSamples | ( | int | new_sample_rate, |
openshot::AudioResampler * | resampler, | ||
int * | sample_count | ||
) |
|
static |
int Frame::GetSamplesPerFrame | ( | openshot::Fraction | fps, |
int | sample_rate, | ||
int | channels | ||
) |
Calculate the # of samples per video frame (for the current frame number)
Definition at line 547 of file Frame.cpp.
Referenced by openshot::FrameMapper::GetFrame(), openshot::QtImageReader::GetFrame(), openshot::Timeline::GetFrame(), openshot::AudioReaderSource::getNextAudioBlock(), and openshot::FrameMapper::ResampleMappedAudio().
std::shared_ptr< QImage > Frame::GetWaveform | ( | int | width, |
int | height, | ||
int | Red, | ||
int | Green, | ||
int | Blue, | ||
int | Alpha | ||
) |
Get an audio waveform image.
Definition at line 176 of file Frame.cpp.
Referenced by DisplayWaveform(), and GetWaveformPixels().
const unsigned char * Frame::GetWaveformPixels | ( | int | width, |
int | height, | ||
int | Red, | ||
int | Green, | ||
int | Blue, | ||
int | Alpha | ||
) |
int Frame::GetWidth | ( | ) |
Get height of image.
Definition at line 559 of file Frame.cpp.
Referenced by DeckLinkOutputDelegate::WriteFrame().
void Frame::ResizeAudio | ( | int | channels, |
int | length, | ||
int | sample_rate, | ||
openshot::ChannelLayout | channel_layout | ||
) |
Resize audio container to hold more (or less) samples and channels.
Definition at line 860 of file Frame.cpp.
Referenced by openshot::CacheDisk::GetFrame(), and openshot::FrameMapper::ResampleMappedAudio().
int Frame::SampleRate | ( | ) |
Get the original sample rate of this frame's audio data.
Definition at line 565 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), openshot::Clip::GetFrame(), openshot::FrameMapper::GetFrame(), openshot::Timeline::GetFrame(), and openshot::FrameMapper::ResampleMappedAudio().
|
inline |
void Frame::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, PNG, PPM, XBM, XPM.
Definition at line 578 of file Frame.cpp.
Referenced by openshot::CacheDisk::Add(), and openshot::ChunkWriter::WriteFrame().
void Frame::SetFrameNumber | ( | int64_t | number | ) |
Set frame number.
Definition at line 517 of file Frame.cpp.
Referenced by openshot::Timeline::GetFrame().
void Frame::SetPixelRatio | ( | int | num, |
int | den | ||
) |
void Frame::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 |
||
) |
Thumbnail the frame image with tons of options to the specified path. The image format is determined from the extension (i.e. image.PNG, image.JPEG). This method allows for masks, overlays, background color, and much more accurate resizing (including padding and centering)
bool openshot::Frame::has_audio_data |
This frame has been loaded with audio data.
Definition at line 130 of file Frame.h.
Referenced by openshot::CacheDisk::Add(), AddAudio(), AddAudioSilence(), and DeepCopy().
bool openshot::Frame::has_image_data |
This frame has been loaded with pixel data.
Definition at line 131 of file Frame.h.
Referenced by AddColor(), AddImage(), AddMagickImage(), and DeepCopy().
int64_t openshot::Frame::number |
This is the frame number (starting at 1)
Definition at line 129 of file Frame.h.
Referenced by openshot::CacheDisk::Add(), openshot::CacheMemory::Add(), DeepCopy(), openshot::CacheDisk::GetFrame(), openshot::FrameMapper::GetFrame(), GetSamplesPerFrame(), openshot::FrameMapper::ResampleMappedAudio(), SetFrameNumber(), and openshot::FFmpegWriter::WriteFrame().