Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Unable to run ffmpeg with qProcess to extract a single frame from Video

    General and Desktop
    3
    5
    2005
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kulvi last edited by kulvi

      I am trying to extract a single frame from a video using the Qprocess and ffmpeg and store it in a tmp folder. When I run the program in terminal command line it is able to extract it but not when qprocess runs it. I'm developing on a mac. What am I doing wrong.

      QString extractSingleFrame(QString videoPath, QDir tmpDir)
      {
          QString program = ffmpegPath();
          QProcess *ffmpegProcess = new QProcess();
          QString arguments;
          QFileInfo videoInfo(videoPath);
          QString videoName = videoInfo.fileName();
      
          QString firstFrameName(tmpDir.absolutePath() + "/" + videoName + ".jpg");
          arguments = " -y -i " + QDir::toNativeSeparators(videoPath)
                      + " -frames:v 1 -q:v 1 -f image2 " + QDir::toNativeSeparators(firstFrameName);
      
          QFile::remove(firstFrameName);
          qDebug() << "Starting program" << program + arguments;
          ffmpegProcess->start(program + arguments);
      
          if (ffmpegProcess->state() == QProcess::Starting){
             qDebug() << "program is starting" + ffmpegProcess->state();
          }
          ffmpegProcess->waitForFinished(-1);
      
          qDebug() << "done";
      
          delete ffmpegProcess;
      
          return firstFrameName;
      }
      

      This is the printed command
      Starting program "ffmpeg -y -i "/Users/userX/test.mov" -vframes 1 -q:v 1 -f image2 "/var/folders/s1/vtv2cx36p3h0000gn/T/test-ywDBgj/test.mov.jpg""

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        You seems to append all parameters to one string.
        It might be the reason.
        Normally its a QStringList and given as a separate parameter.

         QObject *parent;
            ...
            QString program = "./path/to/Qt/examples/widgets/analogclock";
            QStringList arguments;
            arguments << "-style" << "fusion";
        
            QProcess *myProcess = new QProcess(parent);
            myProcess->start(program, arguments);
        
        1 Reply Last reply Reply Quote 4
        • K
          kulvi last edited by

          I have tried to do:

          ffmpegProcess->start(program , QStringList()
                                   << "-y"
                                   << "-i"
                                   << QDir::toNativeSeparators(videoPath)
                                   << "-frames:v 1"
                                   << "-q:v 1"
                                   << "-f"
                                   << "image2"
                                   << QDir::toNativeSeparators(firstFrameName));
          

          This just gives the same result. In both cases ffmpegProcess->state() == QProcess::NotRunning gives a true flag.

          I'm having a hard time getting some error message output to pinpoint this issue. I am new to Qt so further help would be deeply appreciated.
          Using this to debug this gives me only an empty string:

          QString StdOut_sdcompare = ffmpegProcess->readAllStandardOutput();
              qDebug() << StdOut_sdcompare;
              QString StdError_sdcompare = ffmpegProcess->readAllStandardError();
              qDebug() << StdError_sdcompare;
          
          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            You still don't generate the parameter list correctly:

                QProcess ffmpeg;
                ffmpeg.start("ffmpeg" , QStringList()
                                     << "-y"
                                     << "-i" << QDir::toNativeSeparators(videoPath)
                                     << "-frames:v" << "1"
                                     << "-q:v" << "1"
                                     << "-f" << "image2"
                                     << QDir::toNativeSeparators(firstFrameName));
                ffmpeg.waitForFinished(-1);
            

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply Reply Quote 5
            • K
              kulvi @SGaist last edited by

              Thanks that did the trick, also I wasn't passing in the full path of ffmpeg.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post