OpenShot Library | libopenshot  0.1.9
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  };
77 
78  /**
79  * @brief This abstract class is the base class, used by writers. Writers are types of classes that encode
80  * video, audio, and image files.
81  *
82  * The only requirements for a 'writer', are to derive from this base class, and implement the
83  * WriteFrame method.
84  */
85  class WriterBase
86  {
87  public:
88  /// Constructor for WriterBase class, many things are initialized here
89  WriterBase();
90 
91  /// Information about the current media file
93 
94  /// @brief This method copy's the info struct of a reader, and sets the writer with the same info
95  /// @param reader The source reader to copy
96  void CopyReaderInfo(ReaderBase* reader);
97 
98  /// Determine if writer is open or closed
99  virtual bool IsOpen() = 0;
100 
101  /// This method is required for all derived classes of WriterBase. Write a Frame to the video file.
102  virtual void WriteFrame(std::shared_ptr<Frame> frame) = 0;
103 
104  /// This method is required for all derived classes of WriterBase. Write a block of frames from a reader.
105  virtual void WriteFrame(ReaderBase* reader, int64_t start, int64_t length) = 0;
106 
107  /// Get and Set JSON methods
108  string Json(); ///< Generate JSON string of this object
109  Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
110  void SetJson(string value); ///< Load JSON string into this object
111  void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
112 
113  /// Display file information in the standard output stream (stdout)
114  void DisplayInfo();
115 
116  /// Open the writer (and start initializing streams)
117  virtual void Open() = 0;
118  };
119 
120 }
121 
122 #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:92
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
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:95
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:85
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
This namespace is the default namespace for all code in the openshot library.
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