PDA

View Full Version : Qprocess error with ffmpeg



davidlamhauge
3rd February 2014, 19:28
Hi.

I work on a storyboard program.
In line 3-10, I make a series of png-images (640x480 pix), and numbers them "im_00001.png", "im_00002.png" etc. That part works fine.

void animatic::exportAnimatic()
{
int teller = 1;
for (int i = 0; i < pixmapList.size();i++){
QImage image = pixmapList[i].toImage();
for (int j = 0;j < infoList[i][frames].toInt();j++){
image.save(projFilePath + sceneDir + "/" + sceneDir +
tr("_%1.png","DO NOT TRANSLATE").arg(QString::number(teller),5,'0'));
teller += 1;
}
}
QStringList sl;
sl << "-i " + projFilePath + sceneDir + "/" + sceneDir + "_%5d.png";
QString sr;
sl << "-r " + sr.setNum(fps) ;
sl << projFilePath + sceneDir + "/" + sceneDir + ".mp4";
qDebug() << sl;
proc.start("ffmpeg",sl);
int c = 1;
while (proc.state() > 0) {
sleep(5);
qDebug() << proc.state() << c;
c+=1;
}
qDebug() << proc.state() << " at the end...";
qDebug() << proc.exitCode() << " exitcode";
qDebug() << proc.error() << " error";
qDebug() << proc.errorString() << " errorstring";
}
It works fine untill it starts the proc (QProcess).
Here are the debug-messages:


("-i /home/david/tegnefilm/david2/h3/h3_%5d.png", "-r 25", "/home/david/tegnefilm/david2/h3/h3.mp4")
2 1 (while-loop)
2 2 (while-loop)
0 3 (while-loop)
0 at the end...
1 exitcode
5 error
"Ukendt fejl" errorstring ("Unknown error")

If I run:

ffmpeg -i /home/david/tegnefilm/david2/h3/h3_%5d.png -r 25 /home/david/tegnefilm/david2/h3/h3.mp4
in a terminal, it produces a fine mp4-file.
ffmpeg is in the path. I have run the the command from several positions, and it produces a mp4-video every time.
I have also tried to write "/usr/bin/ffmpeg" as the command in line 18, but with the same error messages.
Can anyone help here?

stampede
3rd February 2014, 21:18
I think it is because you have arguments that contains spaces - on windows they are wrapped in "quotes" and passed to the called process as single argument, look:


// simple program that will write passed command line arguments into file

#include <stdio.h>

int main(int argc, char ** argv){
FILE * f = fopen("args.txt","w");
int i=0;
for (i=0 ; i<argc ; ++i){
fprintf(f,"%s\n",argv[i]);
}
fclose(f);
return 0;
}

// QProcess test code:

...
QStringList sl;
sl << "no_space" << "what is this" << "out.txt";
qDebug() << sl;
QProcess proc;
proc.start("args.exe",sl);
qDebug() << proc.waitForStarted();
qDebug() << proc.waitForFinished();


args.txt will contain four arguments, as "what is this" string was passed in as single string, I think you can see how different it is from calling the same process from the console:


args.exe no_space what is this out.txt

now args.txt will contain six arguments.
I don't know how ffmpeg handles its arguments, but my guess is - you have to separate the "-i" and "-r" arguments:


QStringList sl;
sl << "-i";
sl << projFilePath + sceneDir + "/" + sceneDir + "_%5d.png";
QString sr;
sl << "-r"
sl << sr.setNum(fps) ;

davidlamhauge
3rd February 2014, 23:02
Thanks!
I followed your advice, and now it works like a charm...