1

I've got some code that starts mencoder in a QProcess, converts a video while displaying a progress bar, then exits. The problem is, mencoder always exits before it's actually finished. The loop runs through a few times, and then closes. If I comment out the line that updates the progress bar (progress.setValue()), mencoder runs to completion and exits happily.

Been at this for a day, and can't figure it out! Also, I should mention I'm on a Mac.

Any ideas?

Thanks

Marlon

void MainWindow::convertVideo()
{
    QString input_filename = "/var/input.avi";
    QString output_filename = "/var/output.264";

    QStringList arguments;
    arguments << input_filename << "-nosound" << "-of" << "rawvideo" << "-ofps" << "30" << "-vf" << "harddup" << "-ovc" << "x264" << "-x264encopts" << "bframes=0" << "-o" << output_filename;

    QProcess* myProcess = new QProcess(this);
    myProcess->setReadChannel(QProcess::StandardOutput);

    myProcess->start("/opt/local/bin/mencoder", arguments);

    QString output_string;
    QStringList output_pieces;

    QProgressDialog progress("Converting video...", "Abort", 0, 100, this);
    progress.setWindowModality(Qt::WindowModal);
    progress.setValue(0);
    progress.show();


    while(myProcess->state() != QProcess::NotRunning)
    {
        output_string = myProcess->readAllStandardOutput();

        output_pieces = output_string.split(" ");
        QStringList width_string_list = output_pieces.filter("%)");
        if(width_string_list.length() > 0)
        {
            width_string_list = width_string_list[width_string_list.length() - 1].split("(");
            if(width_string_list.length() > 1)
            {
                width_string_list = width_string_list[1].split("%");
            }
            else
            {
                width_string_list = width_string_list[0].split("%");
            }

            progress.setValue(width_string_list[0].toInt());

            qDebug() << width_string_list[0].toInt();

        }

        myProcess->waitForReadyRead();
    }

    return;
}
4

1 回答 1

0

我认为 QProcess 在完成工作之前会超时。添加一个myProcess->waitForFinished(-1)可能会有所帮助。然后你的过程不会超时。

于 2012-12-14T06:10:37.647 回答