Qprocess error with ffmpeg
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.
Code:
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;
}
}
sl << "-i " + projFilePath + sceneDir + "/" + sceneDir + "_%5d.png";
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:
Code:
("-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:
Quote:
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?
Re: Qprocess error with ffmpeg
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:
Code:
// 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:
...
sl << "no_space" << "what is this" << "out.txt";
qDebug() << sl;
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:
Code:
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:
Code:
sl << "-i";
sl << projFilePath + sceneDir + "/" + sceneDir + "_%5d.png";
sl << "-r"
sl << sr.setNum(fps) ;
Re: Qprocess error with ffmpeg
Thanks!
I followed your advice, and now it works like a charm...