-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetInfo.cpp
203 lines (186 loc) · 7.34 KB
/
getInfo.cpp
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
#include "mainwindow.h"
int getNumFrameFinished(QProcess* process) {
QString output = readStdOutput(process);
if (output.contains("frame="))
output = output.remove(output.indexOf("fps"), output.length()).remove("frame=");
return output.toInt();
}
double getDuration(QFileInfo file) {
QMediaPlayer* player = new QMediaPlayer;
player->setSource(QUrl(file.absoluteFilePath()));
QMediaMetaData metaData(player->metaData());
delete player;
return qvariant_cast<double>(QVariant(metaData.value(QMediaMetaData::Duration))) / 1000.0;
}
QStringList getGPUID(QString output) {
QStringList list = output.split("\n[");
for (int i = 0; i < list.length(); i++) {
list[i] = list[i].remove(list[i].indexOf(']'), list[i].length()).remove('[');
list[i] = list[i].insert(0, '[');
list[i] = list[i].insert(2, ']');
}
list.removeDuplicates();
return list;
}
QString MainWindow::getParameter(QString para) {
if (para == "model") {
if (ui->comboBox_Engine->currentIndex() == 0) {
QString x;
switch (ui->comboBox_Model->currentIndex()) {
case 0:
x = " -s ";
if (ui->comboBox_Res->currentText() == "--") {
resizingNeeded = true;
if (res[0] * 2 > ui->lineEdit_Res->text().toInt()) x += "2";
else if (res[0] * 3 > ui->lineEdit_Res->text().toInt()) x += "3";
else x += "4";
}
else if (ui->comboBox_Res->currentText() == "x1") {
resizingNeeded = true;
x += "2";
scale = 2;
}
else {
resizingNeeded = false;
x += ui->comboBox_Res->currentText().remove('x');
}
return " -n " + ui->comboBox_Model->currentText() + x;
case 1: case 2: case 3: case 4: case 5:
if (ui->comboBox_Res->currentText() == "x4") resizingNeeded = false;
else {
resizingNeeded = true;
scale = 4;
}
return " -n " + ui->comboBox_Model->currentText();
default:
QString modelName;
QDir modelsDir = QDir(currentPath + "/realesrgan-ncnn-vulkan/models");
foreach (QString model, modelsDir.entryList(QDir::Files)) {
if (model.contains(".bin") && model.sliced(3, model.length() - 7) == ui->comboBox_Model->currentText()) {
modelName = model.remove(".bin");
break;
}
}
x += modelName[0];
if (ui->comboBox_Res->currentText().remove("x") == x) resizingNeeded = false;
else {
resizingNeeded = true;
scale = x.toInt();
}
return " -n " + modelName + " -s " + x;
}
}
else {
QString x = " -s ";
if (ui->comboBox_Res->currentText() == "--") {
resizingNeeded = true;
if (res[0] * 2 > ui->lineEdit_Res->text().toInt()) x += "2";
else if (res[0] * 3 > ui->lineEdit_Res->text().toInt()) x += "3";
else x += "4";
}
else if (ui->comboBox_Res->currentText() == "x1") {
resizingNeeded = true;
x += "2";
scale = 2;
}
else {
resizingNeeded = false;
x += ui->comboBox_Res->currentText().remove('x');
}
return " -m " + ui->comboBox_Model->currentText() + x;
}
}
else if (para == "gpuid") {
if (ui->comboBox_GpuID->currentText() != "")
return " -g " + ui->comboBox_GpuID->currentText();
else return "";
}
else if (para == "thread") {
if (ui->lineEdit_Thread->text() != "")
return " -j " + ui->lineEdit_Thread->text();
else return "";
}
else {
if (ui->comboBox_Engine->currentIndex() == 1)
return " -n " + QString::number(ui->comboBox_Denoise->currentIndex() - 1) + " -c " + QString::number(ui->comboBox_SyncGap->currentIndex());
else return "";
}
}
QString MainWindow::getVCodec() {
if (ui->comboBox_VCodec->currentIndex() == 0) return " -c:v libx264 -vtag avc1";
else return " -c:v libx265 -vtag hvc1";
}
QString MainWindow::getScaleFilter() {
QString scaleFilter;
if (resizingNeeded && ui->comboBox_Tool->currentIndex() == 0) {
scaleFilter = " -vf scale=";
if (ui->comboBox_Res->currentIndex() == 0) scaleFilter += ui->lineEdit_Res->text() + ":" + ui->lineEdit_Res_2->text();
else {
int t = ui->comboBox_Res->currentText().remove("x").QString::toInt();
switch (scale) {
case 1:
switch (t) {
case 2: scaleFilter += "iw*2:ih*2"; break;
case 3: scaleFilter += "iw*3:ih*3"; break;
case 4: scaleFilter += "iw*4:ih*4"; break;
}
break;
case 2:
switch (t) {
case 1: scaleFilter += "iw*0.5:ih*0.5"; break;
case 3: scaleFilter += "iw*1.5:ih*1.5"; break;
case 4: scaleFilter += "iw*2:ih*2"; break;
}
break;
case 4:
switch (t) {
case 1: scaleFilter += "iw*0.25:ih*0.25"; break;
case 2: scaleFilter += "iw*0.5:ih*0.5"; break;
case 3: scaleFilter += "iw*0.75:ih*0.75"; break;
}
}
}
scaleFilter += ":flags=lanczos";
}
return scaleFilter;
}
int MainWindow::getTargetNumFrame(int numFrame) {
if (ui->comboBox_Fps->currentIndex() == 0) {
return qRound(numFrame * ui->lineEdit_Fps->text().toDouble() / fps);
}
else return numFrame * (ui->comboBox_Fps->currentIndex() + 1);
}
double MainWindow::getNewFps() {
if (ui->comboBox_Fps->currentIndex() == 0) {
return ui->lineEdit_Fps->text().toDouble();
}
else return fps * (ui->comboBox_Fps->currentIndex() + 1);
}
void MainWindow::getMetadata() {
QSize size;
if (type == "video" || fi.suffix() == "gif") {
QMediaPlayer* player = new QMediaPlayer;
player->setSource(QUrl(fi.absoluteFilePath()));
QMediaMetaData metaData(player->metaData());
delete player;
size = qvariant_cast<QSize>(QVariant(metaData.value(QMediaMetaData::Resolution)));
dur = getDuration(fi);
fps = qvariant_cast<double>(QVariant(metaData.value(QMediaMetaData::VideoFrameRate)));
ui->lineEdit_Fps->setText(QString::number(fps, 'f', 2));
}
else if (type == "image") {
size = QImage(fi.absoluteFilePath()).size();
}
res[0] = size.width();
res[1] = size.height();
ui->lineEdit_Res->setText(QString::number(res[0]));
ui->lineEdit_Res_2->setText(QString::number(res[1]));
}
void MainWindow::readModelName() {
QDir modelsDir = QDir(currentPath + "/realesrgan-ncnn-vulkan/models");
foreach(QString model, modelsDir.entryList(QDir::Files)) {
if (model.contains(".bin") && model[1] == 'x') {
ui->comboBox_Model->addItem(model.remove(0, 3).remove(".bin"));
}
}
}