summaryrefslogtreecommitdiffstats
path: root/helper.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-08-11 08:01:22 +0200
committerArno <am@disconnect.de>2013-08-11 08:01:22 +0200
commit7b374095aaec92e0fb7044550903aa8e10522677 (patch)
tree82fa5c69f56db2a6def9923b50916dabbea53ce8 /helper.cpp
parentf597c802ab31560bcc200ab068675ecc34f423c9 (diff)
downloadSheMov-7b374095aaec92e0fb7044550903aa8e10522677.tar.gz
SheMov-7b374095aaec92e0fb7044550903aa8e10522677.tar.bz2
SheMov-7b374095aaec92e0fb7044550903aa8e10522677.zip
Implement preview
Show 4 frames of the selected movie in PictureViewer2.
Diffstat (limited to 'helper.cpp')
-rw-r--r--helper.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/helper.cpp b/helper.cpp
index 3856bfc..348c066 100644
--- a/helper.cpp
+++ b/helper.cpp
@@ -24,6 +24,8 @@
#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
+#include <QPainter>
+#include <QDir>
#include <stdio.h>
@@ -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){