From 7b374095aaec92e0fb7044550903aa8e10522677 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 11 Aug 2013 08:01:22 +0200 Subject: Implement preview Show 4 frames of the selected movie in PictureViewer2. --- helper.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp index 3856bfc..348c066 100644 --- a/helper.cpp +++ b/helper.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include @@ -250,6 +252,44 @@ namespace Helper { return QJsonDocument::fromJson(ffData); } + QPixmap preview(const QString &path){ + QVariantMap m = ffmpegData(path); + int secs = m.value("duration").toDouble(); + int interval = secs / 4; + QImage retval(640 * 2 + 40, 480 * 2 + 40, QImage::Format_ARGB32); + retval.fill(Qt::transparent); + QPainter p(&retval); + QImage img1 = snapshot(path, 20); + p.drawImage(0, 0, img1); + QImage img2 = snapshot(path, interval * 2); + p.drawImage(680, 0, img2); + QImage img3 = snapshot(path, interval * 3); + p.drawImage(0, 520, img3); + QImage img4 = snapshot(path, secs - 60); + p.drawImage(680, 520, img4); + QPixmap pmretval = QPixmap::fromImage(retval); + return pmretval; + } + + QImage snapshot(const QString &path, int where){ + QSettings s; + QString ffmpeg = s.value("paths/ffmpeg").toString(); + QStringList args; + QTemporaryFile tf; + tf.open(); + args << "-y" << "-ss" << QString::number(where) << "-i" << path << "-f" << "image2" << "-vframes" << "1" << tf.fileName(); + QProcess ffproc; + ffproc.start(ffmpeg, args); + if(!ffproc.waitForStarted()){ + return QImage(); + } + if(ffproc.state() == QProcess::Running){ + ffproc.waitForFinished(); + } + QImage retval(tf.fileName()); + return retval.scaledToWidth(640); + } + Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {} Duration::Duration(qint64 seconds){ -- cgit v1.2.3-70-g09d2