How to get ffmpeg output

Hi,

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);
}

Would really appreciate your help. Thank you.

Hi,

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.

Hope this helps

Oh i forgot :slight_smile:

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.

Hope this helps

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().

ok, I’ve managed to get some output from ffmpeg:


FFmpeg version UNKNOWN, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Feb  6 2010 12:16:08 with gcc 4.4.1 [gcc-4_4-branch revision 150839]
  configuration: --shlibdir=/usr/lib64 --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib64 --enable-shared --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libfaad --enable-libfaac --enable-nonfree --enable-libxvid --enable-postproc --enable-gpl --enable-x11grab --enable-libschroedinger --enable-libdirac --enable-libgsm --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libdc1394 --enable-pthreads
  libavutil     50. 8. 0 / 50. 8. 0
  libavcodec    52.52. 0 / 52.52. 0
  libavformat   52.50. 0 / 52.50. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Input #0, avi, from '/home/linuxoid/Temp/video.avi':
  Duration: 00:00:09.00, start: 0.000000, bitrate: 554 kb/s
    Stream #0.0: Video: msvideo1, rgb555le, 160x100, 10 tbr, 10 tbn, 10 tbc

Output #0, matroska, to '/home/linuxoid/Temp/fdhdfh.mkv':
    Stream #0.0: Video: mpeg4, yuv420p, 160x100, q=2-31, 200 kb/s, 1k tbn, 10 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding

frame=   90 fps=  0 q=2.9 Lsize=     268kB time=9.00 bitrate= 243.6kbits/s    
video:266kB audio:0kB global headers:0kB muxing overhead 0.471088%

and then it stopped. I use this code:


Connect(proc, SIGNAL("readyReadStandardError()"), this, SLOT("OnProcessOutputReady()"));

[Q_SLOT]
private void OnBtnStartClicked() {
...
// codec = ffmpeg
// arguments = -i video.avi video.mp4
...
proc.Start(codec, arguments);

}
		
[Q_SLOT]
private void OnProcessOutputReady() {
	proc.WaitForBytesWritten();
	QByteArray cmdoutput = proc.ReadAllStandardError();
	String txtoutput = cmdoutput.ConstData();
	this.txtLog.Append(txtoutput);
	cmdoutput = proc.ReadAllStandardError();
	txtoutput = cmdoutput.ConstData();
	this.txtLog.Append(txtoutput);
}

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.

This is taken from the ffmpeg FAQ:
"3.5 How can I read from the standard input or write to the standard output?
Use `-’ as file name. "

Anyone know what it means?

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:


...
Connect(btnStart, SIGNAL("clicked()"), this, SLOT("OnBtnStartClicked()"));
Connect(proc, SIGNAL("readyReadStandardError()"), this, SLOT("OnProcessOutputReady()"));
...

[Q_SLOT]
private void OnBtnStartClicked() {
        string source = txtSourceFile.Text;
        string destination = txtDestinationFolder.Text + "/" + txtDestinationFile.Text;
        List<string> arguments = new List<string>();
        arguments.Add("-i");
        arguments.Add(source);
        arguments.Add(destination);
        if (CheckSourceInput() && CheckDestinationInput()) {
                txtLog.Clear();
                proc.Start(codec, arguments);
        }
}

[Q_SLOT]
private void OnProcessOutputReady() {
        proc.WaitForBytesWritten();
        QByteArray output = proc.ReadAllStandardError();
        String txtoutput = output.ConstData();
        this.txtLog.Append(txtoutput);
}

Good that it works for you now. It looks like ffmpeg prints it output to stderr. Nice to know :slight_smile:

Have a lot of fun