-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocesses.cpp
268 lines (223 loc) · 10.3 KB
/
processes.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "mainwindow.h"
int MainWindow::Spliting() {
setTimeTaken();
if (ui->lineEdit_Segment->text() != "" && ui->lineEdit_Segment->text().QString::toDouble() < dur) {
QDir splitedDir(fi.absolutePath() + '/' + fi.completeBaseName() + "_splited");
if (splitedDir.exists()) splitedDir.removeRecursively();
QDir(fi.absolutePath()).mkdir(fi.completeBaseName() + "_splited");
process = new QProcess;
QString cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -i \"" + fi.filePath() + "\" -c copy -map 0 -f segment -segment_time " + ui->lineEdit_Segment->text() + " -reset_timestamps 1 \"" + splitedDir.absolutePath() + "/%d." + fi.suffix() + "\" -hide_banner";
process->start(cmd);
while (process->state() != 0) {
setTimeTaken();
delay(100);
}
delete process;
return splitedDir.count() - 2;
}
else return 0;
}
int MainWindow::Decoding(QFileInfo file, int numFrame) {
setTimeTaken();
QTime startTime = QTime::currentTime();
QDir frameDir(file.absolutePath() + '/' + file.completeBaseName() + "_frames");
if (frameDir.exists()) frameDir.removeRecursively();
QDir(file.absolutePath()).mkdir(file.completeBaseName() + "_frames");
ui->progressBar->setValue(0);
process = new QProcess;
QString cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -i \"" + file.filePath() + "\" \"" + frameDir.absolutePath() + "/%8d.png\" -hide_banner";
process->start(cmd);
while (process->state() != 0) {
setProgressBarVal(int(getNumFrameFinished(process) * 100 / numFrame));
setTimeTaken();
setRemaining(startTime);
delay(100);
if (ui->pushButton_Stop->isDown()) {
if (ConfirmToStop()) {
process->kill();
state = "Stopped";
}
}
}
delete process;
DecodingTime = DecodingTime.addSecs(-QTime::currentTime().secsTo(startTime));
if (state != "Stopped") setProgressBarVal(100);
return frameDir.count() - 2;
}
void MainWindow::Interpolating(QFileInfo file, int numFrame) {
retryInterpolating:;
setTimeTaken();
QTime startTime = QTime::currentTime();
QDir frameDir(file.absolutePath() + '/' + file.completeBaseName() + "_interpolated");
if (frameDir.exists()) frameDir.removeRecursively();
QDir(file.absolutePath()).mkdir(file.completeBaseName() + "_interpolated");
QString targetNumFrame; // Only rife-v4 support target num frame
if ((ui->comboBox_Engine->currentIndex() == 0 && ui->comboBox_Model->currentIndex() < 9) || (ui->comboBox_Engine->currentIndex() == 1 && ui->comboBox_Model->currentIndex() > 2)) targetNumFrame = "";
else targetNumFrame = " -n " + QString::number(numFrame);
QString UHD = "";
if (res[1] >= 2160) UHD = " -u";
ui->progressBar->setValue(0);
process = new QProcess;
QString cmd = "\"" + currentPath + "/" + ui->comboBox_Engine->currentText().toLower() + "/" + ui->comboBox_Engine->currentText().toLower() + ".exe\" -i \"" + file.absolutePath() + '/' + file.completeBaseName() + "_frames" + "\" -o \"" + frameDir.absolutePath() + "\"" + targetNumFrame + " -m " + ui->comboBox_Model->currentText() + getParameter("gpuid") + getParameter("thread") + UHD;
process->start(cmd);
while (process->state() != 0) {
setProgressBarVal((QDir(frameDir.absolutePath()).count() - 2) * 100 / numFrame);
setTimeTaken();
setRemaining(startTime);
delay(100);
if (ui->pushButton_Stop->isDown()) {
if (ConfirmToStop()) {
process->kill();
state = "Stopped";
}
}
if (readStdOutput(process).contains("failed")) {
process->kill();
dealWithInterpolatingErr();
if (state != "Stopped") goto retryInterpolating;
}
}
delete process;
InterpolatingTime = InterpolatingTime.addSecs(-QTime::currentTime().secsTo(startTime));
if (state != "Stopped") {
setProgressBarVal(100);
QDir(file.absolutePath() + '/' + file.completeBaseName() + "_frames").removeRecursively();
}
}
void MainWindow::Upscaling(QFileInfo input, int numFrame) {
retryUpscaling:;
setTimeTaken();
QTime startTime = QTime::currentTime();
QString inputPath;
if (type == "video" || fi.suffix() == "gif") inputPath = input.absolutePath() + '/' + input.completeBaseName() + "_frames";
else inputPath = input.filePath();
QString outputPath, model = getParameter("model"); // Declare 'model' variable here to make 'resizingNeeded' variable assigned value
if (type == "video" || fi.suffix() == "gif") outputPath = input.absolutePath() + '/' + input.completeBaseName() + "_upscaled";
else if (resizingNeeded) {
if (type == "image") outputPath = input.absolutePath() + '/' + input.completeBaseName() + "_upscaled." + fo.suffix();
else outputPath = input.filePath() + "_upscaled";
}
else outputPath = ui->lineEdit_Output->text();
if (type != "image" || fi.suffix() == "gif") {
QDir dir(outputPath);
if (dir.exists()) dir.removeRecursively();
QDir(dir.absolutePath()).mkdir(outputPath);
}
ui->progressBar->setValue(0);
process = new QProcess;
QString cmd = "\"" + currentPath + "/" + ui->comboBox_Engine->currentText().toLower() + "/" + ui->comboBox_Engine->currentText().toLower() + ".exe\" -i \"" + inputPath + "\" -o \"" + outputPath + "\"" + model + " -t " + ui->lineEdit_TileSize->text() + getParameter("noise_syncgap") + getParameter("gpuid") + getParameter("thread");
process->start(cmd);
while (process->state() != 0) {
setTimeTaken();
setRemaining(startTime);
delay(100);
if (ui->pushButton_Stop->isDown()) {
if (ConfirmToStop()) {
process->kill();
state = "Stopped";
}
}
QString output = readStdOutput(process);
if (type != "image" || fi.suffix() == "gif") setProgressBarVal((QDir(outputPath).count() - 2) * 100 / numFrame);
else if (output.contains("%\r\n")) setProgressBarVal(qRound(output.remove("%\r\n").toDouble()));
if (output.contains("alpha") && fo.suffix() == "jpg") {
process->kill();
state = "Stopped";
QMessageBox msg(QMessageBox::Critical, "Conversion failed!", "Detected alpha channel!", QMessageBox::Close);
msg.setStyleSheet("QPushButton{height: 25px}");
msg.exec();
}
if (output.contains("failed")) {
process->kill();
dealWithUpscalingErr();
if (state != "Stopped") goto retryUpscaling;
}
}
delete process;
UpscalingTime = UpscalingTime.addSecs(-QTime::currentTime().secsTo(startTime));
if (state != "Stopped") {
setProgressBarVal(100);
if (type == "video" || fi.suffix() == "gif") QDir(inputPath).removeRecursively();
}
}
void MainWindow::Encoding(QFileInfo file, double fps) {
setTimeTaken();
QTime startTime = QTime::currentTime();
QString suffix;
if (ui->comboBox_Tool->currentIndex() == 0) suffix = "_upscaled";
else suffix = "_interpolated";
QDir frameDir(file.absolutePath() + '/' + file.completeBaseName() + suffix);
QString outputPath;
if (numPart == 0) outputPath = ui->lineEdit_Output->text();
else outputPath = frameDir.absolutePath() + '.' + fo.suffix();
ui->progressBar->setValue(0);
process = new QProcess;
QString cmd;
if (type == "video") {
cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -r " + QString::number(fps, 'f', 2) + " -i \"" + frameDir.absolutePath() + "/%8d.png\" -i \"" + file.filePath() + "\" -map 0:v -map 1:a:? -map 1:s:? -map 1:t:? -c:a copy -c:s copy -c:t copy -disposition:s default -crf " + QString::number(ui->spinBox_CRF->value()) + getVCodec() + getScaleFilter() + " -y \"" + outputPath + "\" -hide_banner";
}
else { // fi.suffix == "gif"
cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -r " + QString::number(fps, 'f', 2) + " -i \"" + frameDir.absolutePath() + "/%8d.png\"" + getScaleFilter() + " -y \"" + outputPath + "\" -hide_banner";
}
process->start(cmd);
while (process->state() != 0) {
setProgressBarVal(int(getNumFrameFinished(process) * 100 / numFrame));
setTimeTaken();
setRemaining(startTime);
delay(100);
if (ui->pushButton_Stop->isDown()) {
if (ConfirmToStop()) {
process->kill();
state = "Stopped";
}
}
}
delete process;
EncodingTime = EncodingTime.addSecs(-QTime::currentTime().secsTo(startTime));
if (state != "Stopped") {
setProgressBarVal(100);
frameDir.removeRecursively();
}
}
void MainWindow::Joining(QDir dir) {
setTimeTaken();
QFile list(dir.absolutePath() + "/list.txt");
if (list.open(QIODevice::WriteOnly)) {
QString suffix;
if (ui->comboBox_Tool->currentIndex() == 0) suffix = "_upscaled";
else suffix = "_interpolated";
QTextStream stream(&list);
for (int i = 0; i < numPart; i++) {
stream << "file '" + dir.absolutePath() + "/" + QString::number(i) + suffix + "." + fo.suffix() + "'\n";
}
}
ui->progressBar->setValue(0);
process = new QProcess;
QString cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -f concat -safe 0 -i \"" + dir.absolutePath() + "/list.txt\" -c copy -y \"" + ui->lineEdit_Output->text() + "\" -hide_banner";
process->start(cmd);
while (process->state() != 0) {
setTimeTaken();
delay(100);
}
delete process;
setProgressBarVal(100);
list.close();
dir.removeRecursively();
}
void MainWindow::Resizing(QFileInfo file) {
setTimeTaken();
QString output;
if (type == "dir") output = file.filePath().replace(file.absolutePath(), fo.filePath());
else if (type == "image") output = fo.filePath();
else output = file.filePath().replace("_upscaled", "_resized");
process = new QProcess;
QString cmd = "\"" + currentPath + "/ffmpeg/ffmpeg.exe\" -i \"" + file.filePath() + "\" -vf scale=" + getScaleFilter() + ":flags=lanczos -y \"" + output + "\" -hide_banner";
process->start(cmd);
if (type == "image") {
while (process->state() != 0) {
setTimeTaken();
delay(100);
}
delete process;
}
}