40 bool read_file =
false;
58 QFile inputFile(
path.c_str());
59 if (inputFile.open(QIODevice::ReadOnly))
61 QTextStream in(&inputFile);
64 QString line = in.readLine();
66 if (line.length() <= 0)
70 QStringList parts = line.split(
"=" );
71 std::string setting = parts[0].toStdString();
72 std::string value = parts[1].toStdString();
76 if (setting ==
"description") {
79 else if (setting ==
"frame_rate_num") {
80 value_int = std::stoi(value);
83 else if (setting ==
"frame_rate_den") {
84 value_int = std::stoi(value);
87 else if (setting ==
"width") {
88 value_int = std::stoi(value);
91 else if (setting ==
"height") {
92 value_int = std::stoi(value);
95 else if (setting ==
"progressive") {
96 value_int = std::stoi(value);
99 else if (setting ==
"sample_aspect_num") {
100 value_int = std::stoi(value);
103 else if (setting ==
"sample_aspect_den") {
104 value_int = std::stoi(value);
107 else if (setting ==
"display_aspect_num") {
108 value_int = std::stoi(value);
111 else if (setting ==
"display_aspect_den") {
112 value_int = std::stoi(value);
115 else if (setting ==
"colorspace") {
116 value_int = std::stoi(value);
119 else if (setting ==
"spherical") {
120 value_int = std::stoi(value);
129 catch (
const std::exception& e)
132 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
138 throw InvalidFile(
"Profile could not be found or loaded (or is invalid).",
path);
142std::string Profile::formattedFPS(
bool include_decimal) {
144 if (!include_decimal) {
156 std::snprintf(buffer,
sizeof(buffer),
"%04d", fps_code);
157 return std::string(buffer);
163 if (std::fabs(fps - std::round(fps)) < 0.01) {
164 return std::to_string(
static_cast<int>(std::round(fps)));
168 std::snprintf(buffer,
sizeof(buffer),
"%.2f", fps);
169 return std::string(buffer);
174 std::string raw_fps = formattedFPS(
false);
177 std::string fps_padded = std::string(4 - raw_fps.length(),
'0') + raw_fps;
180 std::snprintf(buffer,
sizeof(buffer),
"%05dx%04d%s%s_%02d-%02d",
189 std::string result(buffer);
198 std::string fps_string = formattedFPS(
true);
199 std::string result = std::to_string(
info.
width) +
"x" + std::to_string(
info.
height) + progressive_str + fps_string;
209 std::string fps_string = formattedFPS(
true);
211 progressive_str +
" @ " + fps_string +
223 std::string fps_string = formattedFPS(
true);
226 progressive_str +
" @ " + fps_string +
241 std::ofstream file(file_path);
242 if (!file.is_open()) {
243 throw std::ios_base::failure(
"Failed to save profile.");
247 file <<
"frame_rate_num=" <<
info.
fps.
num <<
"\n";
248 file <<
"frame_rate_den=" <<
info.
fps.
den <<
"\n";
278 root[
"fps"] = Json::Value(Json::objectValue);
281 root[
"pixel_ratio"] = Json::Value(Json::objectValue);
284 root[
"display_ratio"] = Json::Value(Json::objectValue);
304 catch (
const std::exception& e)
307 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
314 if (!root[
"description"].isNull())
316 if (!root[
"height"].isNull())
318 if (!root[
"width"].isNull())
320 if (!root[
"pixel_format"].isNull())
322 if (!root[
"fps"].isNull()) {
326 if (!root[
"pixel_ratio"].isNull()) {
331 if (!root[
"display_ratio"].isNull()) {
336 if (!root[
"progressive"].isNull())
338 if (!root[
"spherical"].isNull())
Header file for all Exception classes.
Header file for Profile class.
int num
Numerator for the fraction.
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
int den
Denominator for the fraction.
Exception for files that can not be found or opened.
Exception for invalid JSON.
std::string LongName()
Return a longer format name (1920x1080p @ 29.97 fps (16:9))
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
std::string ShortName()
Return the name of this profile (1920x1080p29.97)
Profile()
Default Constructor for Profile.
void Save(const std::string &file_path) const
Save profile to a text file (label=value, one per line format)
std::string LongNameWithDesc()
Return a longer format name with description (1920x1080p @ 29.97 fps (16:9) HD 1080i 29....
std::string Json() const
Generate JSON string of this object.
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)
Json::Value JsonValue() const
Generate Json::Value for this object.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)
std::string description
The description of this profile.
int width
The width of the video (in pixels)
bool interlaced_frame
Are the contents of this frame interlaced.
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
int height
The height of the video (in pixels)
bool spherical
Is this video a spherical/360° video.
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)