Load JSON meta data about this chunk folder
| 47 | |
| 48 | // Load JSON meta data about this chunk folder |
| 49 | void ChunkReader::load_json() |
| 50 | { |
| 51 | // Load path of chunk folder |
| 52 | std::string json_path = QDir::cleanPath(QString(path.c_str()) + QDir::separator() + "info.json").toStdString(); |
| 53 | std::stringstream json_string; |
| 54 | |
| 55 | // Read the JSON file |
| 56 | std::ifstream myfile (json_path.c_str()); |
| 57 | std::string line = ""; |
| 58 | if (myfile.is_open()) |
| 59 | { |
| 60 | while (myfile.good()) |
| 61 | { |
| 62 | getline (myfile, line); |
| 63 | json_string << line; |
| 64 | } |
| 65 | myfile.close(); |
| 66 | } |
| 67 | |
| 68 | // Parse JSON string into JSON objects |
| 69 | Json::Value root; |
| 70 | Json::CharReaderBuilder rbuilder; |
| 71 | |
| 72 | std::string errors; |
| 73 | bool success = Json::parseFromStream(rbuilder, json_string, &root, &errors); |
| 74 | if (!success) |
| 75 | // Raise exception |
| 76 | throw InvalidJSON("Chunk folder could not be opened.", path); |
| 77 | |
| 78 | |
| 79 | // Set info from the JSON objects |
| 80 | try |
| 81 | { |
| 82 | info.has_video = root["has_video"].asBool(); |
| 83 | info.has_audio = root["has_audio"].asBool(); |
| 84 | info.duration = root["duration"].asDouble(); |
| 85 | info.file_size = std::stoll(root["file_size"].asString()); |
| 86 | info.height = root["height"].asInt(); |
| 87 | info.width = root["width"].asInt(); |
| 88 | info.pixel_format = root["pixel_format"].asInt(); |
| 89 | info.fps.num = root["fps"]["num"].asInt(); |
| 90 | info.fps.den = root["fps"]["den"].asInt(); |
| 91 | info.video_bit_rate = root["video_bit_rate"].asUInt(); |
| 92 | info.pixel_ratio.num = root["pixel_ratio"]["num"].asInt(); |
| 93 | info.pixel_ratio.den = root["pixel_ratio"]["den"].asInt(); |
| 94 | info.display_ratio.num = root["display_ratio"]["num"].asInt(); |
| 95 | info.display_ratio.den = root["display_ratio"]["den"].asInt(); |
| 96 | info.vcodec = root["vcodec"].asString(); |
| 97 | info.video_length = std::stoll(root["video_length"].asString()); |
| 98 | info.video_stream_index = root["video_stream_index"].asInt(); |
| 99 | info.video_timebase.num = root["video_timebase"]["num"].asInt(); |
| 100 | info.video_timebase.den = root["video_timebase"]["den"].asInt(); |
| 101 | info.interlaced_frame = root["interlaced_frame"].asBool(); |
| 102 | info.top_field_first = root["top_field_first"].asBool(); |
| 103 | info.acodec = root["acodec"].asString(); |
| 104 | info.audio_bit_rate = root["audio_bit_rate"].asUInt(); |
| 105 | info.sample_rate = root["sample_rate"].asUInt(); |
| 106 | info.channels = root["channels"].asInt(); |
nothing calls this directly
no test coverage detected