From 2bb77bf0c2b479475e559dd27d8eddcef9fd5ca0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 26 Sep 2009 05:17:37 -0400 Subject: Encoding skeleton and cleanups. --- dvdimagejobgui.cpp | 2 +- encodemp4job.cpp | 33 ++++++++++++++++++++++++++++++--- encodemp4job.h | 2 ++ job.cpp | 9 +++++++-- job.h | 4 +++- mainwindow.cpp | 2 ++ videogui.cpp | 1 + videogui.h | 4 ++-- videoqueue.cpp | 10 +++++----- 9 files changed, 53 insertions(+), 14 deletions(-) diff --git a/dvdimagejobgui.cpp b/dvdimagejobgui.cpp index 7041ebc..5f22b80 100644 --- a/dvdimagejobgui.cpp +++ b/dvdimagejobgui.cpp @@ -14,7 +14,7 @@ DVDImageJobGui::DVDImageJobGui(DVDImageJob *job) : m_progressBar = new QProgressBar; m_progressLabel = new QLabel; QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(new QLabel(tr("Copying DVD ISO"))); + layout->addWidget(new QLabel(tr("Copying DVD ISO of %1").arg(job->video()->title()))); layout->addWidget(m_progressBar); layout->addWidget(m_progressLabel); setLayout(layout); diff --git a/encodemp4job.cpp b/encodemp4job.cpp index 34b82f9..d056002 100644 --- a/encodemp4job.cpp +++ b/encodemp4job.cpp @@ -1,6 +1,10 @@ #include "encodemp4job.h" #include #include +#include +#include +#include +#include EncodeMP4Job::EncodeMP4Job(Video *video, QString encodePath, QString imagePath) : Job(video), @@ -14,9 +18,32 @@ Video::Jobs EncodeMP4Job::jobType() const } bool EncodeMP4Job::executeJob() { - //TODO: encode the actual mp4! - sleep(5); - return true; + QProcess process; + QStringList arguments; + arguments << "-i" << m_imagePath; + arguments << "-o" << m_encodePath; + arguments << "-e" << "x264"; + arguments << "-b" << "500"; + arguments << "-E" << "faac"; + arguments << "-B" << "96"; + arguments << "-R" << "auto"; + arguments << "-6" << "stereo"; + arguments << "-N" << "eng" << "--native-dub"; + arguments << "-f" << "mp4"; + arguments << "-P" << "-2" << "-T"; + arguments << "--optimize" << "--decomb" << "--deblock" << "--denoise=\"weak\""; + arguments << "-x" << "ref=3:mixed-refs:bframes=6:weightb:direct=auto:b-pyramid:me=umh:subme=9:analyse=all:8x8dct:trellis=1:no-fast-pskip:psy-rd=1,1"; + process.start(QLatin1String("HandBrakeCLI"), arguments, QIODevice::ReadOnly); + if (!process.waitForStarted()) + return false; + QTextStream reader(&process); + QRegExp percentLinePattern(QLatin1String("^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\\.[0-9]*) %( \\(([0-9]*\\.[0-9]*) fps, avg ([0-9]*\\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\\))?")); + while (process.waitForReadyRead(-1)) { + if (percentLinePattern.exactMatch(reader.readLine())) { + qDebug() << percentLinePattern.capturedTexts(); //cap(n) + } + } + return process.waitForFinished(-1); } QWidget* EncodeMP4Job::gui() { diff --git a/encodemp4job.h b/encodemp4job.h index 41eef3b..d82bbd0 100644 --- a/encodemp4job.h +++ b/encodemp4job.h @@ -16,6 +16,8 @@ protected: private: QString m_encodePath; QString m_imagePath; +signals: + void encodePercentage(float percentage); }; #endif // ENCODEMP4JOB_H diff --git a/job.cpp b/job.cpp index ae3a9e2..af35104 100644 --- a/job.cpp +++ b/job.cpp @@ -2,14 +2,19 @@ #include "video.h" #include -Job::Job(QObject *parent) +Job::Job(Video *parent) : QObject(parent), - m_gui(0) + m_gui(0), + m_video(parent) { m_watcher = new QFutureWatcher; m_watcher->setParent(this); connect(m_watcher, SIGNAL(finished()), this, SLOT(jobFinished())); } +Video* Job::video() const +{ + return m_video; +} void Job::runJob() { m_watcher->setFuture(QtConcurrent::run(this, &Job::executeJob)); diff --git a/job.h b/job.h index e7b824d..9b276ca 100644 --- a/job.h +++ b/job.h @@ -13,13 +13,15 @@ public: void runJob(); virtual Video::Jobs jobType() const = 0; QWidget* widget(); + Video* video() const; protected: - Job(QObject *parent = 0); + Job(Video *parent); virtual bool executeJob() = 0; virtual QWidget* gui() = 0; private: QFutureWatcher *m_watcher; QWidget *m_gui; + Video *m_video; private slots: void jobFinished(); signals: diff --git a/mainwindow.cpp b/mainwindow.cpp index 147514a..aa20310 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -40,6 +40,8 @@ MainWindow::MainWindow() Video *video = new Video(title, this); if (video->isJobCompleted(Video::DVDImage)) addVideo(video); + else + settings.remove(QString("Videos/%1").arg(title)); } setLayout(layout); } diff --git a/videogui.cpp b/videogui.cpp index d0b2e95..02aad03 100644 --- a/videogui.cpp +++ b/videogui.cpp @@ -34,6 +34,7 @@ VideoGui::VideoGui(Video *video) : layout->addWidget(m_subtitleCheck); layout->addWidget(m_posterCheck); setLayout(layout); + setFrameStyle(QFrame::StyledPanel); } void VideoGui::jobCompleted(Video::Jobs jobType, bool success) { diff --git a/videogui.h b/videogui.h index d087b85..58e20ad 100644 --- a/videogui.h +++ b/videogui.h @@ -1,12 +1,12 @@ #ifndef VIDEOGUI_H #define VIDEOGUI_H -#include +#include #include "video.h" class QCheckBox; class Video; -class VideoGui : public QWidget +class VideoGui : public QFrame { Q_OBJECT public: diff --git a/videoqueue.cpp b/videoqueue.cpp index f4eb639..468d17a 100644 --- a/videoqueue.cpp +++ b/videoqueue.cpp @@ -9,11 +9,11 @@ VideoQueue::VideoQueue(QObject *parent) : QObject(parent), m_jobQueues(QVector(4)) { - m_jobQueues.insert(Video::DVDImage, new JobQueue(this)); - m_jobQueues.insert(Video::EncodeMP4, new JobQueue(this)); - m_jobQueues.insert(Video::Upload, new JobQueue(this)); - m_jobQueues.insert(Video::TitleLoad, new JobQueue(this)); - foreach(JobQueue *queue, m_jobQueues) + m_jobQueues.replace(Video::DVDImage, new JobQueue(this)); + m_jobQueues.replace(Video::EncodeMP4, new JobQueue(this)); + m_jobQueues.replace(Video::Upload, new JobQueue(this)); + m_jobQueues.replace(Video::TitleLoad, new JobQueue(this)); + foreach (JobQueue *queue, m_jobQueues) connect(queue, SIGNAL(runningJob(Job*)), this, SIGNAL(runningJob(Job*))); } void VideoQueue::newVideo(Video *video) -- cgit v1.2.3-59-g8ed1b