/* * 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 #include #include #include #include #include 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;istr=rtsplst.item(i).toElement().text(); ft[i]->start(); //qDebug()<currentThreadId(); } while(true) { //qDebug()<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;iisRunning()) { ft[i]->start(); qDebug() << ft[i]->str << "is fault!"; } } usleep(30000000); } } return a.exec(); }