forked from suntaoxy/raspberrylive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moviemod.cpp
145 lines (122 loc) · 4.16 KB
/
moviemod.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
#include "moviemod.h"
#include <QLayout>
#include <QDir>
#include <QProcess>
#include <QDebug>
#include <QFile>
#include "makeshell.h"
#include<QApplication>
Moviemod::Moviemod(QWidget *parent) : QWidget(parent)
{
websitelabel=new QLabel(tr("网址"));
websitetext=new QLineEdit("rtmp://js.live-send.acg.tv/live-js/");
streamlabel=new QLabel(tr("推流码"));
streamtext=new QLineEdit("?streamname=live_956714_5294207&key=a47f28b34b8809026e8e93e75adca602");
okbtn=new QPushButton;
okbtn->setText(tr("开始直播"));
closebtn=new QPushButton;
closebtn->setText(tr("停止直播"));
choosemoive=new QPushButton;
choosemoive->setText(tr("选择电影"));
moviename=new QLineEdit;
choosesrt=new QPushButton;
choosesrt->setText(tr("选择字幕"));
srt_name=new QLineEdit;
// fswatcher = new QFileSystemWatcher(this);
QGridLayout* mainlayout=new QGridLayout(this);
QHBoxLayout* btnlayout=new QHBoxLayout;
btnlayout->addStretch(1);
btnlayout->addWidget(okbtn);
btnlayout->addWidget(closebtn);
mainlayout->setMargin(10);
mainlayout->setSpacing(6);
mainlayout->addWidget(websitelabel,0,0);
mainlayout->addWidget(websitetext,0,1);
mainlayout->addWidget(streamlabel,1,0);
mainlayout->addWidget(streamtext,1,1);
mainlayout->addWidget(choosemoive,2,0);
mainlayout->addWidget(moviename,2,1);
mainlayout->addWidget(choosesrt,3,0);
mainlayout->addWidget(srt_name,3,1);
mainlayout->addLayout(btnlayout,4,0,1,2);
process_0 = new QProcess(this);
connect(okbtn,SIGNAL(clicked()),this,SLOT(mkandexcute_shell()));
connect(choosemoive,SIGNAL(clicked()),this,SLOT(showfile()));
connect(closebtn,SIGNAL(clicked()),process_0,SLOT(kill()));
connect(choosesrt,SIGNAL(clicked(bool)),this,SLOT(showsrt()));
connect(&fswatcher,SIGNAL(directoryChanged(QString)),this,SLOT(setsrt(QString)));
}
void Moviemod::showfile()
{
QString path_of_video =QFileDialog::getOpenFileName(this,tr("选择电影文件"),"/");
moviename->setText(path_of_video);
}
void Moviemod::showsrt()
{
QString path_of_video =QFileDialog::getOpenFileName(this,tr("选择srt字幕文件"),moviename->text());
srt_name->setText(path_of_video);
}
void Moviemod::mkandexcute_shell()
{
QString rtmp = websitetext->text()+streamtext->text();
creat_srt_shell(moviename->text(),rtmp,srt_name->text());
#if defined(Q_OS_WIN32)
QString pathofshell = QDir::currentPath() + "/raspliveshell.bat" ;
qDebug() << pathofshell;
process_0->start("cmd.exe",QStringList() << "/c" << pathofshell);
#elif defined(Q_OS_LINUX)
QString pathofshell = "sh "+QDir::currentPath() + "/raspliveshell.sh" ;
qDebug() << pathofshell;
process_0->start(pathofshell);
#endif
}
void Moviemod::downsrt()
{
if(moviename->text().isEmpty())
return;
QString path_movie=moviename->text();
QFileInfo mvinfo(path_movie);
fswatcher.addPath(mvinfo.absolutePath());
qDebug()<<mvinfo.absolutePath();
#if defined(Q_OS_LINUX)
QString shell = "python3 "+QApplication::applicationDirPath()+"/getsrt.py "+path_movie;
process_0->start(shell);
#elif defined(Q_OS_WIN32)
QString shell = QApplication::applicationDirPath()+"/getsrt.py "+path_movie;
qDebug()<<shell;
process_0->start("cmd.exe",QStringList() << "/c" << shell);
#endif
}
void Moviemod::setsrt(QString path)
{
// qDebug()<<path;
QDir mvdir(path);
QStringList str_list;
str_list<<"*";
QFileInfoList filelist=mvdir.entryInfoList(str_list,QDir::Files,QDir::Name);
foreach(QFileInfo finfo, filelist)
{
if(finfo.suffix()=="srt")
{
QString shell="ffmpeg -i "+finfo.absoluteFilePath()+" newname.ass";
#if defined(Q_QS_LINUX)
process_0->start(shell);
#elif defined(Q_OS_WIN32)
qDebug()<<shell;
process_0->start("cmd.exe",QStringList() << "/c" << shell);
#endif
break;
}
}
foreach(QFileInfo finfo, filelist)
{
if(finfo.suffix()=="ass"||finfo.suffix()=="srt")
{
srt_name->setText(finfo.absoluteFilePath());
break;
}
}
}
Moviemod::~Moviemod()
{
}