我有一些代码在QProcess中启动mencoder,在显示进度条的同时转换视频,然后退出。问题是,mencoder总是在实际完成之前退出。循环运行几次,然后关闭。如果我注释掉更新进度条的行(progress.setValue()),mencoder将运行完成并快乐退出。
已经在这一天了,无法弄清楚!另外,我应该提一下我在Mac上。
有什么想法吗?
由于
马龙
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;
}
答案 0 :(得分:0)
我认为QProcess在完成工作之前会超时。添加myProcess->waitForFinished(-1)
可能会有所帮助。然后你的过程不会超时。