OpenShot Library | libopenshot 0.2.7
WriterBase.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Header file for WriterBase class
4 * @author Jonathan Thomas <jonathan@openshot.org>
5 *
6 * @ref License
7 */
8
9/* LICENSE
10 *
11 * Copyright (c) 2008-2019 OpenShot Studios, LLC
12 * <http://www.openshotstudios.com/>. This file is part of
13 * OpenShot Library (libopenshot), an open-source project dedicated to
14 * delivering high quality video editing and animation solutions to the
15 * world. For more information visit <http://www.openshot.org/>.
16 *
17 * OpenShot Library (libopenshot) is free software: you can redistribute it
18 * and/or modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation, either version 3 of the
20 * License, or (at your option) any later version.
21 *
22 * OpenShot Library (libopenshot) is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef OPENSHOT_WRITER_BASE_H
32#define OPENSHOT_WRITER_BASE_H
33
34#include <iostream>
35#include <iomanip>
36#include "ChannelLayouts.h"
37#include "Fraction.h"
38#include "Frame.h"
39#include "ReaderBase.h"
40#include "ZmqLogger.h"
41
42namespace openshot
43{
44 /**
45 * @brief This struct contains info about encoding a media file, such as height, width, frames per second, etc...
46 *
47 * Each derived class of WriterBase is responsible for updating this struct to reflect accurate information
48 * about the streams.
49 */
51 {
52 bool has_video; ///< Determines if this file has a video stream
53 bool has_audio; ///< Determines if this file has an audio stream
54 bool has_single_image; ///< Determines if this file only contains a single image
55 float duration; ///< Length of time (in seconds)
56 int64_t file_size; ///< Size of file (in bytes)
57 int height; ///< The height of the video (in pixels)
58 int width; ///< The width of the video (in pixels)
59 int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...)
60 openshot::Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps)
61 int video_bit_rate; ///< The bit rate of the video stream (in bytes)
62 openshot::Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
63 openshot::Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
64 std::string vcodec; ///< The name of the video codec used to encode / decode the video stream
65 int64_t video_length; ///< The number of frames in the video stream
66 int video_stream_index; ///< The index of the video stream
67 openshot::Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen
68 bool interlaced_frame; ///< Are the contents of this frame interlaced
69 bool top_field_first; ///< Which interlaced field should be displayed first
70 std::string acodec; ///< The name of the audio codec used to encode / decode the video stream
71 int audio_bit_rate; ///< The bit rate of the audio stream (in bytes)
72 int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate)
73 int channels; ///< The number of audio channels used in the audio stream
74 openshot::ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
75 int audio_stream_index; ///< The index of the audio stream
76 openshot::Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
77 std::map<std::string, std::string> metadata; ///< An optional map/dictionary of video & audio metadata
78 };
79
80 /**
81 * @brief This abstract class is the base class, used by writers. Writers are types of classes that encode
82 * video, audio, and image files.
83 *
84 * The only requirements for a 'writer', are to derive from this base class, and implement the
85 * WriteFrame method.
86 */
88 {
89 public:
90 /// Constructor for WriterBase class, many things are initialized here
91 WriterBase();
92
93 /// Information about the current media file
95
96 /// @brief This method copy's the info struct of a reader, and sets the writer with the same info
97 /// @param reader The source reader to copy
99
100 /// Determine if writer is open or closed
101 virtual bool IsOpen() = 0;
102
103 /// This method is required for all derived classes of WriterBase. Write a Frame to the video file.
104 virtual void WriteFrame(std::shared_ptr<openshot::Frame> frame) = 0;
105
106 /// This method is required for all derived classes of WriterBase. Write a block of frames from a reader.
107 virtual void WriteFrame(openshot::ReaderBase* reader, int64_t start, int64_t length) = 0;
108
109 // Get and Set JSON methods
110 std::string Json() const; ///< Generate JSON string of this object
111 Json::Value JsonValue() const; ///< Generate Json::Value for this object
112 void SetJson(const std::string value); ///< Load JSON string into this object
113 void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
114
115 /// Display file information in the standard output stream (stdout)
116 void DisplayInfo();
117
118 /// Open the writer (and start initializing streams)
119 virtual void Open() = 0;
120
121 virtual ~WriterBase() = default;
122 };
123
124}
125
126#endif
Header file for ChannelLayout class.
Header file for Fraction class.
Header file for Frame class.
Header file for ReaderBase class.
Header file for ZeroMQ-based Logger class.
This class represents a fraction.
Definition: Fraction.h:48
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
This abstract class is the base class, used by writers. Writers are types of classes that encode vide...
Definition: WriterBase.h:88
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:68
virtual ~WriterBase()=default
std::string Json() const
Generate JSON string of this object.
Definition: WriterBase.cpp:143
void DisplayInfo()
Display file information in the standard output stream (stdout)
Definition: WriterBase.cpp:103
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.
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.
virtual void Open()=0
Open the writer (and start initializing streams)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: WriterBase.cpp:216
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: WriterBase.cpp:150
virtual bool IsOpen()=0
Determine if writer is open or closed.
WriterInfo info
Information about the current media file.
Definition: WriterBase.h:94
void SetJson(const std::string value)
Load JSON string into this object.
Definition: WriterBase.cpp:199
WriterBase()
Constructor for WriterBase class, many things are initialized here.
Definition: WriterBase.cpp:37
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
This struct contains info about encoding a media file, such as height, width, frames per second,...
Definition: WriterBase.h:51
int height
The height of the video (in pixels)
Definition: WriterBase.h:57
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Definition: WriterBase.h:71
int video_bit_rate
The bit rate of the video stream (in bytes)
Definition: WriterBase.h:61
bool has_audio
Determines if this file has an audio stream.
Definition: WriterBase.h:53
int64_t video_length
The number of frames in the video stream.
Definition: WriterBase.h:65
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition: WriterBase.h:59
bool top_field_first
Which interlaced field should be displayed first.
Definition: WriterBase.h:69
float duration
Length of time (in seconds)
Definition: WriterBase.h:55
int channels
The number of audio channels used in the audio stream.
Definition: WriterBase.h:73
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Definition: WriterBase.h:64
bool has_video
Determines if this file has a video stream.
Definition: WriterBase.h:52
int audio_stream_index
The index of the audio stream.
Definition: WriterBase.h:75
std::map< std::string, std::string > metadata
An optional map/dictionary of video & audio metadata.
Definition: WriterBase.h:77
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: WriterBase.h:60
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Definition: WriterBase.h:70
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition: WriterBase.h:76
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition: WriterBase.h:67
int video_stream_index
The index of the video stream.
Definition: WriterBase.h:66
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition: WriterBase.h:74
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:63
int width
The width of the video (in pixels)
Definition: WriterBase.h:58
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
Definition: WriterBase.h:62
bool has_single_image
Determines if this file only contains a single image.
Definition: WriterBase.h:54
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition: WriterBase.h:72
bool interlaced_frame
Are the contents of this frame interlaced.
Definition: WriterBase.h:68
int64_t file_size
Size of file (in bytes)
Definition: WriterBase.h:56