我的 QProcess 有问题。我将 FFmpeg 和命令添加到 Qt 进程中。当我运行此命令时,我在应该是文件 .mkv 的文件夹中没有看到任何更改。有人说我要添加“ “但是这没有帮助。(我在 macOS Catalina 上这样做)
void MainWindow::Recording(){
qDebug() << "Nagrywam!";
Qrec.setProcessChannelMode(QProcess::MergedChannels);
Qrec.setProgram("/Users/nintyswinty/Desktop/Dev/Qt/build-PlazaPCO-Desktop_Qt_5_15_1_clang_64bit-Debug/ffmpeg");
Qrec.setArguments({"-framerate", "30", "-f", "avfoundation", "-i", "1", "-f", "avfoundation", "-framerate", "30", "-i", "0", "-c:v", "libx264", "-crf", "0", "-preset", "ultrafast", "~/Desktop/PlazaPCO/" + QString::fromStdString(date) + ".mkv\n"});
Qrec.start();
Qrec.waitForFinished();
qDebug() << "Koniec - nagrywam";
}```
“~”和“ " 创建了此错误。必须使用 getenv 而不是 "~' 并删除 " ”.
如何使用 QProcess 示例启动 FFmpeg 完整代码
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();