31 #include "../include/WriterBase.h" 103 std::cout << std::fixed << std::setprecision(2) << std::boolalpha;
104 std::cout <<
"----------------------------" << std::endl;
105 std::cout <<
"----- File Information -----" << std::endl;
106 std::cout <<
"----------------------------" << std::endl;
107 std::cout <<
"--> Has Video: " <<
info.
has_video << std::endl;
108 std::cout <<
"--> Has Audio: " <<
info.
has_audio << std::endl;
110 std::cout <<
"--> Duration: " <<
info.
duration <<
" Seconds" << std::endl;
111 std::cout <<
"--> File Size: " << double(
info.
file_size) / 1024 / 1024 <<
" MB" << std::endl;
112 std::cout <<
"----------------------------" << std::endl;
113 std::cout <<
"----- Video Attributes -----" << std::endl;
114 std::cout <<
"----------------------------" << std::endl;
115 std::cout <<
"--> Width: " <<
info.
width << std::endl;
116 std::cout <<
"--> Height: " <<
info.
height << std::endl;
119 std::cout <<
"--> Video Bit Rate: " <<
info.
video_bit_rate/1000 <<
" kb/s" << std::endl;
122 std::cout <<
"--> Video Codec: " <<
info.
vcodec << std::endl;
123 std::cout <<
"--> Video Length: " <<
info.
video_length <<
" Frames" << std::endl;
128 std::cout <<
"----------------------------" << std::endl;
129 std::cout <<
"----- Audio Attributes -----" << std::endl;
130 std::cout <<
"----------------------------" << std::endl;
131 std::cout <<
"--> Audio Codec: " <<
info.
acodec << std::endl;
132 std::cout <<
"--> Audio Bit Rate: " <<
info.
audio_bit_rate/1000 <<
" kb/s" << std::endl;
133 std::cout <<
"--> Sample Rate: " <<
info.
sample_rate <<
" Hz" << std::endl;
134 std::cout <<
"--> # of Channels: " <<
info.
channels << std::endl;
138 std::cout <<
"----------------------------" << std::endl;
157 std::stringstream filesize_stream;
159 root[
"file_size"] = filesize_stream.str();
163 root[
"fps"] = Json::Value(Json::objectValue);
167 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
170 root[
"display_ratio"] = Json::Value(Json::objectValue);
174 std::stringstream video_length_stream;
176 root[
"video_length"] = video_length_stream.str();
178 root[
"video_timebase"] = Json::Value(Json::objectValue);
189 root[
"audio_timebase"] = Json::Value(Json::objectValue);
202 Json::CharReaderBuilder rbuilder;
203 Json::CharReader* reader(rbuilder.newCharReader());
206 bool success = reader->parse( value.c_str(),
207 value.c_str() + value.size(), &root, &errors );
212 throw InvalidJSON(
"JSON could not be parsed (or is invalid)");
219 catch (
const std::exception& e)
222 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
230 if (!root[
"has_video"].isNull())
232 if (!root[
"has_audio"].isNull())
234 if (!root[
"has_single_image"].isNull())
236 if (!root[
"duration"].isNull())
238 if (!root[
"file_size"].isNull())
240 if (!root[
"height"].isNull())
242 if (!root[
"width"].isNull())
244 if (!root[
"pixel_format"].isNull())
246 if (!root[
"fps"].isNull() && root[
"fps"].isObject()) {
247 if (!root[
"fps"][
"num"].isNull())
249 if (!root[
"fps"][
"den"].isNull())
252 if (!root[
"video_bit_rate"].isNull())
254 if (!root[
"pixel_ratio"].isNull() && root[
"pixel_ratio"].isObject()) {
255 if (!root[
"pixel_ratio"][
"num"].isNull())
257 if (!root[
"pixel_ratio"][
"den"].isNull())
260 if (!root[
"display_ratio"].isNull() && root[
"display_ratio"].isObject()) {
261 if (!root[
"display_ratio"][
"num"].isNull())
263 if (!root[
"display_ratio"][
"den"].isNull())
266 if (!root[
"vcodec"].isNull())
268 if (!root[
"video_length"].isNull())
270 if (!root[
"video_stream_index"].isNull())
272 if (!root[
"video_timebase"].isNull() && root[
"video_timebase"].isObject()) {
273 if (!root[
"video_timebase"][
"num"].isNull())
275 if (!root[
"video_timebase"][
"den"].isNull())
278 if (!root[
"interlaced_frame"].isNull())
280 if (!root[
"top_field_first"].isNull())
282 if (!root[
"acodec"].isNull())
285 if (!root[
"audio_bit_rate"].isNull())
287 if (!root[
"sample_rate"].isNull())
289 if (!root[
"channels"].isNull())
291 if (!root[
"channel_layout"].isNull())
293 if (!root[
"audio_stream_index"].isNull())
295 if (!root[
"audio_timebase"].isNull() && root[
"audio_timebase"].isObject()) {
296 if (!root[
"audio_timebase"][
"num"].isNull())
298 if (!root[
"audio_timebase"][
"den"].isNull())
int channels
The number of audio channels used in the audio stream.
int num
Numerator for the fraction.
WriterInfo info
Information about the current media file.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
int video_bit_rate
The bit rate of the video stream (in bytes)
int width
The width of the video (in pixesl)
int64_t video_length
The number of frames in the video stream.
float duration
Length of time (in seconds)
void DisplayInfo()
Display file information in the standard output stream (stdout)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
WriterBase()
Constructor for WriterBase class, many things are initialized here.
This abstract class is the base class, used by all readers in libopenshot.
int width
The width of the video (in pixels)
int audio_bit_rate
The bit rate of the audio stream (in bytes)
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
bool has_video
Determines if this file has a video stream.
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
std::string Json()
Get and Set JSON methods.
int64_t file_size
Size of file (in bytes)
int64_t file_size
Size of file (in bytes)
int video_stream_index
The index of the video stream.
float duration
Length of time (in seconds)
int audio_bit_rate
The bit rate of the audio stream (in bytes)
bool has_audio
Determines if this file has an audio stream.
void SetJson(std::string value)
Load JSON string into this object.
int audio_stream_index
The index of the audio stream.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
bool top_field_first
Which interlaced field should be displayed first.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
This class represents a fraction.
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
bool has_single_image
Determines if this file only contains a single image.
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.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
openshot::ReaderInfo info
Information about the current media file.
bool has_video
Determines if this file has a video stream.
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Json::Value JsonValue()
Generate Json::JsonValue for this object.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
int audio_stream_index
The index of the audio stream.
Exception for invalid JSON.
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
int video_bit_rate
The bit rate of the video stream (in bytes)
bool has_audio
Determines if this file has an audio stream.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
std::string vcodec
The name of the video codec used to encode / decode the video stream.
int height
The height of the video (in pixels)
int den
Denominator for the fraction.
int channels
The number of audio channels used in the audio stream.
int video_stream_index
The index of the video stream.
void CopyReaderInfo(openshot::ReaderBase *reader)
This method copy's the info struct of a reader, and sets the writer with the same info...
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
bool has_single_image
Determines if this file only contains a single image.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
int sample_rate
The number of audio samples per second (44100 is a common sample rate)