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;
|
||||
pos = qMax(0.0, qMin(pos, m_duration));
|
||||
commandAsync(QVariantList() << "seek" << pos << "absolute");
|
||||
command(QVariantList() << "seek" << pos << "absolute");
|
||||
}
|
||||
|
||||
void MpvObject::loadFile(QVariant urls)
|
||||
|
@ -542,9 +542,13 @@ void MpvObject::loadFile(QVariant urls)
|
|||
command(QVariantList() << "loadfile" << urls);
|
||||
}
|
||||
|
||||
void MpvObject::screenshotToFile(QUrl url) {
|
||||
QString file = url.path() + ".jpg";
|
||||
commandAsync(QVariantList() << "screenshot-to-file" << file << "video");
|
||||
void MpvObject::screenshotToFile(QString file) {
|
||||
command(QVariantList() << "show-progress");
|
||||
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)
|
||||
|
|
|
@ -137,7 +137,7 @@ public slots:
|
|||
void stepForward();
|
||||
void seek(double pos);
|
||||
void loadFile(QVariant urls);
|
||||
void screenshotToFile(QUrl url);
|
||||
void screenshotToFile(QString file);
|
||||
void subAdd(QVariant urls);
|
||||
|
||||
bool enableAudio() const { return m_enableAudio; }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "slidemodel.h"
|
||||
#include "mpv/mpvobject.h"
|
||||
#include "serviceitem.h"
|
||||
#include "slide.h"
|
||||
#include <qabstractitemmodel.h>
|
||||
|
@ -12,6 +13,7 @@
|
|||
#include <QFile>
|
||||
#include <QMap>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTemporaryDir>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QSettings>
|
||||
|
@ -645,31 +647,41 @@ void SlideModel::moveRowFromService(const int &fromIndex,
|
|||
|
||||
QString SlideModel::thumbnailVideo(QString video, int serviceItemId) {
|
||||
|
||||
// if (!writeDir.mkpath(".")) {
|
||||
// qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
||||
qDebug() << "dir location " << writeDir.absolutePath();
|
||||
if (!writeDir.mkpath(".")) {
|
||||
qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
||||
}
|
||||
|
||||
QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails";
|
||||
qDebug() << "thumbnails dir: " << dir;
|
||||
QDir absDir = writeDir.absolutePath() + "/librepresenter";
|
||||
if (!dir.exists()) {
|
||||
qDebug() << dir.path() << "does not exist";
|
||||
absDir.mkdir("thumbnails");
|
||||
}
|
||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
qDebug() << dir.path();
|
||||
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() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
// }
|
||||
|
||||
// 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");
|
||||
MpvObject *mpv;
|
||||
mpv->loadFile(video);
|
||||
mpv->seek(5);
|
||||
mpv->screenshotToFile(thumbnail);
|
||||
// mpv.quit();
|
||||
|
||||
QTemporaryFile thumbnail = ;
|
||||
if (thumbnail.open()) {
|
||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
qDebug() << thumbnail.fileName();
|
||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
|
||||
// return thumbnail.fileName();
|
||||
}
|
||||
|
||||
QTemporaryDir dir;
|
||||
if (dir.isValid()) {
|
||||
// dir.path() returns the unique directory path
|
||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
qDebug() << dir.path();
|
||||
qDebug() << "@@@@@@@@@@@@@@@@@@@@@";
|
||||
}
|
||||
return thumbnailInfo.filePath();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
Q_INVOKABLE QVariantMap getItem(int index) const;
|
||||
Q_INVOKABLE QVariantList getItems();
|
||||
Q_INVOKABLE int findSlideIdFromServItm(int index);
|
||||
Q_INVOKABLE void thumbnailVideo(QString video, int serviceItemId);
|
||||
Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId);
|
||||
|
||||
|
||||
public slots:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue