-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuisettings_controller.cpp
More file actions
220 lines (183 loc) · 7.15 KB
/
Copy pathuisettings_controller.cpp
File metadata and controls
220 lines (183 loc) · 7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "ffmpeg_encoder.h"
UISettingsController::UISettingsController(const EncoderInfo& encoderInfo) : encoderInfo(encoderInfo) {
InitDefaults();
}
UISettingsController::UISettingsController(const HostCodecConfigCommon& commonProps, const EncoderInfo& encoderInfo)
: commonProps(commonProps), encoderInfo(encoderInfo) {
InitDefaults();
}
void UISettingsController::Load(IPropertyProvider* values) {
uint8_t val8 = 0;
values->GetUINT8("ffmpeg_reset", val8);
if (val8 != 0) {
*this = UISettingsController(encoderInfo);
return;
}
int32_t val32 = 0;
values->GetINT32(qualityModeId.c_str(), val32);
qualityMode = static_cast<QualityMode>(val32);
SetFirstSupportedQualityMode();
values->GetINT32(qpId.c_str(), qp);
values->GetINT32(bitrateId.c_str(), bitRate);
values->GetINT32(presetId.c_str(), preset);
// external encoder options
std::string s;
if (values->GetString(extExePathId.c_str(), s)) extExePath = s;
s.clear();
if (values->GetString(extArgsId.c_str(), s)) extArgs = s;
// pass2 options
uint8_t b = 0;
values->GetUINT8(pass2EnableId.c_str(), b);
pass2Enabled = (b != 0);
s.clear();
if (values->GetString(pass2ArgsId.c_str(), s)) pass2Args = s;
}
StatusCode UISettingsController::Render(HostListRef* settingsList) const {
StatusCode err = RenderQuality(settingsList);
if (err != errNone) {
return err;
}
{
HostUIConfigEntryRef item("ffmpeg_reset");
item.MakeButton("Reset");
item.SetTriggersUpdate(true);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate the button entry");
return errFail;
}
}
return errNone;
}
void UISettingsController::InitDefaults() {
qualityMode = CRF;
SetFirstSupportedQualityMode();
qp = encoderInfo.qp[1];
bitRate = 6000;
preset = encoderInfo.defaultPreset;
const std::string prefix = std::string("ffmpeg_") + encoderInfo.encoder + "_";
qualityModeId = prefix + "q_mode";
qpId = prefix + "qp";
bitrateId = prefix + "bitrate";
presetId = prefix + "preset";
extExePathId = prefix + "ext_path";
extArgsId = prefix + "ext_args";
pass2EnableId = prefix + "pass2_enable";
pass2ArgsId = prefix + "pass2_args";
extExePath = std::string();
extArgs = std::string();
pass2Enabled = false;
pass2Args = std::string();
}
void UISettingsController::SetFirstSupportedQualityMode() {
if (!(qualityMode & encoderInfo.qualityModes)) {
if (encoderInfo.qualityModes & CRF)
qualityMode = CRF;
else if (encoderInfo.qualityModes & CQP)
qualityMode = CQP;
else if (encoderInfo.qualityModes & VBR)
qualityMode = VBR;
}
}
StatusCode UISettingsController::RenderQuality(HostListRef* settingsList) const {
{
if (!encoderInfo.encoder || std::string(encoderInfo.encoder) == "external x264") {
{
HostUIConfigEntryRef item(extExePathId);
item.MakeTextBox("External Encoder Path", extExePath, std::string());
if (!item.IsSuccess() || !settingsList->Append(&item)) return errFail;
}
{
HostUIConfigEntryRef item(extArgsId);
item.MakeTextBox("Extra Args", extArgs, std::string());
if (!item.IsSuccess() || !settingsList->Append(&item)) return errFail;
}
{
HostUIConfigEntryRef item(pass2EnableId);
item.MakeCheckBox("Two-Pass", "Enable Two Pass", pass2Enabled);
item.SetTriggersUpdate(true);
if (!item.IsSuccess() || !settingsList->Append(&item)) return errFail;
}
{
HostUIConfigEntryRef item(pass2ArgsId);
item.MakeTextBox("Two Pass Args", pass2Args, std::string());
item.SetDisabled(!pass2Enabled);
if (!item.IsSuccess() || !settingsList->Append(&item)) return errFail;
}
return errNone;
}
}
{
HostUIConfigEntryRef item(presetId);
std::vector<std::string> textsVec;
std::vector<int> valuesVec;
for (const auto& [key, value] : encoderInfo.presets) {
valuesVec.push_back(key);
textsVec.emplace_back(value);
}
item.MakeComboBox("Encoder Preset", textsVec, valuesVec, preset);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate encoder preset UI entry");
return errFail;
}
}
{
HostUIConfigEntryRef item(qualityModeId);
std::vector<std::string> textsVec;
std::vector<int> valuesVec;
if (encoderInfo.qualityModes & CRF) {
textsVec.emplace_back("Constant Rate Factor");
valuesVec.push_back(CRF);
}
if (encoderInfo.qualityModes & CQP) {
textsVec.emplace_back("Constant Quality");
valuesVec.push_back(CQP);
}
if (encoderInfo.qualityModes & VBR) {
textsVec.emplace_back("Variable Rate");
valuesVec.push_back(VBR);
}
item.MakeRadioBox("Quality Control", textsVec, valuesVec, qualityMode);
item.SetTriggersUpdate(true);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate quality UI entry");
return errFail;
}
}
{
HostUIConfigEntryRef item(qpId);
const char* pLabel = nullptr;
if (encoderInfo.hwAcceleration == Nvenc && qp == 0) {
pLabel = "(automatic)";
} else if (qp < encoderInfo.qp[2] / 3) {
pLabel = "(high)";
} else if (qp < encoderInfo.qp[2] * 2 / 3) {
pLabel = "(medium)";
} else {
pLabel = "(low)";
}
item.MakeSlider("Factor", pLabel, qp, encoderInfo.qp[0], encoderInfo.qp[2], encoderInfo.qp[1]);
item.SetTriggersUpdate(true);
item.SetHidden(qualityMode == VBR);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate qp slider UI entry");
return errFail;
}
}
{
{
HostUIConfigEntryRef item(bitrateId);
item.MakeSlider("Bit Rate", "kb/s", bitRate, 100, 100000, 1);
if (!encoderInfo.encoder || std::string(encoderInfo.encoder) != "external_x264") return errNone;
item.SetHidden(true);
item.SetHidden(qualityMode != VBR);
if (!item.IsSuccess() || !settingsList->Append(&item)) {
g_Log(logLevelError, "FFmpeg Plugin :: Failed to populate bitrate slider UI entry");
return errFail;
}
}
}
}
QualityMode UISettingsController::GetQualityMode() const { return qualityMode; }
int32_t UISettingsController::GetQP() const { return std::max<int>(0, qp); }
int32_t UISettingsController::GetBitRate() const { return bitRate * 1000; }
int32_t UISettingsController::GetPreset() const { return preset; }