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
QtWS25 Last Chance

QProcess with ffmpeg is not working

Scheduled Pinned Locked Moved Solved General and Desktop
qprocessffmpeg
5 Posts 3 Posters 920 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.
  • S Offline
    S Offline
    Saviz
    wrote on 1 Mar 2023, 17:23 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?

    J 1 Reply Last reply 1 Mar 2023, 17:28
    0
    • S Saviz
      1 Mar 2023, 17:23

      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?

      J Offline
      J Offline
      JonB
      wrote on 1 Mar 2023, 17:28 last edited by JonB 3 Jan 2023, 17:37
      #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.

      S 1 Reply Last reply 1 Mar 2023, 18:01
      3
      • J JonB
        1 Mar 2023, 17:28

        @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.

        S Offline
        S Offline
        Saviz
        wrote on 1 Mar 2023, 18:01 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
        • S Saviz has marked this topic as solved on 1 Mar 2023, 18:01
        • D Offline
          D Offline
          DungeonLords
          wrote on 18 Aug 2024, 07:30 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();
          
          J 1 Reply Last reply 18 Aug 2024, 08:03
          0
          • D DungeonLords
            18 Aug 2024, 07:30

            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();
            
            J Offline
            J Offline
            JonB
            wrote on 18 Aug 2024, 08:03 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

            5/5

            18 Aug 2024, 08:03

            • Login

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