2012-07-09 15:18:24 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @file
|
|
|
|
|
* @brief Header file for WriterBase class
|
2013-09-12 17:52:10 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2012-07-09 15:18:24 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
#ifndef OPENSHOT_WRITER_BASE_H
|
|
|
|
|
#define OPENSHOT_WRITER_BASE_H
|
|
|
|
|
|
2012-07-09 15:18:24 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <iomanip>
|
2015-02-05 00:02:59 -06:00
|
|
|
#include "ChannelLayouts.h"
|
2012-07-09 15:18:24 -05:00
|
|
|
#include "Fraction.h"
|
|
|
|
|
#include "Frame.h"
|
2013-09-08 16:40:57 -05:00
|
|
|
#include "ReaderBase.h"
|
2016-04-04 23:09:18 -05:00
|
|
|
#include "ZmqLogger.h"
|
2012-07-09 15:18:24 -05:00
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This struct contains info about encoding a media file, such as height, width, frames per second, etc...
|
2012-07-09 15:18:24 -05:00
|
|
|
*
|
2013-09-08 16:40:57 -05:00
|
|
|
* Each derived class of WriterBase is responsible for updating this struct to reflect accurate information
|
2012-07-09 15:18:24 -05:00
|
|
|
* about the streams.
|
|
|
|
|
*/
|
|
|
|
|
struct WriterInfo
|
|
|
|
|
{
|
2015-09-28 22:05:50 -05:00
|
|
|
bool has_video; ///< Determines if this file has a video stream
|
|
|
|
|
bool has_audio; ///< Determines if this file has an audio stream
|
|
|
|
|
bool has_single_image; ///< Determines if this file only contains a single image
|
|
|
|
|
float duration; ///< Length of time (in seconds)
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t file_size; ///< Size of file (in bytes)
|
2015-09-28 22:05:50 -05:00
|
|
|
int height; ///< The height of the video (in pixels)
|
|
|
|
|
int width; ///< The width of the video (in pixels)
|
|
|
|
|
int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...)
|
2019-08-05 02:17:22 -04:00
|
|
|
openshot::Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps)
|
2017-09-28 16:03:01 -05:00
|
|
|
int video_bit_rate; ///< The bit rate of the video stream (in bytes)
|
2019-08-05 02:17:22 -04:00
|
|
|
openshot::Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
|
|
|
|
|
openshot::Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
|
2019-08-04 21:53:29 -04:00
|
|
|
std::string vcodec; ///< The name of the video codec used to encode / decode the video stream
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t video_length; ///< The number of frames in the video stream
|
2012-07-09 15:18:24 -05:00
|
|
|
int video_stream_index; ///< The index of the video stream
|
2019-08-05 02:17:22 -04:00
|
|
|
openshot::Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen
|
2015-09-28 22:05:50 -05:00
|
|
|
bool interlaced_frame; ///< Are the contents of this frame interlaced
|
|
|
|
|
bool top_field_first; ///< Which interlaced field should be displayed first
|
2019-08-04 21:53:29 -04:00
|
|
|
std::string acodec; ///< The name of the audio codec used to encode / decode the video stream
|
2017-09-28 16:03:01 -05:00
|
|
|
int audio_bit_rate; ///< The bit rate of the audio stream (in bytes)
|
2015-09-28 22:05:50 -05:00
|
|
|
int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate)
|
|
|
|
|
int channels; ///< The number of audio channels used in the audio stream
|
2019-08-05 02:17:22 -04:00
|
|
|
openshot::ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
|
2012-07-09 15:18:24 -05:00
|
|
|
int audio_stream_index; ///< The index of the audio stream
|
2019-08-05 02:17:22 -04:00
|
|
|
openshot::Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
|
2019-08-04 21:53:29 -04:00
|
|
|
std::map<std::string, std::string> metadata; ///< An optional map/dictionary of video & audio metadata
|
2012-07-09 15:18:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This abstract class is the base class, used by writers. Writers are types of classes that encode
|
2012-07-09 15:18:24 -05:00
|
|
|
* video, audio, and image files.
|
|
|
|
|
*
|
|
|
|
|
* The only requirements for a 'writer', are to derive from this base class, and implement the
|
|
|
|
|
* WriteFrame method.
|
|
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class WriterBase
|
2012-07-09 15:18:24 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2015-02-05 00:02:59 -06:00
|
|
|
/// Constructor for WriterBase class, many things are initialized here
|
2014-08-27 09:44:27 -05:00
|
|
|
WriterBase();
|
|
|
|
|
|
2012-07-09 15:18:24 -05:00
|
|
|
/// Information about the current media file
|
|
|
|
|
WriterInfo info;
|
|
|
|
|
|
2015-02-05 00:02:59 -06:00
|
|
|
/// @brief This method copy's the info struct of a reader, and sets the writer with the same info
|
|
|
|
|
/// @param reader The source reader to copy
|
2019-08-05 02:17:22 -04:00
|
|
|
void CopyReaderInfo(openshot::ReaderBase* reader);
|
2013-07-31 12:45:47 -05:00
|
|
|
|
2015-02-05 00:02:59 -06:00
|
|
|
/// Determine if writer is open or closed
|
|
|
|
|
virtual bool IsOpen() = 0;
|
|
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
/// This method is required for all derived classes of WriterBase. Write a Frame to the video file.
|
2019-08-05 02:17:22 -04:00
|
|
|
virtual void WriteFrame(std::shared_ptr<openshot::Frame> frame) = 0;
|
2012-08-20 00:02:09 -05:00
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
/// This method is required for all derived classes of WriterBase. Write a block of frames from a reader.
|
2019-08-05 02:17:22 -04:00
|
|
|
virtual void WriteFrame(openshot::ReaderBase* reader, int64_t start, int64_t length) = 0;
|
2012-07-12 15:55:41 -05:00
|
|
|
|
2013-12-07 16:52:09 -06:00
|
|
|
/// Get and Set JSON methods
|
2019-08-04 21:53:29 -04:00
|
|
|
std::string Json(); ///< Generate JSON string of this object
|
2013-12-07 16:52:09 -06:00
|
|
|
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
2019-08-04 21:53:29 -04:00
|
|
|
void SetJson(std::string value); ///< Load JSON string into this object
|
2013-12-07 21:09:55 -06:00
|
|
|
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
2013-12-03 00:13:25 -06:00
|
|
|
|
2012-07-09 15:18:24 -05:00
|
|
|
/// Display file information in the standard output stream (stdout)
|
|
|
|
|
void DisplayInfo();
|
2014-08-27 09:44:27 -05:00
|
|
|
|
2015-02-05 00:02:59 -06:00
|
|
|
/// Open the writer (and start initializing streams)
|
|
|
|
|
virtual void Open() = 0;
|
2019-04-27 12:37:24 +02:00
|
|
|
|
|
|
|
|
virtual ~WriterBase() = default;
|
2012-07-09 15:18:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|