-
Notifications
You must be signed in to change notification settings - Fork 8
/
makeshell.cpp
94 lines (79 loc) · 2.97 KB
/
makeshell.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
#include "makeshell.h"
#include<QFile>
#include<QFileDialog>
#include<QTextStream>
#include<QtDebug>
#include<QDir>
void creat_shell(QString pwd,QString rtmp)
{
QStringList str_list;
str_list<<"*";
QDir diry(pwd);
QFileInfoList filelist=diry.entryInfoList(str_list,QDir::Files,QDir::Name);
QFile file("raspliveshell.sh");
if(file.open(QIODevice::ReadWrite|QIODevice::Truncate))
{
QString ffmpeg_order_fore =" ffmpeg -re -i ";
QString ffmpeg_order_mid =" -vcodec copy -acodec aac -b:a 128k -f flv ";
QTextStream writeinshell(&file);
writeinshell<<"#!/bin/bash"<<left<<endl;
writeinshell<<"while true"<<left<<endl;
writeinshell<<"do"<<left<<endl;
foreach (QFileInfo finfo, filelist)
{
if(finfo.suffix()=="mp4"||finfo.suffix()=="mkv")
{
writeinshell<<ffmpeg_order_fore + "\"" + finfo.filePath()+"\"" +ffmpeg_order_mid
+" \"" + rtmp +"\" "<<left<<endl;
}
}
writeinshell<<"done"<<left<<endl;
}
}
void creat_srt_shell(QString path_movie,QString rtmp,QString path_srt)
{
QFileInfo filemovie=QFileInfo(path_movie); //文件信息类
QFileInfo filesrt=QFileInfo(path_srt);
#if defined(Q_OS_WIN32)
QFile file("raspliveshell.bat");
#elif defined(Q_OS_LINUX)
QFile file("raspliveshell.sh");
#endif
if(file.open(QIODevice::ReadWrite|QIODevice::Truncate))
{
#if defined(Q_OS_WIN32)
QString ffmpeg_order_fore =" ffmpeg -re -i ";
QString ffmpeg_order_mid;
if(filesrt.suffix()=="ass")
{
ffmpeg_order_mid =" -vf \"ass="+filesrt.fileName()+"\" -vcodec h264 -acodec aac -b:a 128k -f flv ";
}
else
{
ffmpeg_order_mid =" -vf subtitles="+filesrt.fileName()+" -vcodec h264 -acodec aac -b:a 128k -f flv ";
}
QTextStream writeinshell(&file);
writeinshell<<"cd /d "+ filemovie.absolutePath()+"\r\n"<<left;
writeinshell<<ffmpeg_order_fore + "\"" +filemovie.fileName()+"\"" +ffmpeg_order_mid+" \"" + rtmp +"\" \r\n"<<left;
writeinshell<<"pause"<<left<<endl;
#elif defined(Q_OS_LINUX)
QString ffmpeg_order_fore =" ffmpeg -re -i ";
QString ffmpeg_order_mid;
if(filesrt.suffix()=="ass")
{
ffmpeg_order_mid =" -vf \"ass="+filesrt.fileName()+"\" -vcodec h264 -acodec aac -b:a 128k -f flv ";
}
else
{
ffmpeg_order_mid =" -vf subtitles="+filesrt.fileName()+" -vcodec h264 -acodec aac -b:a 128k -f flv ";
}
QTextStream writeinshell(&file);
writeinshell<<"#!/bin/bash"<<left<<endl;
writeinshell<<"while true"<<left<<endl;
writeinshell<<"do"<<left<<endl;
writeinshell<<"cd "+ filemovie.absolutePath()<<left<<endl;
writeinshell<<ffmpeg_order_fore + "\"" +filemovie.fileName()+"\"" +ffmpeg_order_mid+" \"" + rtmp +"\" "<<left<<endl;
writeinshell<<"done"<<left<<endl;
#endif
}
}