/
pathprocess.cpp
126 lines (96 loc) · 3.37 KB
/
pathprocess.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
#include "pathprocess.h"
#include <QtDebug>
#include <QProcess>
PathProcess::PathProcess(QObject *parent):QThread(parent)
{
// connect(mConvertProcess, SIGNAL(started()), this, SLOT(processStarted()));
m_CurrentValue = 0;
m_CurrentFile = 1;
// connect(mConvertProcess, SIGNAL(finished(int)), this, SLOT(encodingFinished()));
}
PathProcess::~PathProcess()
{
}
void PathProcess::setpath(QString path)
{
this->path = path;
}
void PathProcess::readyReadStandardOutput()
{
mOutputString.append(mConvertProcess->readAllStandardOutput());
emit Log(mOutputString);
}
void PathProcess::ConvertFinished()
{
int value = 100/m_CurrentFile;
m_CurrentValue+=value ;
emit ThreadProcessBar(m_CurrentValue);
}
void PathProcess::run()
{
emit Log("jejee");
m_CurrentValue = 0;
emit ThreadProcessBar(m_CurrentValue);
mConvertProcess = new QProcess(this);
connect(mConvertProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(mConvertProcess, SIGNAL(finished(int)), this, SLOT(ConvertFinished()));
QDir dir(this->path);
if (!dir.exists())
{
return;
}
QStringList filters;
filters << QString("*.ts") << QString("*.TS");
dir.setFilter(QDir::Files); //设置类型过滤器,只为文件格式
dir.setNameFilters(filters); //设置文件名称过滤器,只为filters格式(后缀为.jpeg等图片格式)
QFileInfoList list = dir.entryInfoList();
int file_count = list.count();
if (file_count <= 0)
{
return;
}
m_CurrentFile= file_count;
emit Log("The path has ts file number:" + QString::number(file_count));
for (int i = 0; i < file_count; i++)
{
QFileInfo fileInfo = list.at(i);
QString mkdir_path = fileInfo.path() + "/" + fileInfo.baseName();
qDebug() << "mkdir_path" + mkdir_path;
//mkdir same name dir
QDir *dir_mkdir = new QDir;
bool exist = dir_mkdir->exists(mkdir_path);
if (exist)
{
}
else
{
bool ok = dir_mkdir->mkdir(mkdir_path);
if (ok)
{
//textEdit->append(mkdir_path + " path create ok");
}
}
delete dir_mkdir;
QString m3u8_name = fileInfo.path() + "/" + fileInfo.baseName()+"/" + fileInfo.baseName() +".m3u8";
QString list_name = fileInfo.path() + "/" + fileInfo.baseName()+"/" + fileInfo.baseName() +"%03d.ts";
QStringList args;
args <<"-i"<<fileInfo.absoluteFilePath();
args <<"-c"<<"copy";
args <<"-map"<<"0";
args <<"-f"<<"segment";
args <<"-segment_list"<< m3u8_name;
args <<"-segment_time"<<"10";
args <<list_name;
qDebug() << args << endl;
mConvertProcess->setProcessChannelMode(QProcess::MergedChannels);
QString program = QApplication::applicationDirPath() + "/ffmpeg/ffmpeg";
//QString program = "D:/ffmpeg/qtffmpeg/ffmpeghls/ffmpegtosegment/github/ffmpeg-segment/bin/ffmpeg";
mConvertProcess->start(program, args);
while (false == mConvertProcess->waitForFinished())
{
}
}
emit Log("Convert Surcessfully\N");
m_CurrentValue=100 ;
emit ThreadProcessBar(m_CurrentValue);
}