You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.8 KiB

  1. #include "ffmpeg_qualitycheck.h"
  2. #include <QRegularExpression>
  3. #include <QDebug>
  4. ffmpeg_qualitycheck::ffmpeg_qualitycheck(QObject *parent) : QObject(parent)
  5. {
  6. }
  7. void ffmpeg_qualitycheck::start(stream_t stream){
  8. qualities.clear();
  9. #ifdef WIN32
  10. QString program = "ffmpeg.exe";
  11. QStringList params = QStringList() << "-i" << "" + stream.url.toString() + "";
  12. #else
  13. QString program = "sh";
  14. QStringList params = QStringList() << "-c" << "ffmpeg -i \"" + stream.url.toString() + "\"";
  15. #endif
  16. mFFmpegProcess = new QProcess(this);
  17. connect(mFFmpegProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
  18. connect(mFFmpegProcess, static_cast<void (QProcess::*)(int)>(&QProcess::finished)
  19. , this, [this](int){
  20. emit this->finished(this->qualities);
  21. });
  22. mFFmpegProcess->setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
  23. mFFmpegProcess->start(program, params);
  24. mFFmpegProcess->waitForStarted(-1);
  25. }
  26. void ffmpeg_qualitycheck::cancel(){
  27. mFFmpegProcess->kill();
  28. }
  29. void ffmpeg_qualitycheck::readyReadStandardOutput()
  30. {
  31. QRegularExpression re_program("(Program)\\s\\K\\d+(?<!\\s)");
  32. QRegularExpression re_stream("(?!Video:)\\s\\K(?P<h>\\d+?)x(?P<w>\\d+?)\\s");
  33. QString out = mFFmpegProcess->readAllStandardOutput();
  34. QRegularExpressionMatch m_program = re_program.match(out);
  35. if(m_program.hasMatch())
  36. currentProgram = m_program.captured().toInt();
  37. QRegularExpressionMatch m_stream = re_stream.match(out);
  38. if(m_stream.hasMatch()){
  39. ffmpeg_quality_t q;
  40. q.program = currentProgram;
  41. q.height = m_stream.captured("h").toInt();
  42. q.width = m_stream.captured("w").toInt();
  43. qualities.append(q);
  44. }
  45. qDebug() << "QCHECK> " << out;
  46. }