video_thumbnail works to be set in rust
Since every slide is asking for their own, we don't need to loop through all slides, we just use the index to put the thumbnail into the right slides and emit data changed.
This commit is contained in:
parent
995f9ffc03
commit
060341adb7
3 changed files with 47 additions and 1 deletions
|
@ -700,6 +700,51 @@ void SlideModel::moveRowFromService(const int &fromIndex,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SlideModel::thumbnailVideoRust(QString video, int serviceItemId, int index, SlideyMod *slideModel) {
|
||||||
|
|
||||||
|
QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails";
|
||||||
|
QDir absDir = writeDir.absolutePath() + "/librepresenter";
|
||||||
|
if (!dir.exists()) {
|
||||||
|
qDebug() << dir.path() << "does not exist";
|
||||||
|
absDir.mkdir("thumbnails");
|
||||||
|
}
|
||||||
|
|
||||||
|
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() << "FOR" << index;
|
||||||
|
if (thumbnailInfo.exists()) {
|
||||||
|
slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
||||||
|
return thumbnailInfo.filePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QImage image;
|
||||||
|
QString filename = video.right(video.size() - 7);
|
||||||
|
image = frameToImage(filename, 576);
|
||||||
|
if (image.isNull()) {
|
||||||
|
qDebug() << QStringLiteral("Failed to create thumbnail for file: %1").arg(video);
|
||||||
|
return "failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "dir location " << writeDir.absolutePath();
|
||||||
|
if (!writeDir.mkpath(".")) {
|
||||||
|
qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!image.save(thumbnailInfo.filePath())) {
|
||||||
|
qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video);
|
||||||
|
}
|
||||||
|
|
||||||
|
slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
||||||
|
|
||||||
|
return thumbnailInfo.filePath();
|
||||||
|
}
|
||||||
|
|
||||||
QString SlideModel::thumbnailVideo(QString video, int serviceItemId, int index) {
|
QString SlideModel::thumbnailVideo(QString video, int serviceItemId, int index) {
|
||||||
|
|
||||||
QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails";
|
QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails";
|
||||||
|
|
|
@ -86,6 +86,7 @@ public:
|
||||||
Q_INVOKABLE QVariantList getItems();
|
Q_INVOKABLE QVariantList getItems();
|
||||||
Q_INVOKABLE int findSlideIdFromServItm(int index);
|
Q_INVOKABLE int findSlideIdFromServItm(int index);
|
||||||
Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId, int index);
|
Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId, int index);
|
||||||
|
Q_INVOKABLE QString thumbnailVideoRust(QString video, int serviceItemId, int index, SlideyMod *slideModel);
|
||||||
QImage frameToImage(const QString &video, int width);
|
QImage frameToImage(const QString &video, int width);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ Item {
|
||||||
property bool showVidBG
|
property bool showVidBG
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (model.videoBackground != "")
|
if (model.videoBackground != "")
|
||||||
SlideModel.thumbnailVideo(model.videoBackground, model.serviceItemId, index);
|
SlideModel.thumbnailVideoRust(model.videoBackground, model.serviceItemId, index, SlideMod);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue