You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.2 KiB
C++
116 lines
3.2 KiB
C++
2 years ago
|
/*
|
||
|
* To change this license header, choose License Headers in Project Properties.
|
||
|
* To change this template file, choose Tools | Templates
|
||
|
* and open the template in the editor.
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
* File: main.cpp
|
||
|
* Author: shjd
|
||
|
*
|
||
|
* Created on 2018年7月20日, 上午10:03
|
||
|
*/
|
||
|
|
||
|
#include <QApplication>
|
||
|
#include <QThread>
|
||
|
#include <QDebug>
|
||
|
#include <QProcess>
|
||
|
#include <QtXml>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
class FfmpegThread : public QThread
|
||
|
{
|
||
|
public:
|
||
|
QString str;
|
||
|
private:
|
||
|
void run();
|
||
|
};
|
||
|
void FfmpegThread::run()
|
||
|
{
|
||
|
// QProcess ffmpegprocess=new QProcess();
|
||
|
// ffmpegprocess.start("./usr/local/ffmpeg/bin/ffmpeg",str);
|
||
|
system(FfmpegThread::str.toLatin1().data());
|
||
|
}
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
QCoreApplication a(argc, argv);
|
||
|
// QString str1="ffmpeg -rtsp_transport tcp -re -i rtsp://admin:12345@192.168.1.2:554/h264/ch1/main/av_stream -vcodec copy -acodec copy -f rtsp rtsp://192.168.188.168:554/test.sdp";
|
||
|
// //QProcess *ffmpegprocess=new QProcess();
|
||
|
// //ffmpegprocess->start("ffmpeg",QStringList(" -rtsp_transport tcp -re -i rtsp://admin:12345@192.168.1.2:554/h264/ch1/main/av_stream -vcodec copy -acodec copy -f rtsp rtsp://192.168.188.168:554/test.sdp"));
|
||
|
// FfmpegThread *ft=new FfmpegThread;
|
||
|
// ft->str=str1;
|
||
|
// ft->start();
|
||
|
// while(true)
|
||
|
// {
|
||
|
// qDebug() << ft->isRunning();
|
||
|
// usleep(1000000);
|
||
|
// }
|
||
|
QDomDocument doc("rtspList");
|
||
|
QFile file("rtspList.xml");
|
||
|
if (!file.open(QIODevice::ReadOnly))
|
||
|
{
|
||
|
qDebug() << "File Open Failed!";
|
||
|
return a.exec();
|
||
|
}
|
||
|
if (!doc.setContent(&file))
|
||
|
{
|
||
|
file.close();
|
||
|
qDebug() << "File Load Failed!";
|
||
|
return a.exec();
|
||
|
}
|
||
|
file.close();
|
||
|
|
||
|
// print out the element names of all elements that are direct children
|
||
|
// of the outermost element.
|
||
|
QDomElement docElem = doc.documentElement();
|
||
|
QDomNodeList rtsplst=docElem.elementsByTagName("rtsp");
|
||
|
|
||
|
if(!rtsplst.isEmpty())
|
||
|
{
|
||
|
int cnt=rtsplst.count();
|
||
|
FfmpegThread *ft[cnt];
|
||
|
for(int i=0;i<cnt;i++)
|
||
|
{
|
||
|
ft[i]=new FfmpegThread();
|
||
|
}
|
||
|
for(int i=0;i<cnt;i++)
|
||
|
{
|
||
|
//qDebug() << rtsplst.item(i).toElement().text();
|
||
|
ft[i]->str=rtsplst.item(i).toElement().text();
|
||
|
ft[i]->start();
|
||
|
//qDebug()<<ft[i]->currentThreadId();
|
||
|
}
|
||
|
while(true)
|
||
|
{
|
||
|
//qDebug()<<time->toString();
|
||
|
QTime *time=new QTime(QDateTime::currentDateTime().time());
|
||
|
if(time->hour()==20 || time->hour()==6)
|
||
|
{
|
||
|
if(time->minute()==0)
|
||
|
{
|
||
|
if(time->second()>0 && time->second()<60)
|
||
|
{
|
||
|
system("killall -9 ffmpeg");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for(int i=0;i<cnt;i++)
|
||
|
{
|
||
|
|
||
|
|
||
|
|
||
|
if(!ft[i]->isRunning())
|
||
|
{
|
||
|
ft[i]->start();
|
||
|
qDebug() << ft[i]->str << "is fault!";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
usleep(30000000);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return a.exec();
|
||
|
}
|