Results 1 to 3 of 3

Thread: How to get ffmpeg output

  1. #1
    Join Date
    Feb 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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):
    Qt Code:
    1. QProcess proc = new QProcess(this);
    2. string line;
    3. proc.Start("ffmpeg -i video.avi video.mp4");
    4. proc.WaitForFinished();
    5. proc.SetReadChannel(QProcess.ProcessChannel.StandardOutput);
    6. QTextStream reader = new QTextStream(proc.ReadAllStandardOutput());
    7. while ((line = reader.ReadAll()) != null) {
    8. txtLog.Append(line);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Would really appreciate your help. Thank you.

  2. #2
    Join Date
    Feb 2010
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ffmpeg output

    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:
    Qt Code:
    1. void ffmpegHasStdout();
    2. void ffmpegHasStderr();
    To copy to clipboard, switch view to plain text mode 
    And before running ffmpeg, I connect the appropriate QProcess signals to these slots:
    Qt Code:
    1. connect(&Runner, SIGNAL(readyReadStandardOutput()), this, SLOT(ffmpegHasStdout()), Qt::QueuedConnection);
    2. connect(&Runner, SIGNAL(readyReadStandardError()), this, SLOT(ffmpegHasStderr()), Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. void Converter::ffmpegHasStdout()
    2. {
    3. QString logMsg = QString(Runner.readAllStandardOutput()).trimmed();
    4. qDebug("Converter::ffmpegHasStdout(): %s", qPrintable(logMsg));
    5. emit ffmpegHasLog(logMsg);
    6. }
    7.  
    8. void Converter::ffmpegHasStderr()
    9. {
    10. QString logMsg = QString(Runner.readAllStandardError()).trimmed();
    11. qDebug("Converter::ffmpegHasStderr(): %s", qPrintable(logMsg));
    12. emit ffmpegHasLog(logMsg);
    13. }
    To copy to clipboard, switch view to plain text mode 
    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

  3. #3
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get ffmpeg output

    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.

Similar Threads

  1. QImage data via FFmpeg
    By Degenko in forum Qt Programming
    Replies: 9
    Last Post: 14th September 2010, 04:05
  2. do we have ffmpeg like in qt/qt-modules
    By h123 in forum Qt Programming
    Replies: 4
    Last Post: 9th January 2010, 03:09
  3. Replies: 2
    Last Post: 12th July 2009, 08:24
  4. linking problem (ffmpeg)
    By kralyk in forum Qt Programming
    Replies: 2
    Last Post: 13th April 2009, 07:35
  5. output UTF?
    By mikro in forum Newbie
    Replies: 4
    Last Post: 18th May 2006, 23:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.