39 bool read_file =
false;
46 QFile inputFile(path.c_str());
47 if (inputFile.open(QIODevice::ReadOnly))
49 QTextStream in(&inputFile);
52 QString line = in.readLine();
54 if (line.length() <= 0)
58 QStringList parts = line.split(
"=" );
59 std::string setting = parts[0].toStdString();
60 std::string value = parts[1].toStdString();
64 if (setting ==
"description") {
67 else if (setting ==
"frame_rate_num") {
68 std::stringstream(value) >> value_int;
71 else if (setting ==
"frame_rate_den") {
72 std::stringstream(value) >> value_int;
75 else if (setting ==
"width") {
76 std::stringstream(value) >> value_int;
79 else if (setting ==
"height") {
80 std::stringstream(value) >> value_int;
83 else if (setting ==
"progressive") {
84 std::stringstream(value) >> value_int;
87 else if (setting ==
"sample_aspect_num") {
88 std::stringstream(value) >> value_int;
91 else if (setting ==
"sample_aspect_den") {
92 std::stringstream(value) >> value_int;
95 else if (setting ==
"display_aspect_num") {
96 std::stringstream(value) >> value_int;
99 else if (setting ==
"display_aspect_den") {
100 std::stringstream(value) >> value_int;
103 else if (setting ==
"colorspace") {
104 std::stringstream(value) >> value_int;
113 catch (
const std::exception& e)
116 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).", path);
122 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).", path);
126 std::string Profile::formattedFPS(
bool include_decimal) {
129 std::stringstream fps_string;
132 fps_string << std::fixed << std::setprecision(0) << fps;
135 fps_string << std::fixed << std::setprecision(2) << fps;
137 if (!include_decimal) {
138 QString fps_qstring = QString::fromStdString(fps_string.str());
139 fps_qstring.replace(
".",
"");
140 fps_string.str(fps_qstring.toStdString());
143 return fps_string.str();
148 std::stringstream output;
149 std::string progressive_str =
"p";
151 progressive_str =
"i";
153 std::string fps_string = formattedFPS(
false);
154 output << std::setfill(
'0') << std::setw(5) <<
info.
width << std::setfill(
'\0') <<
"x";
155 output << std::setfill(
'0') << std::setw(4) <<
info.
height << std::setfill(
'\0') << progressive_str;
156 output << std::setfill(
'0') << std::setw(4) << fps_string << std::setfill(
'\0') <<
"_";
157 output << std::setfill(
'0') << std::setw(2) <<
info.
display_ratio.
num << std::setfill(
'\0') <<
"-";
164 std::stringstream output;
165 std::string progressive_str =
"p";
167 progressive_str =
"i";
169 std::string fps_string = formattedFPS(
true);
176 std::stringstream output;
177 std::string progressive_str =
"p";
179 progressive_str =
"i";
181 std::string fps_string = formattedFPS(
true);
189 std::stringstream output;
190 std::string progressive_str =
"p";
192 progressive_str =
"i";
194 std::string fps_string = formattedFPS(
true);
215 root[
"fps"] = Json::Value(Json::objectValue);
218 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
221 root[
"display_ratio"] = Json::Value(Json::objectValue);
240 catch (
const std::exception& e)
243 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
250 if (!root[
"height"].isNull())
252 if (!root[
"width"].isNull())
254 if (!root[
"pixel_format"].isNull())
256 if (!root[
"fps"].isNull()) {
260 if (!root[
"pixel_ratio"].isNull()) {
264 if (!root[
"display_ratio"].isNull()) {
268 if (!root[
"interlaced_frame"].isNull())
int num
Numerator for the fraction.
ProfileInfo info
Profile data stored here.
void SetJson(const std::string value)
Load JSON string into this object.
std::string Key()
Return a unique key of this profile with padding (01920x1080i2997_16:09)
std::string ShortName()
Return the name of this profile (1920x1080p29.97)
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
std::string LongName()
Return a longer format name (1920x1080p @ 29.97 fps (16:9))
std::string description
The description of this profile.
const Json::Value stringToJson(const std::string value)
std::string LongNameWithDesc()
Return a longer format name with description (1920x1080p @ 29.97 fps (16:9) HD 1080i 29...
Profile()
Default Constructor for Profile.
std::string Json() const
Generate JSON string of this object.
Header file for all Exception classes.
Exception for files that can not be found or opened.
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
Header file for Profile class.
Json::Value JsonValue() const
Generate Json::Value for this object.
int width
The width of the video (in pixels)
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
int height
The height of the video (in pixels)
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
int den
Denominator for the fraction.