trying to use mpv as a thumbnailing utility
This commit is contained in:
parent
fb9d551f6b
commit
1b55be29e5
5 changed files with 48 additions and 31 deletions
|
@ -533,7 +533,7 @@ void MpvObject::seek(double pos)
|
||||||
{
|
{
|
||||||
// qDebug() << "seek" << pos;
|
// qDebug() << "seek" << pos;
|
||||||
pos = qMax(0.0, qMin(pos, m_duration));
|
pos = qMax(0.0, qMin(pos, m_duration));
|
||||||
commandAsync(QVariantList() << "seek" << pos << "absolute");
|
command(QVariantList() << "seek" << pos << "absolute");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpvObject::loadFile(QVariant urls)
|
void MpvObject::loadFile(QVariant urls)
|
||||||
|
@ -542,9 +542,13 @@ void MpvObject::loadFile(QVariant urls)
|
||||||
command(QVariantList() << "loadfile" << urls);
|
command(QVariantList() << "loadfile" << urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpvObject::screenshotToFile(QUrl url) {
|
void MpvObject::screenshotToFile(QString file) {
|
||||||
QString file = url.path() + ".jpg";
|
command(QVariantList() << "show-progress");
|
||||||
commandAsync(QVariantList() << "screenshot-to-file" << file << "video");
|
command(QVariantList() << "screenshot-to-file" << file << "video");
|
||||||
|
command(QVariantList() << "show-progress");
|
||||||
|
qDebug() << "screenshot-to-file" << file << "video";
|
||||||
|
qDebug() << "screenshot made: " << file;
|
||||||
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpvObject::subAdd(QVariant urls)
|
void MpvObject::subAdd(QVariant urls)
|
||||||
|
|
|
@ -137,7 +137,7 @@ public slots:
|
||||||
void stepForward();
|
void stepForward();
|
||||||
void seek(double pos);
|
void seek(double pos);
|
||||||
void loadFile(QVariant urls);
|
void loadFile(QVariant urls);
|
||||||
void screenshotToFile(QUrl url);
|
void screenshotToFile(QString file);
|
||||||
void subAdd(QVariant urls);
|
void subAdd(QVariant urls);
|
||||||
|
|
||||||
bool enableAudio() const { return m_enableAudio; }
|
bool enableAudio() const { return m_enableAudio; }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "slidemodel.h"
|
#include "slidemodel.h"
|
||||||
|
#include "mpv/mpvobject.h"
|
||||||
#include "serviceitem.h"
|
#include "serviceitem.h"
|
||||||
#include "slide.h"
|
#include "slide.h"
|
||||||
#include <qabstractitemmodel.h>
|
#include <qabstractitemmodel.h>
|
||||||
|
@ -12,6 +13,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <QTemporaryDir>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -645,31 +647,41 @@ void SlideModel::moveRowFromService(const int &fromIndex,
|
||||||
|
|
||||||
QString SlideModel::thumbnailVideo(QString video, int serviceItemId) {
|
QString SlideModel::thumbnailVideo(QString video, int serviceItemId) {
|
||||||
|
|
||||||
// if (!writeDir.mkpath(".")) {
|
qDebug() << "dir location " << writeDir.absolutePath();
|
||||||
// qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
if (!writeDir.mkpath(".")) {
|
||||||
// }
|
qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
||||||
|
|
||||||
// qDebug() << "Url of screenshot to be taken: " << url;
|
|
||||||
// QDir dir = writeDir.absolutePath() + "/thumbnails";
|
|
||||||
// qDebug() << "thumbnails dir: " << dir;
|
|
||||||
// QDir absDir = writeDir.absolutePath();
|
|
||||||
// if (!dir.exists())
|
|
||||||
// absDir.mkdir("thumbnails");
|
|
||||||
|
|
||||||
QTemporaryFile thumbnail = ;
|
|
||||||
if (thumbnail.open()) {
|
|
||||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
|
||||||
qDebug() << thumbnail.fileName();
|
|
||||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
|
||||||
|
|
||||||
// return thumbnail.fileName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTemporaryDir dir;
|
QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails";
|
||||||
if (dir.isValid()) {
|
qDebug() << "thumbnails dir: " << dir;
|
||||||
// dir.path() returns the unique directory path
|
QDir absDir = writeDir.absolutePath() + "/librepresenter";
|
||||||
|
if (!dir.exists()) {
|
||||||
|
qDebug() << dir.path() << "does not exist";
|
||||||
|
absDir.mkdir("thumbnails");
|
||||||
|
}
|
||||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||||
qDebug() << dir.path();
|
qDebug() << dir.path();
|
||||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||||
}
|
|
||||||
|
QFileInfo vid(video);
|
||||||
|
QString id;
|
||||||
|
id.setNum(serviceItemId);
|
||||||
|
QString vidName(vid.fileName() + "-" + id);
|
||||||
|
qDebug() << vidName;
|
||||||
|
QString thumbnail = dir.path() + "/" + vidName + ".webp";
|
||||||
|
QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg");
|
||||||
|
qDebug() << thumbnailInfo.filePath();
|
||||||
|
// if (thumbnail.open(QIODevice::ReadOnly)) {
|
||||||
|
// qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||||
|
// qDebug() << thumbnailInfo.filePath();
|
||||||
|
// qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||||
|
// }
|
||||||
|
|
||||||
|
MpvObject *mpv;
|
||||||
|
mpv->loadFile(video);
|
||||||
|
mpv->seek(5);
|
||||||
|
mpv->screenshotToFile(thumbnail);
|
||||||
|
// mpv.quit();
|
||||||
|
|
||||||
|
return thumbnailInfo.filePath();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
Q_INVOKABLE QVariantMap getItem(int index) const;
|
Q_INVOKABLE QVariantMap getItem(int index) const;
|
||||||
Q_INVOKABLE QVariantList getItems();
|
Q_INVOKABLE QVariantList getItems();
|
||||||
Q_INVOKABLE int findSlideIdFromServItm(int index);
|
Q_INVOKABLE int findSlideIdFromServItm(int index);
|
||||||
Q_INVOKABLE void thumbnailVideo(QString video, int serviceItemId);
|
Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -59,7 +59,8 @@ Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onClicked: {
|
onClicked: {
|
||||||
changeSlide(index);
|
/* changeSlide(index); */
|
||||||
|
showPassiveNotification(SlideModel.thumbnailVideo(model.videoBackground, model.serviceItemId));
|
||||||
}
|
}
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
propagateComposedEvents: true
|
propagateComposedEvents: true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue