QProcess with ffmpeg is not working
-
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?
-
@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 usingQProcess::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 findffmpeg.exe
in that directory to run, because it's not on yourPATH
, this won't (shouldn't) work. Pass the full path as the command instead. -
@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(); }
-
-
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();
-
@DungeonLords
What is your question? Your code runs abash -c "...."
, which is fine. Your linked output shows libGL errors. What happens if you runffmpeg -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
?