Loading...
Searching...
No Matches
WriterBase.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_WRITER_BASE_H
#define OPENSHOT_WRITER_BASE_H
#include <iostream>
#include "ChannelLayouts.h"
#include "Fraction.h"
#include "Json.h"
namespace openshot
{
class ReaderBase;
class Frame;
struct WriterInfo
{
bool has_video;
bool has_audio;
bool has_single_image;
float duration;
int64_t file_size;
int height;
int width;
int pixel_format;
openshot::Fraction fps;
int video_bit_rate;
openshot::Fraction pixel_ratio;
openshot::Fraction display_ratio;
std::string vcodec;
int64_t video_length;
int video_stream_index;
openshot::Fraction video_timebase;
bool interlaced_frame;
bool top_field_first;
std::string acodec;
int audio_bit_rate;
int sample_rate;
int channels;
openshot::ChannelLayout channel_layout;
int audio_stream_index;
openshot::Fraction audio_timebase;
std::map<std::string, std::string> metadata;
};
class WriterBase
{
public:
WriterBase();
WriterInfo info;
void CopyReaderInfo(openshot::ReaderBase* reader);
virtual bool IsOpen() = 0;
virtual void WriteFrame(std::shared_ptr<openshot::Frame> frame) = 0;
virtual void WriteFrame(openshot::ReaderBase* reader, int64_t start, int64_t length) = 0;
// Get and Set JSON methods
std::string Json() const;
Json::Value JsonValue() const;
void SetJson(const std::string value);
void SetJsonValue(const Json::Value root);
void DisplayInfo(std::ostream* out=&std::cout);
virtual void Open() = 0;
virtual ~WriterBase() = default;
};
}
#endif
ChannelLayouts.h
Header file for ChannelLayout class.
Fraction.h
Header file for Fraction class.
Json.h
Header file for JSON class.
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition ReaderBase.h:76
openshot::WriterBase
This abstract class is the base class, used by writers. Writers are types of classes that encode vide...
Definition WriterBase.h:70
openshot::WriterBase::CopyReaderInfo
void CopyReaderInfo(openshot::ReaderBase *reader)
This method copy's the info struct of a reader, and sets the writer with the same info.
Definition WriterBase.cpp:56
openshot::WriterBase::~WriterBase
virtual ~WriterBase()=default
openshot::WriterBase::Json
std::string Json() const
Generate JSON string of this object.
Definition WriterBase.cpp:131
openshot::WriterBase::WriteFrame
virtual void WriteFrame(std::shared_ptr< openshot::Frame > frame)=0
This method is required for all derived classes of WriterBase. Write a Frame to the video file.
openshot::WriterBase::WriteFrame
virtual void WriteFrame(openshot::ReaderBase *reader, int64_t start, int64_t length)=0
This method is required for all derived classes of WriterBase. Write a block of frames from a reader.
openshot::WriterBase::Open
virtual void Open()=0
Open the writer (and start initializing streams)
openshot::WriterBase::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition WriterBase.cpp:204
openshot::WriterBase::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition WriterBase.cpp:138
openshot::WriterBase::IsOpen
virtual bool IsOpen()=0
Determine if writer is open or closed.
openshot::WriterBase::info
WriterInfo info
Information about the current media file.
Definition WriterBase.h:76
openshot::WriterBase::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition WriterBase.cpp:187
openshot::WriterBase::WriterBase
WriterBase()
Constructor for WriterBase class, many things are initialized here.
Definition WriterBase.cpp:25
openshot::WriterBase::DisplayInfo
void DisplayInfo(std::ostream *out=&std::cout)
Display file information in the standard output stream (stdout)
Definition WriterBase.cpp:91
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
openshot::WriterInfo
This struct contains info about encoding a media file, such as height, width, frames per second,...
Definition WriterBase.h:33
openshot::WriterInfo::height
int height
The height of the video (in pixels)
Definition WriterBase.h:39
openshot::WriterInfo::audio_bit_rate
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Definition WriterBase.h:53
openshot::WriterInfo::video_bit_rate
int video_bit_rate
The bit rate of the video stream (in bytes)
Definition WriterBase.h:43
openshot::WriterInfo::has_audio
bool has_audio
Determines if this file has an audio stream.
Definition WriterBase.h:35
openshot::WriterInfo::video_length
int64_t video_length
The number of frames in the video stream.
Definition WriterBase.h:47
openshot::WriterInfo::pixel_format
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition WriterBase.h:41
openshot::WriterInfo::top_field_first
bool top_field_first
Which interlaced field should be displayed first.
Definition WriterBase.h:51
openshot::WriterInfo::duration
float duration
Length of time (in seconds)
Definition WriterBase.h:37
openshot::WriterInfo::channels
int channels
The number of audio channels used in the audio stream.
Definition WriterBase.h:55
openshot::WriterInfo::vcodec
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Definition WriterBase.h:46
openshot::WriterInfo::has_video
bool has_video
Determines if this file has a video stream.
Definition WriterBase.h:34
openshot::WriterInfo::audio_stream_index
int audio_stream_index
The index of the audio stream.
Definition WriterBase.h:57
openshot::WriterInfo::metadata
std::map< std::string, std::string > metadata
An optional map/dictionary of video & audio metadata.
Definition WriterBase.h:59
openshot::WriterInfo::fps
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition WriterBase.h:42
openshot::WriterInfo::acodec
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Definition WriterBase.h:52
openshot::WriterInfo::audio_timebase
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition WriterBase.h:58
openshot::WriterInfo::video_timebase
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition WriterBase.h:49
openshot::WriterInfo::video_stream_index
int video_stream_index
The index of the video stream.
Definition WriterBase.h:48
openshot::WriterInfo::channel_layout
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition WriterBase.h:56
openshot::WriterInfo::display_ratio
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
Definition WriterBase.h:45
openshot::WriterInfo::width
int width
The width of the video (in pixels)
Definition WriterBase.h:40
openshot::WriterInfo::pixel_ratio
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
Definition WriterBase.h:44
openshot::WriterInfo::has_single_image
bool has_single_image
Determines if this file only contains a single image.
Definition WriterBase.h:36
openshot::WriterInfo::sample_rate
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition WriterBase.h:54
openshot::WriterInfo::interlaced_frame
bool interlaced_frame
Are the contents of this frame interlaced.
Definition WriterBase.h:50
openshot::WriterInfo::file_size
int64_t file_size
Size of file (in bytes)
Definition WriterBase.h:38