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