18 #include <QMessageBox>
23 : QObject(parent), m_Process(new QProcess(this)), m_Framerate(0), m_IsRunning(false)
25 this->connect(m_Process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(OnProcessError(QProcess::ProcessError)));
28 m_Process, SIGNAL(finished(
int, QProcess::ExitStatus)),
this, SLOT(OnProcessFinished(
int, QProcess::ExitStatus)));
57 m_Size = QSize(width, height);
67 m_Framerate = framerate;
82 if (m_FFmpegPath.isEmpty())
83 mitkThrow() <<
"FFmpeg/Libav path is empty!";
86 mitkThrow() <<
"Invalid video frame size!";
91 if (m_OutputPath.isEmpty())
94 m_Process->start(m_FFmpegPath,
101 << QString(
"%1x%2").arg(m_Size.width()).arg(m_Size.height())
103 << QString(
"%1").arg(m_Framerate)
114 m_Process->waitForStarted();
125 if (frame ==
nullptr || !m_Process->isOpen())
128 m_Process->write(reinterpret_cast<const char *>(frame), m_Size.width() * m_Size.height() * 3);
129 m_Process->waitForBytesWritten();
135 m_Process->closeWriteChannel();
138 void QmitkFFmpegWriter::OnProcessError(QProcess::ProcessError error)
142 MITK_ERROR << QString::fromLatin1(m_Process->readAllStandardError()).toStdString();
146 case QProcess::FailedToStart:
147 mitkThrow() <<
"FFmpeg/Libav failed to start!";
149 case QProcess::Crashed:
152 case QProcess::Timedout:
153 mitkThrow() <<
"FFmpeg/Libav timed out!";
155 case QProcess::WriteError:
156 mitkThrow() <<
"Could not write to FFmpeg/Libav!";
158 case QProcess::ReadError:
159 mitkThrow() <<
"Could not read from FFmpeg/Libav!";
162 mitkThrow() <<
"An unknown error occurred!";
166 void QmitkFFmpegWriter::OnProcessFinished(
int exitCode, QProcess::ExitStatus exitStatus)
170 if (exitStatus != QProcess::CrashExit)
175 mitkThrow() << QString(
"FFmpeg/Libav exit code: %1").arg(exitCode).toStdString().c_str();
QString GetOutputPath() const
void WriteFrame(const unsigned char *frame)
void SetFramerate(int framerate)
void SetFFmpegPath(const QString &path)
void SetSize(const QSize &size)
QString GetFFmpegPath() const
QmitkFFmpegWriter(QObject *parent=nullptr)
void SetOutputPath(const QString &path)