Results 1 to 3 of 3

Thread: How to get ffmpeg output

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  2. #2
    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
  •  
Qt is a trademark of The Qt Company.