mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-10 04:52:41 +01:00
Add smaller preview thumbnail generation. This should speed up loading preview images in the installed section. The image size is now the same as the width of the thumbnail. Also the image size gets reduced by tenfold. If no previewThumbnail is found the regular preview is used instead. This is not recommended.
This commit is contained in:
parent
b8b39a21e8
commit
1094b098c0
@ -36,6 +36,9 @@ Item {
|
||||
case CreateImportVideo.ConvertingPreviewImage:
|
||||
txtConvert.text = qsTr("Generating preview image...")
|
||||
break
|
||||
case CreateImportVideo.ConvertingPreviewThumbnailImage:
|
||||
txtConvert.text = qsTr("Generating preview thumbnail image...")
|
||||
break
|
||||
case CreateImportVideo.ConvertingPreviewImageFinished:
|
||||
imgPreview.source = "file:///" + ScreenPlay.create.workingDir + "/preview.jpg"
|
||||
imgPreview.visible = true
|
||||
|
@ -124,6 +124,7 @@ void Create::saveWallpaper(QString title, QString description, QString filePath,
|
||||
} else {
|
||||
obj.insert("preview", "preview.jpg");
|
||||
}
|
||||
obj.insert("previewThumbnail", "previewThumbnail.jpg");
|
||||
obj.insert("type", "videoWallpaper");
|
||||
|
||||
QJsonArray tagsJsonArray;
|
||||
|
@ -33,6 +33,11 @@ void CreateImportVideo::process()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!createWallpaperImageThumbnailPreview() || QThread::currentThread()->isInterruptionRequested()) {
|
||||
emit abortAndCleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!createWallpaperImagePreview() || QThread::currentThread()->isInterruptionRequested()) {
|
||||
emit abortAndCleanup();
|
||||
return;
|
||||
@ -343,6 +348,67 @@ bool CreateImportVideo::createWallpaperGifPreview()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateImportVideo::createWallpaperImageThumbnailPreview()
|
||||
{
|
||||
|
||||
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageThumbnail);
|
||||
|
||||
QStringList args;
|
||||
args.clear();
|
||||
args.append("-y");
|
||||
args.append("-stats");
|
||||
args.append("-ss");
|
||||
args.append("00:00:02");
|
||||
args.append("-i");
|
||||
args.append(m_videoPath);
|
||||
args.append("-vframes");
|
||||
args.append("1");
|
||||
args.append("-q:v");
|
||||
args.append("2");
|
||||
args.append("-vf");
|
||||
args.append("scale=320:-1");
|
||||
args.append(m_exportPath + "/previewThumbnail.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
QScopedPointer<QProcess> proConvertImage(new QProcess());
|
||||
proConvertImage->setArguments(args);
|
||||
#ifdef Q_OS_WIN
|
||||
proConvertImage->setProgram(QApplication::applicationDirPath() + "/ffmpeg.exe");
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
proConvertImage->setProgram(QApplication::applicationDirPath() + "/ffmpeg");
|
||||
#endif
|
||||
proConvertImage->start();
|
||||
|
||||
while (!proConvertImage->waitForFinished(100)) //Wake up every 100ms and check if we must exit
|
||||
{
|
||||
if (QThread::currentThread()->isInterruptionRequested()) {
|
||||
qDebug() << "Interrupt thread";
|
||||
proConvertImage->terminate();
|
||||
if (!proConvertImage->waitForFinished(1000)) {
|
||||
proConvertImage->kill();
|
||||
}
|
||||
break;
|
||||
}
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
QString tmpErrImg = proConvertImage->readAllStandardError();
|
||||
if (!tmpErrImg.isEmpty()) {
|
||||
QFile previewImg(m_exportPath + "/previewThumbnail.jpg");
|
||||
if (!previewImg.exists() || !(previewImg.size() > 0)) {
|
||||
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageThumbnailError);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
emit processOutput(proConvertImage->readAll());
|
||||
proConvertImage->close();
|
||||
emit createWallpaperStateChanged(ImportVideoState::ConvertingPreviewImageThumbnailFinished);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateImportVideo::createWallpaperImagePreview()
|
||||
{
|
||||
|
||||
@ -360,8 +426,6 @@ bool CreateImportVideo::createWallpaperImagePreview()
|
||||
args.append("1");
|
||||
args.append("-q:v");
|
||||
args.append("2");
|
||||
args.append("-vf");
|
||||
args.append("scale=320:-1");
|
||||
args.append(m_exportPath + "/preview.jpg");
|
||||
|
||||
emit processOutput("ffmpeg " + Util::toString(args));
|
||||
|
@ -61,6 +61,9 @@ public:
|
||||
ConvertingPreviewImage,
|
||||
ConvertingPreviewImageFinished,
|
||||
ConvertingPreviewImageError,
|
||||
ConvertingPreviewImageThumbnail,
|
||||
ConvertingPreviewImageThumbnailFinished,
|
||||
ConvertingPreviewImageThumbnailError,
|
||||
ConvertingAudio,
|
||||
ConvertingAudioFinished,
|
||||
ConvertingAudioError,
|
||||
@ -101,6 +104,7 @@ public slots:
|
||||
bool createWallpaperImagePreview();
|
||||
bool createWallpaperVideo();
|
||||
bool extractWallpaperAudio();
|
||||
bool createWallpaperImageThumbnailPreview();
|
||||
|
||||
void setProgress(float progress)
|
||||
{
|
||||
|
@ -136,11 +136,10 @@ void InstalledListModel::loadInstalledContent()
|
||||
"standaloneWidget"
|
||||
};
|
||||
|
||||
if (availableTypes.contains(obj.value("type").toString())){
|
||||
emit addInstalledItem(obj, item.baseName());
|
||||
if (availableTypes.contains(obj.value("type").toString())) {
|
||||
emit addInstalledItem(obj, item.baseName());
|
||||
}
|
||||
|
||||
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,12 @@ struct ProjectFile {
|
||||
if (obj.contains("file"))
|
||||
m_file = obj.value("file");
|
||||
|
||||
if (obj.contains("preview"))
|
||||
m_preview = obj.value("preview");
|
||||
if (obj.contains("previewThumbnail")){
|
||||
m_preview = obj.value("previewThumbnail");
|
||||
} else {
|
||||
if (obj.contains("preview"))
|
||||
m_preview = obj.value("preview");
|
||||
}
|
||||
|
||||
if (obj.contains("previewGIF"))
|
||||
m_previewGIF = obj.value("previewGIF");
|
||||
|
Loading…
Reference in New Issue
Block a user