Important: Please read the Qt Code of Conduct -

Unable to run ffmpeg with qProcess to extract a single frame from Video

  • I am trying to extract a single frame from a video using the Qprocess and ffmpeg and store it in a tmp folder. When I run the program in terminal command line it is able to extract it but not when qprocess runs it. I'm developing on a mac. What am I doing wrong.

    QString extractSingleFrame(QString videoPath, QDir tmpDir)
        QString program = ffmpegPath();
        QProcess *ffmpegProcess = new QProcess();
        QString arguments;
        QFileInfo videoInfo(videoPath);
        QString videoName = videoInfo.fileName();
        QString firstFrameName(tmpDir.absolutePath() + "/" + videoName + ".jpg");
        arguments = " -y -i " + QDir::toNativeSeparators(videoPath)
                    + " -frames:v 1 -q:v 1 -f image2 " + QDir::toNativeSeparators(firstFrameName);
        qDebug() << "Starting program" << program + arguments;
        ffmpegProcess->start(program + arguments);
        if (ffmpegProcess->state() == QProcess::Starting){
           qDebug() << "program is starting" + ffmpegProcess->state();
        qDebug() << "done";
        delete ffmpegProcess;
        return firstFrameName;

    This is the printed command
    Starting program "ffmpeg -y -i "/Users/userX/" -vframes 1 -q:v 1 -f image2 "/var/folders/s1/vtv2cx36p3h0000gn/T/test-ywDBgj/""

  • Lifetime Qt Champion

    You seems to append all parameters to one string.
    It might be the reason.
    Normally its a QStringList and given as a separate parameter.

     QObject *parent;
        QString program = "./path/to/Qt/examples/widgets/analogclock";
        QStringList arguments;
        arguments << "-style" << "fusion";
        QProcess *myProcess = new QProcess(parent);
        myProcess->start(program, arguments);

  • I have tried to do:

    ffmpegProcess->start(program , QStringList()
                             << "-y"
                             << "-i"
                             << QDir::toNativeSeparators(videoPath)
                             << "-frames:v 1"
                             << "-q:v 1"
                             << "-f"
                             << "image2"
                             << QDir::toNativeSeparators(firstFrameName));

    This just gives the same result. In both cases ffmpegProcess->state() == QProcess::NotRunning gives a true flag.

    I'm having a hard time getting some error message output to pinpoint this issue. I am new to Qt so further help would be deeply appreciated.
    Using this to debug this gives me only an empty string:

    QString StdOut_sdcompare = ffmpegProcess->readAllStandardOutput();
        qDebug() << StdOut_sdcompare;
        QString StdError_sdcompare = ffmpegProcess->readAllStandardError();
        qDebug() << StdError_sdcompare;

  • Lifetime Qt Champion


    You still don't generate the parameter list correctly:

        QProcess ffmpeg;
        ffmpeg.start("ffmpeg" , QStringList()
                             << "-y"
                             << "-i" << QDir::toNativeSeparators(videoPath)
                             << "-frames:v" << "1"
                             << "-q:v" << "1"
                             << "-f" << "image2"
                             << QDir::toNativeSeparators(firstFrameName));

  • Thanks that did the trick, also I wasn't passing in the full path of ffmpeg.

Log in to reply