29 info.has_video =
false;
30 info.has_audio =
false;
31 info.has_single_image =
false;
36 info.pixel_format = -1;
38 info.video_bit_rate = 0;
42 info.video_length = 0;
43 info.video_stream_index = -1;
45 info.interlaced_frame =
false;
46 info.top_field_first =
true;
48 info.audio_bit_rate = 0;
52 info.audio_stream_index = -1;
93 *out << std::fixed << std::setprecision(2) << std::boolalpha;
94 *out <<
"----------------------------" << std::endl;
95 *out <<
"----- File Information -----" << std::endl;
96 *out <<
"----------------------------" << std::endl;
97 *out <<
"--> Has Video: " <<
info.has_video << std::endl;
98 *out <<
"--> Has Audio: " <<
info.has_audio << std::endl;
99 *out <<
"--> Has Single Image: " <<
info.has_single_image << std::endl;
100 *out <<
"--> Duration: " <<
info.duration <<
" Seconds" << std::endl;
101 *out <<
"--> File Size: " << double(
info.file_size) / 1024 / 1024 <<
" MB" << std::endl;
102 *out <<
"----------------------------" << std::endl;
103 *out <<
"----- Video Attributes -----" << std::endl;
104 *out <<
"----------------------------" << std::endl;
105 *out <<
"--> Width: " <<
info.width << std::endl;
106 *out <<
"--> Height: " <<
info.height << std::endl;
107 *out <<
"--> Pixel Format: " <<
info.pixel_format << std::endl;
108 *out <<
"--> Frames Per Second: " <<
info.fps.ToDouble() <<
" (" <<
info.fps.num <<
"/" <<
info.fps.den <<
")" << std::endl;
109 *out <<
"--> Video Bit Rate: " <<
info.video_bit_rate/1000 <<
" kb/s" << std::endl;
110 *out <<
"--> Pixel Ratio: " <<
info.pixel_ratio.ToDouble() <<
" (" <<
info.pixel_ratio.num <<
"/" <<
info.pixel_ratio.den <<
")" << std::endl;
111 *out <<
"--> Display Aspect Ratio: " <<
info.display_ratio.ToDouble() <<
" (" <<
info.display_ratio.num <<
"/" <<
info.display_ratio.den <<
")" << std::endl;
112 *out <<
"--> Video Codec: " <<
info.vcodec << std::endl;
113 *out <<
"--> Video Length: " <<
info.video_length <<
" Frames" << std::endl;
114 *out <<
"--> Video Stream Index: " <<
info.video_stream_index << std::endl;
115 *out <<
"--> Video Timebase: " <<
info.video_timebase.ToDouble() <<
" (" <<
info.video_timebase.num <<
"/" <<
info.video_timebase.den <<
")" << std::endl;
116 *out <<
"--> Interlaced: " <<
info.interlaced_frame << std::endl;
117 *out <<
"--> Interlaced: Top Field First: " <<
info.top_field_first << std::endl;
118 *out <<
"----------------------------" << std::endl;
119 *out <<
"----- Audio Attributes -----" << std::endl;
120 *out <<
"----------------------------" << std::endl;
121 *out <<
"--> Audio Codec: " <<
info.acodec << std::endl;
122 *out <<
"--> Audio Bit Rate: " <<
info.audio_bit_rate/1000 <<
" kb/s" << std::endl;
123 *out <<
"--> Sample Rate: " <<
info.sample_rate <<
" Hz" << std::endl;
124 *out <<
"--> # of Channels: " <<
info.channels << std::endl;
125 *out <<
"--> Channel Layout: " <<
info.channel_layout << std::endl;
126 *out <<
"--> Audio Stream Index: " <<
info.audio_stream_index << std::endl;
127 *out <<
"--> Audio Timebase: " <<
info.audio_timebase.ToDouble() <<
" (" <<
info.audio_timebase.num <<
"/" <<
info.audio_timebase.den <<
")" << std::endl;
128 *out <<
"----------------------------" << std::endl;
143 root[
"has_video"] =
info.has_video;
144 root[
"has_audio"] =
info.has_audio;
145 root[
"has_single_image"] =
info.has_single_image;
146 root[
"duration"] =
info.duration;
147 std::stringstream filesize_stream;
148 filesize_stream <<
info.file_size;
149 root[
"file_size"] = filesize_stream.str();
150 root[
"height"] =
info.height;
151 root[
"width"] =
info.width;
152 root[
"pixel_format"] =
info.pixel_format;
153 root[
"fps"] = Json::Value(Json::objectValue);
154 root[
"fps"][
"num"] =
info.fps.num;
155 root[
"fps"][
"den"] =
info.fps.den;
156 root[
"video_bit_rate"] =
info.video_bit_rate;
157 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
158 root[
"pixel_ratio"][
"num"] =
info.pixel_ratio.num;
159 root[
"pixel_ratio"][
"den"] =
info.pixel_ratio.den;
160 root[
"display_ratio"] = Json::Value(Json::objectValue);
161 root[
"display_ratio"][
"num"] =
info.display_ratio.num;
162 root[
"display_ratio"][
"den"] =
info.display_ratio.den;
163 root[
"vcodec"] =
info.vcodec;
164 std::stringstream video_length_stream;
165 video_length_stream <<
info.video_length;
166 root[
"video_length"] = video_length_stream.str();
167 root[
"video_stream_index"] =
info.video_stream_index;
168 root[
"video_timebase"] = Json::Value(Json::objectValue);
169 root[
"video_timebase"][
"num"] =
info.video_timebase.num;
170 root[
"video_timebase"][
"den"] =
info.video_timebase.den;
171 root[
"interlaced_frame"] =
info.interlaced_frame;
172 root[
"top_field_first"] =
info.top_field_first;
173 root[
"acodec"] =
info.acodec;
174 root[
"audio_bit_rate"] =
info.audio_bit_rate;
175 root[
"sample_rate"] =
info.sample_rate;
176 root[
"channels"] =
info.channels;
177 root[
"channel_layout"] =
info.channel_layout;
178 root[
"audio_stream_index"] =
info.audio_stream_index;
179 root[
"audio_timebase"] = Json::Value(Json::objectValue);
180 root[
"audio_timebase"][
"num"] =
info.audio_timebase.num;
181 root[
"audio_timebase"][
"den"] =
info.audio_timebase.den;
197 catch (
const std::exception& e)
200 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
208 if (!root[
"has_video"].isNull())
209 info.has_video = root[
"has_video"].asBool();
210 if (!root[
"has_audio"].isNull())
211 info.has_audio = root[
"has_audio"].asBool();
212 if (!root[
"has_single_image"].isNull())
213 info.has_single_image = root[
"has_single_image"].asBool();
214 if (!root[
"duration"].isNull())
215 info.duration = root[
"duration"].asDouble();
216 if (!root[
"file_size"].isNull())
217 info.file_size = (int64_t) root[
"file_size"].asUInt();
218 if (!root[
"height"].isNull())
219 info.height = root[
"height"].asInt();
220 if (!root[
"width"].isNull())
221 info.width = root[
"width"].asInt();
222 if (!root[
"pixel_format"].isNull())
223 info.pixel_format = root[
"pixel_format"].asInt();
224 if (!root[
"fps"].isNull() && root[
"fps"].isObject()) {
225 if (!root[
"fps"][
"num"].isNull())
226 info.fps.num = root[
"fps"][
"num"].asInt();
227 if (!root[
"fps"][
"den"].isNull())
228 info.fps.den = root[
"fps"][
"den"].asInt();
230 if (!root[
"video_bit_rate"].isNull())
231 info.video_bit_rate = root[
"video_bit_rate"].asInt();
232 if (!root[
"pixel_ratio"].isNull() && root[
"pixel_ratio"].isObject()) {
233 if (!root[
"pixel_ratio"][
"num"].isNull())
234 info.pixel_ratio.num = root[
"pixel_ratio"][
"num"].asInt();
235 if (!root[
"pixel_ratio"][
"den"].isNull())
236 info.pixel_ratio.den = root[
"pixel_ratio"][
"den"].asInt();
238 if (!root[
"display_ratio"].isNull() && root[
"display_ratio"].isObject()) {
239 if (!root[
"display_ratio"][
"num"].isNull())
240 info.display_ratio.num = root[
"display_ratio"][
"num"].asInt();
241 if (!root[
"display_ratio"][
"den"].isNull())
242 info.display_ratio.den = root[
"display_ratio"][
"den"].asInt();
244 if (!root[
"vcodec"].isNull())
245 info.vcodec = root[
"vcodec"].asString();
246 if (!root[
"video_length"].isNull())
247 info.video_length = (int64_t) root[
"video_length"].asUInt();
248 if (!root[
"video_stream_index"].isNull())
249 info.video_stream_index = root[
"video_stream_index"].asInt();
250 if (!root[
"video_timebase"].isNull() && root[
"video_timebase"].isObject()) {
251 if (!root[
"video_timebase"][
"num"].isNull())
252 info.video_timebase.num = root[
"video_timebase"][
"num"].asInt();
253 if (!root[
"video_timebase"][
"den"].isNull())
254 info.video_timebase.den = root[
"video_timebase"][
"den"].asInt();
256 if (!root[
"interlaced_frame"].isNull())
257 info.interlaced_frame = root[
"interlaced_frame"].asBool();
258 if (!root[
"top_field_first"].isNull())
259 info.top_field_first = root[
"top_field_first"].asBool();
260 if (!root[
"acodec"].isNull())
261 info.acodec = root[
"acodec"].asString();
263 if (!root[
"audio_bit_rate"].isNull())
264 info.audio_bit_rate = root[
"audio_bit_rate"].asInt();
265 if (!root[
"sample_rate"].isNull())
266 info.sample_rate = root[
"sample_rate"].asInt();
267 if (!root[
"channels"].isNull())
268 info.channels = root[
"channels"].asInt();
269 if (!root[
"channel_layout"].isNull())
271 if (!root[
"audio_stream_index"].isNull())
272 info.audio_stream_index = root[
"audio_stream_index"].asInt();
273 if (!root[
"audio_timebase"].isNull() && root[
"audio_timebase"].isObject()) {
274 if (!root[
"audio_timebase"][
"num"].isNull())
275 info.audio_timebase.num = root[
"audio_timebase"][
"num"].asInt();
276 if (!root[
"audio_timebase"][
"den"].isNull())
277 info.audio_timebase.den = root[
"audio_timebase"][
"den"].asInt();
Header file for all Exception classes.
Header file for Frame class.
Header file for ReaderBase class.
Header file for WriterBase class.
This class represents a fraction.
int num
Numerator for the fraction.
int den
Denominator for the fraction.
Exception for invalid JSON.
This abstract class is the base class, used by all readers in libopenshot.
openshot::ReaderInfo info
Information about the current media file.
void CopyReaderInfo(openshot::ReaderBase *reader)
This method copy's the info struct of a reader, and sets the writer with the same info.
std::string Json() const
Generate JSON string of this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Json::Value JsonValue() const
Generate Json::Value for this object.
WriterInfo info
Information about the current media file.
void SetJson(const std::string value)
Load JSON string into this object.
WriterBase()
Constructor for WriterBase class, many things are initialized here.
void DisplayInfo(std::ostream *out=&std::cout)
Display file information in the standard output stream (stdout).
This namespace is the default namespace for all code in the openshot library.
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
const Json::Value stringToJson(const std::string value)
int audio_bit_rate
The bit rate of the audio stream (in bytes).
int video_bit_rate
The bit rate of the video stream (in bytes).
bool has_single_image
Determines if this file only contains a single image.
float duration
Length of time (in seconds).
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
int width
The width of the video (in pixesl).
int channels
The number of audio channels used in the audio stream.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps).
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3).
int height
The height of the video (in pixels).
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...).
int64_t video_length
The number of frames in the video stream.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square).
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...).
bool has_video
Determines if this file has a video stream.
bool has_audio
Determines if this file has an audio stream.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
int video_stream_index
The index of the video stream.
int sample_rate
The number of audio samples per second (44100 is a common sample rate).
int audio_stream_index
The index of the audio stream.
int64_t file_size
Size of file (in bytes).