Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess with ffmpeg is not working

QProcess with ffmpeg is not working

Scheduled Pinned Locked Moved Solved General and Desktop
qprocessffmpeg
5 Posts 3 Posters 923 Views
  • 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.
  • SavizS Offline
    SavizS Offline
    Saviz
    wrote on last edited by
    #1

    I have a simple block of code that I use to run ffmpeg and test the version of it using QProcess:

    Code:

    #include <QApplication>
    #include <QProcess>
    #include <QDir>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QProcess process;
        QStringList arguments;
    
        QString path(QDir::currentPath() + "/lib/ffmpeg/bin/");
    
        process->setWorkingDirectory(
    
                    // I checked this path multiple times and it is correct.
                    path
        );
    
        arguments << "-version";
    
        process->start(
    
                    "ffmpeg.exe",
                    arguments
                    );
    
        QString output = process->readAllStandardOutput(
    
                    );
    
        // Gives me: 
        // "C:/Users/Desktop/User_Name/build-Project-Desktop_Qt_6_2_4_MinGW_64_bit-Debug/lib/ffmpeg/bin/"
        // Which is correct.
        qDebug() << path;
    
        // Both of these give me this >> "", ""
        qDebug() << output;
        qDebug() << process->readAllStandardError();
    
        return a.exec();
    }
    

    Both the output and the errors return me nothing. At this point I have no more clue what is going on. Can someone please explain this to me?

    JonBJ 1 Reply Last reply
    0
    • SavizS Saviz

      I have a simple block of code that I use to run ffmpeg and test the version of it using QProcess:

      Code:

      #include <QApplication>
      #include <QProcess>
      #include <QDir>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QProcess process;
          QStringList arguments;
      
          QString path(QDir::currentPath() + "/lib/ffmpeg/bin/");
      
          process->setWorkingDirectory(
      
                      // I checked this path multiple times and it is correct.
                      path
          );
      
          arguments << "-version";
      
          process->start(
      
                      "ffmpeg.exe",
                      arguments
                      );
      
          QString output = process->readAllStandardOutput(
      
                      );
      
          // Gives me: 
          // "C:/Users/Desktop/User_Name/build-Project-Desktop_Qt_6_2_4_MinGW_64_bit-Debug/lib/ffmpeg/bin/"
          // Which is correct.
          qDebug() << path;
      
          // Both of these give me this >> "", ""
          qDebug() << output;
          qDebug() << process->readAllStandardError();
      
          return a.exec();
      }
      

      Both the output and the errors return me nothing. At this point I have no more clue what is going on. Can someone please explain this to me?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Saviz
      You are not waiting for the process to finish (QProcess::start() merely starts it) before reading its output, nor reacting to signals. There are many examples out there using QProcess::waitForFinished() before trying to read, for simplicity.

      There is a separate issue. QProcess::setWorkingDirectory() sets the directory for the process being run. It does not use it to locate the .exe to run. If you are trying to tell Windows to find ffmpeg.exe in that directory to run, because it's not on your PATH, this won't (shouldn't) work. Pass the full path as the command instead.

      SavizS 1 Reply Last reply
      3
      • JonBJ JonB

        @Saviz
        You are not waiting for the process to finish (QProcess::start() merely starts it) before reading its output, nor reacting to signals. There are many examples out there using QProcess::waitForFinished() before trying to read, for simplicity.

        There is a separate issue. QProcess::setWorkingDirectory() sets the directory for the process being run. It does not use it to locate the .exe to run. If you are trying to tell Windows to find ffmpeg.exe in that directory to run, because it's not on your PATH, this won't (shouldn't) work. Pass the full path as the command instead.

        SavizS Offline
        SavizS Offline
        Saviz
        wrote on last edited by
        #3

        @JonB I changed the cod according to your instructions and it works! Thanks!

        Here is the code if anyone is interested:

        #include <QApplication>
        #include <QProcess>
        #include <QDir>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            QProcess process;
            QStringList arguments;
        
            arguments << "-version";
        
            process->start(
        
                        QDir::currentPath() + "/lib/ffmpeg/bin/ffmpeg.exe",
                        arguments
                        );
            
            // Waiting for it to finish
            process->waitForFinished();
            QString output = process->readAllStandardOutput(
        
                        );
        
            qDebug() << output;
        
            return a.exec();
        }
        
        1 Reply Last reply
        0
        • SavizS Saviz has marked this topic as solved on
        • D Offline
          D Offline
          DungeonLords
          wrote on last edited by
          #4

          How start FFmpeg using QProcess with bash example full code

              //Thanks https://github.com/AndreiCherniaev/libav_MJPEG-transcode-VP9_C_Universe
              process = new QProcess(this);
              connect(process, &QProcess::errorOccurred, this, &MainClass::QProcessErrHandler);
              connect(process, &QProcess::stateChanged, this, &MainClass::QProcessStateChangeHandler);
              connect(process, &QProcess::finished, this, &MainClass::QProcessFinishHandler);
              process->setProcessChannelMode(QProcess::MergedChannels);
              //If you need read Linux env variables (for example $PWD) then use qgetenv("PWD");
              process->setProgram("bash");
              process->setArguments({"-c", "ffmpeg -y -f lavfi -i testsrc=size=1280x720:rate=1:duration=10 -vcodec mjpeg -pix_fmt yuvj422p -f mjpeg input.yuvj422p"});
              process->start();
          
          JonBJ 1 Reply Last reply
          0
          • D DungeonLords

            How start FFmpeg using QProcess with bash example full code

                //Thanks https://github.com/AndreiCherniaev/libav_MJPEG-transcode-VP9_C_Universe
                process = new QProcess(this);
                connect(process, &QProcess::errorOccurred, this, &MainClass::QProcessErrHandler);
                connect(process, &QProcess::stateChanged, this, &MainClass::QProcessStateChangeHandler);
                connect(process, &QProcess::finished, this, &MainClass::QProcessFinishHandler);
                process->setProcessChannelMode(QProcess::MergedChannels);
                //If you need read Linux env variables (for example $PWD) then use qgetenv("PWD");
                process->setProgram("bash");
                process->setArguments({"-c", "ffmpeg -y -f lavfi -i testsrc=size=1280x720:rate=1:duration=10 -vcodec mjpeg -pix_fmt yuvj422p -f mjpeg input.yuvj422p"});
                process->start();
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @DungeonLords
            What is your question? Your code runs a bash -c "....", which is fine. Your linked output shows libGL errors. What happens if you run

            ffmpeg -y -f lavfi -i testsrc=size=1280x720:rate=1:duration=10 -vcodec mjpeg -pix_fmt yuvj422p -f mjpeg input.yuvj422p
            

            from a shell? If that errors what is the relevance of Qt or QProcess?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved