I’m writing an ffmpeg wrapper and want to display the ffmpeg output in a TextEdit box in real time (same as ffmpeg outputs into a konsole). I could only manage to display help and formats output, but it doesn’t show any file conversion output. Any one knows how to capture that? In any language (C# preferred)?
This is my code in C# and Qt (Qyoto):
QProcess proc = new QProcess(this);
string line;
proc.Start("ffmpeg -i video.avi video.mp4");
proc.WaitForFinished();
proc.SetReadChannel(QProcess.ProcessChannel.StandardOutput);
QTextStream reader = new QTextStream(proc.ReadAllStandardOutput());
while ((line = reader.ReadAll()) != null) {
txtLog.Append(line);
}
QProcess emits signals when there’s something to read from the child process so you can read the messages when you connect the signal to some slot. The other possibility is to use QProcess::readAllStandardOutput () to read the standard output. For more informations have a look at the documentation Qt 4.3: QProcess Class Reference
I guess that these functions and signals are also available in the Qt C# library.
in your example I would leave away the call to SetReadChannel() after the process finished it might reset the input. When you explicit want to call this method, which isn’t necessary because you are setting it to the default value, you should do that before starting the process.
QProcess emits signals when there’s something to read from the child process so you can read the messages when you connect the signal to some slot. The other possibility is to use QProcess::readAllStandardOutput () to read the standard output. For more informations have a look at the documentation Qt 4.3: QProcess Class Reference
That is exactly what I’m doing. My code does read output from ffmpeg but only if I use ‘-help’ or ‘-formats’ arguments but not when I convert files. When I convert files ‘readyReadStandardOutput()’ never triggeres. And I DO use ReadAllStandardOutput().
Is there any way to get the rest of the output? The program does convert the file though. It’s just that ffmpeg doesn’t get to output all of its status info into a text box.
IT’S WORKING!!! excuse my excitement, but is freaking working, I can output ffmpeg output into a text box in real time. Far out! It turned out to be a pretty stupid thing, instead of listening for ‘readyReadStandardOutput()’ I changed it to ‘readyReadStandardError()’, how couldn’t I think of that before?
So, for everyone with the same problem, here’s my code extract which runs ffmpeg as a process and outputs its info into a text box: