linuxoid
21st February 2010, 09:13
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.Standa rdOutput);
QTextStream reader = new QTextStream(proc.ReadAllStandardOutput());
while ((line = reader.ReadAll()) != null) {
txtLog.Append(line);
}
Would really appreciate your help. Thank you.
rvgrouik
24th February 2010, 15:51
Hi
I wrote a Qt app that converts mp3 audiobooks to iTunes-compatible audiobooks using ffmpeg, too. Here is what I did to catch stdout & stderr logs from ffmpeg.
I made a wrapper class that takes care of converting tracks, one at a time, by running ffmpeg, then renaming the track (.m4b extension), and tagging it (book name, author, cover jpg, track #, etc). All these operations are atomic so I include all of them in one class.
To get ffmpeg output, I declare 2 private slots in my class:
void ffmpegHasStdout();
void ffmpegHasStderr();
And before running ffmpeg, I connect the appropriate QProcess signals to these slots:
connect(&Runner, SIGNAL(readyReadStandardOutput()), this, SLOT(ffmpegHasStdout()), Qt::QueuedConnection);
connect(&Runner, SIGNAL(readyReadStandardError()), this, SLOT(ffmpegHasStderr()), Qt::QueuedConnection);
Runner is the QProcess instance -- be very careful to use Qt::QueuedConnection! QProcess runs the process in a separate thread.
Here is the code for the slots:
void Converter::ffmpegHasStdout()
{
QString logMsg = QString(Runner.readAllStandardOutput()).trimmed();
qDebug("Converter::ffmpegHasStdout(): %s", qPrintable(logMsg));
emit ffmpegHasLog(logMsg);
}
void Converter::ffmpegHasStderr()
{
QString logMsg = QString(Runner.readAllStandardError()).trimmed();
qDebug("Converter::ffmpegHasStderr(): %s", qPrintable(logMsg));
emit ffmpegHasLog(logMsg);
}
Once caught, I emit the logs to the main GUI window, that has a convenience slot.
Besides, you should get rid of "proc.WaitForFinished();": Qt is fundamentally event-driven, use the signals by connecting QProcess::started() and QProcess::finished(int,QProcess::ExitStatus) to your own slots and deal with it.
I still have some issues though, especially when ffmpeg crashes: sometimes QProcess just notices nothing and hangs. Anybody here has a workaround for this kind of situation?
rvgrouik
ruderik
15th March 2012, 16:06
It's not entirely on-topic ut nevertheless; did you manage to get ffmpeg working within Qt ?
When i start it using the QProcess it just hangs, i get output text, but ffmpeg does no processing.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.