Loading...
Searching...
No Matches
Profiles.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_PROFILE_H
#define OPENSHOT_PROFILE_H
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QFile>
#include <QTextStream>
#include <cstdio>
#include <cstdlib>
#include "Fraction.h"
#include "Json.h"
namespace openshot
{
struct ProfileInfo
{
std::string description;
int height;
int width;
int pixel_format;
Fraction fps;
Fraction pixel_ratio;
Fraction display_ratio;
bool interlaced_frame;
bool spherical;
};
class Profile
{
private:
std::string formattedFPS(bool include_decimal);
friend bool operator<(const Profile& l, const Profile& r)
{
double left_fps = l.info.fps.ToDouble();
double right_fps = r.info.fps.ToDouble();
double left_pixels = l.info.width * l.info.height;
double right_pixels = r.info.width * r.info.height;
double left_dar = l.info.display_ratio.ToDouble();
double right_dar = r.info.display_ratio.ToDouble();
if (left_pixels < right_pixels) {
// less pixels
return true;
} else {
if (left_fps < right_fps) {
// less FPS
return true;
} else {
if (left_dar < right_dar) {
// less DAR
return true;
} else {
return false;
}
}
}
}
friend bool operator>(const Profile& l, const Profile& r)
{
double left_fps = l.info.fps.ToDouble();
double right_fps = r.info.fps.ToDouble();
double left_pixels = l.info.width * l.info.height;
double right_pixels = r.info.width * r.info.height;
double left_dar = l.info.display_ratio.ToDouble();
double right_dar = r.info.display_ratio.ToDouble();
if (left_pixels > right_pixels) {
// less pixels
return true;
} else {
if (left_fps > right_fps) {
// less FPS
return true;
} else {
if (left_dar > right_dar) {
// less DAR
return true;
} else {
return false;
}
}
}
}
friend bool operator==(const Profile& l, const Profile& r)
{
return std::tie(l.info.width, l.info.height, l.info.fps.num, l.info.fps.den, l.info.display_ratio.num, l.info.display_ratio.den, l.info.interlaced_frame, l.info.spherical)
== std::tie(r.info.width, r.info.height, r.info.fps.num, r.info.fps.den, r.info.display_ratio.num, r.info.display_ratio.den, r.info.interlaced_frame, r.info.spherical);
}
public:
ProfileInfo info;
Profile();
Profile(std::string path);
void Save(const std::string& file_path) const;
std::string Key();
std::string ShortName();
std::string LongName();
std::string LongNameWithDesc();
// Get and Set JSON methods
std::string Json() const;
Json::Value JsonValue() const;
void SetJson(const std::string value);
void SetJsonValue(const Json::Value root);
};
}
#endif
path
path
Definition FFmpegWriter.cpp:1468
Fraction.h
Header file for Fraction class.
Json.h
Header file for JSON class.
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30
openshot::Fraction::num
int num
Numerator for the fraction.
Definition Fraction.h:32
openshot::Fraction::ToDouble
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5).
Definition Fraction.cpp:40
openshot::Fraction::den
int den
Denominator for the fraction.
Definition Fraction.h:33
openshot::Profile::LongName
std::string LongName()
Return a longer format name (1920x1080p @ 29.97 fps (16:9)).
Definition Profiles.cpp:207
openshot::Profile::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition Profiles.cpp:312
openshot::Profile::ShortName
std::string ShortName()
Return the name of this profile (1920x1080p29.97).
Definition Profiles.cpp:196
openshot::Profile::operator==
friend bool operator==(const Profile &l, const Profile &r)
Equality operator (compare profile objects).
Definition Profiles.h:128
openshot::Profile::Profile
Profile()
Default Constructor for Profile.
Definition Profiles.cpp:20
openshot::Profile::operator>
friend bool operator>(const Profile &l, const Profile &r)
Definition Profiles.h:100
openshot::Profile::Save
void Save(const std::string &file_path) const
Save profile to a text file (label=value, one per line format).
Definition Profiles.cpp:240
openshot::Profile::LongNameWithDesc
std::string LongNameWithDesc()
Return a longer format name with description (1920x1080p @ 29.97 fps (16:9) HD 1080i 29....
Definition Profiles.cpp:221
openshot::Profile::Json
std::string Json() const
Generate JSON string of this object.
Definition Profiles.cpp:263
openshot::Profile::info
ProfileInfo info
Profile data stored here.
Definition Profiles.h:136
openshot::Profile::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition Profiles.cpp:295
openshot::Profile::Key
std::string Key()
Return a unique key of this profile with padding (01920x1080i2997_16:09).
Definition Profiles.cpp:173
openshot::Profile::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition Profiles.cpp:270
openshot::Profile::operator<
friend bool operator<(const Profile &l, const Profile &r)
Definition Profiles.h:71
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::ProfileInfo
This struct holds profile data, typically loaded from a file.
Definition Profiles.h:39
openshot::ProfileInfo::description
std::string description
The description of this profile.
Definition Profiles.h:40
openshot::ProfileInfo::width
int width
The width of the video (in pixels).
Definition Profiles.h:42
openshot::ProfileInfo::interlaced_frame
bool interlaced_frame
Are the contents of this frame interlaced.
Definition Profiles.h:47
openshot::ProfileInfo::pixel_ratio
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square).
Definition Profiles.h:45
openshot::ProfileInfo::display_ratio
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3).
Definition Profiles.h:46
openshot::ProfileInfo::fps
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps).
Definition Profiles.h:44
openshot::ProfileInfo::height
int height
The height of the video (in pixels).
Definition Profiles.h:41
openshot::ProfileInfo::spherical
bool spherical
Is this video a spherical/360° video.
Definition Profiles.h:48
openshot::ProfileInfo::pixel_format
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...).
Definition Profiles.h:43