OpenShot Library | libopenshot  0.4.0
Profiles.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_PROFILE_H
14 #define OPENSHOT_PROFILE_H
15 
16 #include <iostream>
17 #include <string>
18 #include <sstream>
19 #include <math.h>
20 #include <fstream>
21 #include <QtCore/QString>
22 #include <QtCore/QStringList>
23 #include <QtCore/QFile>
24 #include <QTextStream>
25 #include <cstdio>
26 #include <cstdlib>
27 #include "Fraction.h"
28 #include "Json.h"
29 
30 namespace openshot
31 {
32 
39  struct ProfileInfo
40  {
41  std::string description;
42  int height;
43  int width;
49  bool spherical;
50  };
51 
65  class Profile
66  {
67  private:
68  std::string formattedFPS(bool include_decimal);
69 
72  friend bool operator<(const Profile& l, const Profile& r)
73  {
74  double left_fps = l.info.fps.ToDouble();
75  double right_fps = r.info.fps.ToDouble();
76  double left_pixels = l.info.width * l.info.height;
77  double right_pixels = r.info.width * r.info.height;
78  double left_dar = l.info.display_ratio.ToDouble();
79  double right_dar = r.info.display_ratio.ToDouble();
80 
81  if (left_pixels < right_pixels) {
82  // less pixels
83  return true;
84  } else {
85  if (left_fps < right_fps) {
86  // less FPS
87  return true;
88  } else {
89  if (left_dar < right_dar) {
90  // less DAR
91  return true;
92  } else {
93  return false;
94  }
95  }
96  }
97  }
98 
101  friend bool operator>(const Profile& l, const Profile& r)
102  {
103  double left_fps = l.info.fps.ToDouble();
104  double right_fps = r.info.fps.ToDouble();
105  double left_pixels = l.info.width * l.info.height;
106  double right_pixels = r.info.width * r.info.height;
107  double left_dar = l.info.display_ratio.ToDouble();
108  double right_dar = r.info.display_ratio.ToDouble();
109 
110  if (left_pixels > right_pixels) {
111  // less pixels
112  return true;
113  } else {
114  if (left_fps > right_fps) {
115  // less FPS
116  return true;
117  } else {
118  if (left_dar > right_dar) {
119  // less DAR
120  return true;
121  } else {
122  return false;
123  }
124  }
125  }
126  }
127 
129  friend bool operator==(const Profile& l, const Profile& r)
130  {
133  }
134 
135  public:
138 
140  Profile();
141 
144  Profile(std::string path);
145 
148  void Save(const std::string& file_path) const;
149 
150  std::string Key();
151  std::string ShortName();
152  std::string LongName();
153  std::string LongNameWithDesc();
154 
155  // Get and Set JSON methods
156  std::string Json() const;
157  Json::Value JsonValue() const;
158  void SetJson(const std::string value);
159  void SetJsonValue(const Json::Value root);
160  };
161 
162 }
163 
164 #endif
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:222
Fraction.h
Header file for Fraction class.
openshot::ProfileInfo::spherical
bool spherical
Is this video a spherical/360° video.
Definition: Profiles.h:49
openshot::ProfileInfo::fps
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: Profiles.h:45
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::ProfileInfo::width
int width
The width of the video (in pixels)
Definition: Profiles.h:43
openshot::ProfileInfo::height
int height
The height of the video (in pixels)
Definition: Profiles.h:42
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:46
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:30
openshot::Profile::operator==
friend bool operator==(const Profile &l, const Profile &r)
Equality operator (compare profile objects)
Definition: Profiles.h:129
openshot::ProfileInfo::pixel_format
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition: Profiles.h:44
openshot::Profile::LongName
std::string LongName()
Return a longer format name (1920x1080p @ 29.97 fps (16:9))
Definition: Profiles.cpp:203
openshot::Profile::operator<
friend bool operator<(const Profile &l, const Profile &r)
Definition: Profiles.h:72
openshot::Profile
This class loads a special text-based file called a Profile.
Definition: Profiles.h:65
openshot::ProfileInfo::interlaced_frame
bool interlaced_frame
Are the contents of this frame interlaced.
Definition: Profiles.h:48
openshot::Fraction::ToDouble
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:40
openshot::Fraction::num
int num
Numerator for the fraction.
Definition: Fraction.h:32
openshot::ProfileInfo
This struct holds profile data, typically loaded from a file.
Definition: Profiles.h:39
openshot::Fraction::den
int den
Denominator for the fraction.
Definition: Fraction.h:33
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:47
openshot::Profile::Json
std::string Json() const
Generate JSON string of this object.
Definition: Profiles.cpp:265
openshot::Profile::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Profiles.cpp:314
openshot::ProfileInfo::description
std::string description
The description of this profile.
Definition: Profiles.h:41
path
path
Definition: FFmpegWriter.cpp:1476
openshot::Profile::info
ProfileInfo info
Profile data stored here.
Definition: Profiles.h:137
openshot::Profile::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Profiles.cpp:272
openshot::Profile::operator>
friend bool operator>(const Profile &l, const Profile &r)
Definition: Profiles.h:101
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:242
openshot::Profile::ShortName
std::string ShortName()
Return the name of this profile (1920x1080p29.97)
Definition: Profiles.cpp:185
openshot::Profile::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: Profiles.cpp:297
Json.h
Header file for JSON class.
openshot::Profile::Key
std::string Key()
Return a unique key of this profile with padding (01920x1080i2997_16:09)
Definition: Profiles.cpp:163
openshot::Profile::Profile
Profile()
Default Constructor for Profile.
Definition: Profiles.cpp:20