Calling ffmpeg with QProcess: crashes
-
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."); } }
-
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."); } }
@utkugulgec said in Calling ffmpeg with QProcess: crashes:
QProcess *ffmpegProcess = new QProcess(this);
This is a local variable...
-
@utkugulgec said in Calling ffmpeg with QProcess: crashes:
QProcess *ffmpegProcess = new QProcess(this);
This is a local variable...
@Christian-Ehrlicher oh, silly me, how I couldn't see it. It worked out. sorry for this thread.
-
-
C Christian Ehrlicher moved this topic from Qt Creator and other tools