-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessmanager.cpp
More file actions
executable file
·111 lines (94 loc) · 2.86 KB
/
processmanager.cpp
File metadata and controls
executable file
·111 lines (94 loc) · 2.86 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
#include<iostream>
#include<QProcess>
#include<QTextCodec>
#include<QMessageBox>
#include<QDir>
#include "processmanager.h"
#include "ui_processmanager.h"
using namespace std;
ProcessManager::ProcessManager(QWidget *parent, QSettings *settings, convParams *params) :
QDialog(parent),
ui(new Ui::ProcessManager)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
bool isFFMPEG=settings->value("FFMPEG").toBool();
//kick off worker process
cerr<<"Converstion Starting..."<<endl<<endl;
converter = new QProcess(parent);
connect(converter,SIGNAL(finished(int)),parentWidget(),SLOT(disposeProcess(int)));
connect(converter,SIGNAL(readyReadStandardError()),this,SLOT(readReady()));
connect(ui->buttonBox,SIGNAL(clicked(QAbstractButton*)),this,SLOT(cancel()));
connect(converter,SIGNAL(error(QProcess::ProcessError)),this,SLOT(Error(QProcess::ProcessError)));
QString program= isFFMPEG ? "ffmpeg":"avconv";
QStringList args;
args<<"-i" << params->input;
args<<"-c:v"<< "libx264";
args<<"-c:s"<< "copy";
switch(params->Quality)
{
case 0:
args<<"-crf"<< "18";
break;
case 1:
args<<"-crf"<< "22";
break;
case 2:
args<<"-crf"<< "25";
break;
}
switch(params->Size)
{
case 0:
args<<"-preset"<< "veryslow";
break;
case 1:
args<<"-preset"<< "fast";
break;
case 2:
args<<"-preset"<< "ultrafast";
break;
}
if(params->batchDir=="")
{
args<<params->input+"_converted.mkv";
}else{
QFileInfo currentFile(params->input);
args<<QDir(params->batchDir).absoluteFilePath( currentFile.fileName() +"_converted.mkv");
}
converter->start(program, args);
}
ProcessManager::~ProcessManager()
{
delete ui;
cerr<<"process destoyed"<<endl;
}
void ProcessManager::readReady()
{
QByteArray data=converter->readAllStandardError();
QString DataAsString;
DataAsString.append(data.data());
ui->label->setText(DataAsString);
}
void ProcessManager::cancel()
{
converter->terminate();
ui->label->setText("Please wait while conversion terminates....");
}
void ProcessManager::Error(QProcess::ProcessError perror)
{
cerr<<"QProcess Error:"<<perror<<endl;
QSettings *settings=new QSettings();
bool isFFMPEG=settings->value("FFMPEG").toBool();
QString app=isFFMPEG?"FFMPEG":"LibAV";
if(perror==0)//not installed
{
QMessageBox::critical(this,"Critical Failure","There was a serious problem processing your request. Please ensure "+app+" is installed.");
}
if(perror==1)//crashed
{
QMessageBox::critical(this,"Critical Failure",app+" has crashed");
}
this->deleteLater();
this->close();
}