176
178
// Generate Json::JsonValue for this object
177
Json::Value ReaderBase::JsonValue() {
179
QJsonObject ReaderBase::JsonValue() {
179
181
// Create root json object
181
183
root["has_video"] = info.has_video;
182
184
root["has_audio"] = info.has_audio;
183
185
root["has_single_image"] = info.has_single_image;
184
root["duration"] = info.duration;
185
stringstream filesize_stream;
186
filesize_stream << info.file_size;
187
root["file_size"] = filesize_stream.str();
186
root["duration"] = info.duration;
187
root["file_size"] = info.file_size;
188
188
root["height"] = info.height;
189
189
root["width"] = info.width;
190
190
root["pixel_format"] = info.pixel_format;
191
root["fps"] = Json::Value(Json::objectValue);
192
root["fps"]["num"] = info.fps.num;
193
root["fps"]["den"] = info.fps.den;
191
root["fps"] = QJsonObject();
192
root["fps"].toObject()["num"] = info.fps.num;
193
root["fps"].toObject()["den"] = info.fps.den;
194
194
root["video_bit_rate"] = info.video_bit_rate;
195
root["pixel_ratio"] = Json::Value(Json::objectValue);
196
root["pixel_ratio"]["num"] = info.pixel_ratio.num;
197
root["pixel_ratio"]["den"] = info.pixel_ratio.den;
198
root["display_ratio"] = Json::Value(Json::objectValue);
199
root["display_ratio"]["num"] = info.display_ratio.num;
200
root["display_ratio"]["den"] = info.display_ratio.den;
201
root["vcodec"] = info.vcodec;
202
stringstream video_length_stream;
203
video_length_stream << info.video_length;
204
root["video_length"] = video_length_stream.str();
195
root["pixel_ratio"] = QJsonObject();
196
root["pixel_ratio"].toObject()["num"] = info.pixel_ratio.num;
197
root["pixel_ratio"].toObject()["den"] = info.pixel_ratio.den;
198
root["display_ratio"] = QJsonObject();
199
root["display_ratio"].toObject()["num"] = info.display_ratio.num;
200
root["display_ratio"].toObject()["den"] = info.display_ratio.den;
201
root["vcodec"] = info.vcodec.c_str();
202
root["video_length"] = (long long) info.video_length;
205
203
root["video_stream_index"] = info.video_stream_index;
206
root["video_timebase"] = Json::Value(Json::objectValue);
207
root["video_timebase"]["num"] = info.video_timebase.num;
208
root["video_timebase"]["den"] = info.video_timebase.den;
204
root["video_timebase"] = QJsonObject();
205
root["video_timebase"].toObject()["num"] = info.video_timebase.num;
206
root["video_timebase"].toObject()["den"] = info.video_timebase.den;
209
207
root["interlaced_frame"] = info.interlaced_frame;
210
208
root["top_field_first"] = info.top_field_first;
211
root["acodec"] = info.acodec;
209
root["acodec"] = info.acodec.c_str();
212
210
root["audio_bit_rate"] = info.audio_bit_rate;
213
211
root["sample_rate"] = info.sample_rate;
214
212
root["channels"] = info.channels;
215
213
root["channel_layout"] = info.channel_layout;
216
214
root["audio_stream_index"] = info.audio_stream_index;
217
root["audio_timebase"] = Json::Value(Json::objectValue);
218
root["audio_timebase"]["num"] = info.audio_timebase.num;
219
root["audio_timebase"]["den"] = info.audio_timebase.den;
215
root["audio_timebase"] = QJsonObject();
216
root["audio_timebase"].toObject()["num"] = info.audio_timebase.num;
217
root["audio_timebase"].toObject()["den"] = info.audio_timebase.den;
221
219
// return JsonValue
225
223
// Load Json::JsonValue into this object
226
void ReaderBase::SetJsonValue(Json::Value root) {
224
void ReaderBase::SetJsonValue(QJsonObject root) {
228
226
// Set data from Json (if key is found)
229
227
if (!root["has_video"].isNull())
230
info.has_video = root["has_video"].asBool();
228
info.has_video = root["has_video"].toBool();
231
229
if (!root["has_audio"].isNull())
232
info.has_audio = root["has_audio"].asBool();
230
info.has_audio = root["has_audio"].toBool();
233
231
if (!root["has_single_image"].isNull())
234
info.has_single_image = root["has_single_image"].asBool();
232
info.has_single_image = root["has_single_image"].toBool();
235
233
if (!root["duration"].isNull())
236
info.duration = root["duration"].asDouble();
234
info.duration = root["duration"].toDouble();
237
235
if (!root["file_size"].isNull())
238
info.file_size = atoll(root["file_size"].asString().c_str());
236
info.file_size = root.value("file_size").toVariant().toLongLong();
239
237
if (!root["height"].isNull())
240
info.height = root["height"].asInt();
238
info.height = root["height"].toInt();
241
239
if (!root["width"].isNull())
242
info.width = root["width"].asInt();
240
info.width = root["width"].toInt();
243
241
if (!root["pixel_format"].isNull())
244
info.pixel_format = root["pixel_format"].asInt();
242
info.pixel_format = root["pixel_format"].toInt();
245
243
if (!root["fps"].isNull() && root["fps"].isObject()) {
246
if (!root["fps"]["num"].isNull())
247
info.fps.num = root["fps"]["num"].asInt();
248
if (!root["fps"]["den"].isNull())
249
info.fps.den = root["fps"]["den"].asInt();
244
if (!root["fps"].toObject()["num"].isNull())
245
info.fps.num = root["fps"].toObject()["num"].toInt();
246
if (!root["fps"].toObject()["den"].isNull())
247
info.fps.den = root["fps"].toObject()["den"].toInt();
251
249
if (!root["video_bit_rate"].isNull())
252
info.video_bit_rate = root["video_bit_rate"].asInt();
250
info.video_bit_rate = root["video_bit_rate"].toInt();
253
251
if (!root["pixel_ratio"].isNull() && root["pixel_ratio"].isObject()) {
254
if (!root["pixel_ratio"]["num"].isNull())
255
info.pixel_ratio.num = root["pixel_ratio"]["num"].asInt();
256
if (!root["pixel_ratio"]["den"].isNull())
257
info.pixel_ratio.den = root["pixel_ratio"]["den"].asInt();
252
if (!root["pixel_ratio"].toObject()["num"].isNull())
253
info.pixel_ratio.num = root["pixel_ratio"].toObject()["num"].toInt();
254
if (!root["pixel_ratio"].toObject()["den"].isNull())
255
info.pixel_ratio.den = root["pixel_ratio"].toObject()["den"].toInt();
259
257
if (!root["display_ratio"].isNull() && root["display_ratio"].isObject()) {
260
if (!root["display_ratio"]["num"].isNull())
261
info.display_ratio.num = root["display_ratio"]["num"].asInt();
262
if (!root["display_ratio"]["den"].isNull())
263
info.display_ratio.den = root["display_ratio"]["den"].asInt();
258
if (!root["display_ratio"].toObject()["num"].isNull())
259
info.display_ratio.num = root["display_ratio"].toObject()["num"].toInt();
260
if (!root["display_ratio"].toObject()["den"].isNull())
261
info.display_ratio.den = root["display_ratio"].toObject()["den"].toInt();
265
263
if (!root["vcodec"].isNull())
266
info.vcodec = root["vcodec"].asString();
264
info.vcodec = root["vcodec"].toString().toLocal8Bit().constData();
267
265
if (!root["video_length"].isNull())
268
info.video_length = atoll(root["video_length"].asString().c_str());
266
info.video_length = root.value("video_length").toVariant().toLongLong();
269
267
if (!root["video_stream_index"].isNull())
270
info.video_stream_index = root["video_stream_index"].asInt();
268
info.video_stream_index = root["video_stream_index"].toInt();
271
269
if (!root["video_timebase"].isNull() && root["video_timebase"].isObject()) {
272
if (!root["video_timebase"]["num"].isNull())
273
info.video_timebase.num = root["video_timebase"]["num"].asInt();
274
if (!root["video_timebase"]["den"].isNull())
275
info.video_timebase.den = root["video_timebase"]["den"].asInt();
270
if (!root["video_timebase"].toObject()["num"].isNull())
271
info.video_timebase.num = root["video_timebase"].toObject()["num"].toInt();
272
if (!root["video_timebase"].toObject()["den"].isNull())
273
info.video_timebase.den = root["video_timebase"].toObject()["den"].toInt();
277
275
if (!root["interlaced_frame"].isNull())
278
info.interlaced_frame = root["interlaced_frame"].asBool();
276
info.interlaced_frame = root["interlaced_frame"].toBool();
279
277
if (!root["top_field_first"].isNull())
280
info.top_field_first = root["top_field_first"].asBool();
278
info.top_field_first = root["top_field_first"].toBool();
281
279
if (!root["acodec"].isNull())
282
info.acodec = root["acodec"].asString();
280
info.acodec = root["acodec"].toString().toLocal8Bit().constData();
284
282
if (!root["audio_bit_rate"].isNull())
285
info.audio_bit_rate = root["audio_bit_rate"].asInt();
283
info.audio_bit_rate = root["audio_bit_rate"].toInt();
286
284
if (!root["sample_rate"].isNull())
287
info.sample_rate = root["sample_rate"].asInt();
285
info.sample_rate = root["sample_rate"].toInt();
288
286
if (!root["channels"].isNull())
289
info.channels = root["channels"].asInt();
287
info.channels = root["channels"].toInt();
290
288
if (!root["channel_layout"].isNull())
291
info.channel_layout = (ChannelLayout) root["channel_layout"].asInt();
289
info.channel_layout = (ChannelLayout) root["channel_layout"].toInt();
292
290
if (!root["audio_stream_index"].isNull())
293
info.audio_stream_index = root["audio_stream_index"].asInt();
291
info.audio_stream_index = root["audio_stream_index"].toInt();
294
292
if (!root["audio_timebase"].isNull() && root["audio_timebase"].isObject()) {
295
if (!root["audio_timebase"]["num"].isNull())
296
info.audio_timebase.num = root["audio_timebase"]["num"].asInt();
297
if (!root["audio_timebase"]["den"].isNull())
298
info.audio_timebase.den = root["audio_timebase"]["den"].asInt();
293
if (!root["audio_timebase"].toObject()["num"].isNull())
294
info.audio_timebase.num = root["audio_timebase"].toObject()["num"].toInt();
295
if (!root["audio_timebase"].toObject()["den"].isNull())
296
info.audio_timebase.den = root["audio_timebase"].toObject()["den"].toInt();