OpenShot Library | libopenshot  0.3.3
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;
48  bool interlaced_frame; // Are the contents of this frame interlaced
49  };
50 
64  class Profile
65  {
66  private:
67  std::string formattedFPS(bool include_decimal);
68 
71  friend bool operator<(const Profile& l, const Profile& r)
72  {
73  double left_fps = l.info.fps.ToDouble();
74  double right_fps = r.info.fps.ToDouble();
75  double left_pixels = l.info.width * l.info.height;
76  double right_pixels = r.info.width * r.info.height;
77  double left_dar = l.info.display_ratio.ToDouble();
78  double right_dar = r.info.display_ratio.ToDouble();
79 
80  if (left_pixels < right_pixels) {
81  // less pixels
82  return true;
83  } else {
84  if (left_fps < right_fps) {
85  // less FPS
86  return true;
87  } else {
88  if (left_dar < right_dar) {
89  // less DAR
90  return true;
91  } else {
92  return false;
93  }
94  }
95  }
96  }
97 
100  friend bool operator>(const Profile& l, const Profile& r)
101  {
102  double left_fps = l.info.fps.ToDouble();
103  double right_fps = r.info.fps.ToDouble();
104  double left_pixels = l.info.width * l.info.height;
105  double right_pixels = r.info.width * r.info.height;
106  double left_dar = l.info.display_ratio.ToDouble();
107  double right_dar = r.info.display_ratio.ToDouble();
108 
109  if (left_pixels > right_pixels) {
110  // less pixels
111  return true;
112  } else {
113  if (left_fps > right_fps) {
114  // less FPS
115  return true;
116  } else {
117  if (left_dar > right_dar) {
118  // less DAR
119  return true;
120  } else {
121  return false;
122  }
123  }
124  }
125  }
126 
128  friend bool operator==(const Profile& l, const Profile& r)
129  {
132  }
133 
134  public:
137 
139  Profile();
140 
143  Profile(std::string path);
144 
147  void Save(const std::string& file_path) const;
148 
149  std::string Key();
150  std::string ShortName();
151  std::string LongName();
152  std::string LongNameWithDesc();
153 
154  // Get and Set JSON methods
155  std::string Json() const;
156  Json::Value JsonValue() const;
157  void SetJson(const std::string value);
158  void SetJsonValue(const Json::Value root);
159  };
160 
161 }
162 
163 #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:188
Fraction.h
Header file for Fraction class.
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:128
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:175
openshot::Profile::operator<
friend bool operator<(const Profile &l, const Profile &r)
Definition: Profiles.h:71
openshot::Profile
This class loads a special text-based file called a Profile.
Definition: Profiles.h:64
openshot::ProfileInfo::interlaced_frame
bool interlaced_frame
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:223
openshot::Profile::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Profiles.cpp:271
openshot::ProfileInfo::description
std::string description
The description of this profile.
Definition: Profiles.h:41
path
path
Definition: FFmpegWriter.cpp:1479
openshot::Profile::info
ProfileInfo info
Profile data stored here.
Definition: Profiles.h:136
openshot::Profile::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Profiles.cpp:230
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:201
openshot::Profile::ShortName
std::string ShortName()
Return the name of this profile (1920x1080p29.97)
Definition: Profiles.cpp:163
openshot::Profile::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: Profiles.cpp:254
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:147
openshot::Profile::Profile
Profile()
Default Constructor for Profile.
Definition: Profiles.cpp:20