-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
99 lines (89 loc) · 3.46 KB
/
mainwindow.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
#include "mainwindow.h"
#include "choosefile.h"
#include "filelist.h"
#include <QMessageBox>
#include <QFileInfo>
#include <QTime>
#include <vector>
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
topwidget = new QWidget(this);
TabMain = new QTabWidget(topwidget);
begin = new QPushButton("开始处理", topwidget);
begin->setMaximumWidth(500);
TabChoseFile = new ChooseFile();
TabSetFFmpeg = new ffmpegWidget(TabChoseFile);
TabMore = new QWidget();
TabMain->insertTab(0, TabChoseFile, "选择文件");
TabMain->insertTab(1, TabSetFFmpeg, "参数设置");
TabMain->insertTab(2, TabMore, "更多选项");
topLayout = new QVBoxLayout(topwidget);
topLayout->addWidget(TabMain, Qt::AlignHCenter);
topLayout->addWidget(begin, 1, Qt::AlignHCenter);
topwidget->setLayout(topLayout);
this->setCentralWidget(topwidget);
connect(begin, &QPushButton::clicked, this, &MainWindow::beginProcess);
}
MainWindow::~MainWindow()
{
delete topLayout;
}
void MainWindow::beginProcess(){
TabSetFFmpeg->apply();
if(TabChoseFile->fileToChoose->filelist.size() == 0){
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("没有导入任何文件!");
msgBox.exec();
}
vector<QString> commands;
if(TabChoseFile->fileToChoose->mergeOrSingle->isChecked()){
commands.push_back("");
//merge
auto dir = QDir::temp();
dir.mkdir("VCut_tmp");
dir.cd("VCut_tmp");
QDir::setCurrent(dir.absolutePath());
QString filename="merge_filelist.txt";
QFile file(filename);
if (file.open(QIODevice::ReadWrite)){
QTextStream stream( &file );
for(auto &x: TabChoseFile->fileToChoose->filelist){
stream << "file \" " << x.filename << "\" " << Qt::endl;
}
commands[0] = "ffmpeg -f concat -i \"merge_filelist.txt\" ";
if(TabSetFFmpeg->finalCommand->document()->toPlainText().contains("ffmpeg命令")){
commands[0] += " -c copy 合成的视频" + QTime::currentTime().toString() + ".mp4";
}
else {
QString appliedCommand = TabSetFFmpeg->finalCommand->document()->toPlainText();
appliedCommand.erase(appliedCommand.constBegin(), appliedCommand.constBegin()+20);
commands[0] += appliedCommand;
}
}
}
else{
if(TabSetFFmpeg->finalCommand->document()->toPlainText().contains("ffmpeg命令")){
for(auto iter = TabChoseFile->fileToChoose->filelist.begin();
iter != TabChoseFile->fileToChoose->filelist.end(); iter++){
iter->command = TabSetFFmpeg->finalCommand->document()->toPlainText();
}
}
for(auto &x: TabChoseFile->fileToChoose->filelist){
QString command_of_file = x.command;
command_of_file.erase(command_of_file.constBegin(), command_of_file.constBegin()+20);
QString command_now = "ffmpeg ";
if(x.extract){
command_now += " -ss " + x.beg_time.toString("hh:mm:ss.zzz") + " -to " + x.end_time.toString("hh:mm:ss.zzz") + " ";
}
command_now += "-i \"" + x.filename + "\" " + command_of_file;
commands.push_back(command_now);
}
}
for(auto &x: commands){
x = "./ffmpeg/bin/" + x;
system(x.toStdString().c_str());
}
}