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. Calling ffmpeg with QProcess: crashes
Forum Updated to NodeBB v4.3 + New Features

Calling ffmpeg with QProcess: crashes

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 655 Views 1 Watching
  • 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.
  • U Offline
    U Offline
    utkugulgec
    wrote last edited by
    #1

    Hi. I am making a GUI for ffmpeg and trying to call ffmpeg with QProcess. No matter what I do, I always get
    "qtc.process_stub: Inferior error: QProcess::Crashed "Process crashed".

    • I am working on Windows.
    • ffmpeg is on my path.
    • ffmpeg works in command line.
    • I tried giving the absolute path of ffmpeg to QProcess, no use.
    • QtCreator version 17, with Qt 6.

    The code I am running is below. Basically, when user clicks "convert" button, the app should start ffmpeg with QProcess. To be simple, I tried to get only version information with ffmpeg.

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QProcess *ffmpegProcess = new QProcess(this);
        ffmpegProcess->setWorkingDirectory(QCoreApplication::applicationDirPath());
        ffmpegProcess->setProcessChannelMode(QProcess::MergedChannels);
        
        // Connect buttons
        connect(ui->btnSelFile, &QPushButton::clicked, this, &MainWindow::selectInputFile);
        connect(ui->btnConvert, &QPushButton::clicked, this, &MainWindow::startConversion);
    
        // Connect FFmpeg process signals
        connect(ffmpegProcess, &QProcess::readyReadStandardOutput, this, &MainWindow::readProcessOutput);
        connect(ffmpegProcess, &QProcess::readyReadStandardError, this, &MainWindow::readProcessOutput);
        connect(ffmpegProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
                this, &MainWindow::processFinished);
    }
    
    void MainWindow::selectInputFile()
    {
        QString filePath = QFileDialog::getOpenFileName(this, "Select Video File", "", "Videos (*.mp4 *.mkv *.avi)");
        if (!filePath.isEmpty()) {
            inputFilePath = filePath;
            ui->txtLog->append("Selected file: " + filePath);
        }
    }
    
    void MainWindow::startConversion()
    {
        QString ffmpegPath = "ffmpeg";
        QStringList args;
        args << "-version";
        ui->txtLog->append("Trying to run: " + ffmpegPath + " " + args.join(" "));
        ffmpegProcess->start(ffmpegPath, args);
    
        }
    }
    
    void MainWindow::readProcessOutput()
    {
        QByteArray output = ffmpegProcess->readAllStandardOutput();
        QByteArray errorOutput = ffmpegProcess->readAllStandardError();
    
        if (!output.isEmpty()) {
            ui->txtLog->append(QString::fromLocal8Bit(output));
        }
        if (!errorOutput.isEmpty()) {
            ui->txtLog->append(QString::fromLocal8Bit(errorOutput));
        }
    }
    
    
    void MainWindow::processFinished(int exitCode, QProcess::ExitStatus status)
    {
        Q_UNUSED(status);
        if (exitCode == 0) {
            ui->txtLog->append("✅ Conversion finished successfully!");
        } else {
            ui->txtLog->append("❌ Conversion failed.");
        }
    }
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • U utkugulgec

      Hi. I am making a GUI for ffmpeg and trying to call ffmpeg with QProcess. No matter what I do, I always get
      "qtc.process_stub: Inferior error: QProcess::Crashed "Process crashed".

      • I am working on Windows.
      • ffmpeg is on my path.
      • ffmpeg works in command line.
      • I tried giving the absolute path of ffmpeg to QProcess, no use.
      • QtCreator version 17, with Qt 6.

      The code I am running is below. Basically, when user clicks "convert" button, the app should start ffmpeg with QProcess. To be simple, I tried to get only version information with ffmpeg.

      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          QProcess *ffmpegProcess = new QProcess(this);
          ffmpegProcess->setWorkingDirectory(QCoreApplication::applicationDirPath());
          ffmpegProcess->setProcessChannelMode(QProcess::MergedChannels);
          
          // Connect buttons
          connect(ui->btnSelFile, &QPushButton::clicked, this, &MainWindow::selectInputFile);
          connect(ui->btnConvert, &QPushButton::clicked, this, &MainWindow::startConversion);
      
          // Connect FFmpeg process signals
          connect(ffmpegProcess, &QProcess::readyReadStandardOutput, this, &MainWindow::readProcessOutput);
          connect(ffmpegProcess, &QProcess::readyReadStandardError, this, &MainWindow::readProcessOutput);
          connect(ffmpegProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
                  this, &MainWindow::processFinished);
      }
      
      void MainWindow::selectInputFile()
      {
          QString filePath = QFileDialog::getOpenFileName(this, "Select Video File", "", "Videos (*.mp4 *.mkv *.avi)");
          if (!filePath.isEmpty()) {
              inputFilePath = filePath;
              ui->txtLog->append("Selected file: " + filePath);
          }
      }
      
      void MainWindow::startConversion()
      {
          QString ffmpegPath = "ffmpeg";
          QStringList args;
          args << "-version";
          ui->txtLog->append("Trying to run: " + ffmpegPath + " " + args.join(" "));
          ffmpegProcess->start(ffmpegPath, args);
      
          }
      }
      
      void MainWindow::readProcessOutput()
      {
          QByteArray output = ffmpegProcess->readAllStandardOutput();
          QByteArray errorOutput = ffmpegProcess->readAllStandardError();
      
          if (!output.isEmpty()) {
              ui->txtLog->append(QString::fromLocal8Bit(output));
          }
          if (!errorOutput.isEmpty()) {
              ui->txtLog->append(QString::fromLocal8Bit(errorOutput));
          }
      }
      
      
      void MainWindow::processFinished(int exitCode, QProcess::ExitStatus status)
      {
          Q_UNUSED(status);
          if (exitCode == 0) {
              ui->txtLog->append("✅ Conversion finished successfully!");
          } else {
              ui->txtLog->append("❌ Conversion failed.");
          }
      }
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      @utkugulgec said in Calling ffmpeg with QProcess: crashes:

      QProcess *ffmpegProcess = new QProcess(this);

      This is a local variable...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      U 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        @utkugulgec said in Calling ffmpeg with QProcess: crashes:

        QProcess *ffmpegProcess = new QProcess(this);

        This is a local variable...

        U Offline
        U Offline
        utkugulgec
        wrote last edited by
        #3

        @Christian-Ehrlicher oh, silly me, how I couldn't see it. It worked out. sorry for this thread.

        1 Reply Last reply
        0
        • U utkugulgec has marked this topic as solved
        • Christian EhrlicherC Christian Ehrlicher moved this topic from Qt Creator and other tools

        • Login

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