Getting plymouth with ffmpeg

This commit is contained in:
likehomedream 2023-12-13 16:47:40 +08:00
parent f9b9876b84
commit 761ecbd129
1 changed files with 6 additions and 36 deletions

View File

@ -573,7 +573,12 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD
//ffmpeg -i "111.mp4" -vframes 104 "/home/.cache/theme-build/m_time/src/plymouthTheme/%d.png"
//FIX ME :限制条件
QString cache = cachedir.absolutePath()+"/%d.png";
list<<"-i"<<destinationFilePath<<"-vframes"<<"104"<<cache;
list<<"-i"<<destinationFilePath
<<"-vf"
<<"scale='min(100,iw)':min'(100,ih)':force_original_aspect_ratio=decrease"
<<"-vframes"
<<"104"
<<cache;
QProcess p;
p.start("ffmpeg",list);
@ -581,49 +586,14 @@ void ConfigFileManager::copyMp4toCacheDir(const QString &destinationFilePath, QD
qWarning()<<"start get video image failed.";
}
if (!p.waitForFinished(40000)) {
qWarning()<<"wait video image too long time.";
}
QString err=p.readAllStandardError();
QString read=p.readAll();
if (err.contains("not contain any stream")) {
qWarning()<<"get video image failed.";
}
QDir dir(cachedir);
dir.setFilter(QDir::Files | QDir::NoSymLinks);
dir.setNameFilters(QStringList() << "*.png");
QFileInfoList fileList1 = dir.entryInfoList();
foreach (const QFileInfo& fileInfo, fileList1) {
QString fileName = fileInfo.absoluteFilePath();
QImage image(fileName);
if (image.isNull()) {
qDebug() << "Failed to load image:" << fileName;
continue;
}
// 调整图像大小为20x20像素
QSize newSize(100, 100);
QImage resizedImage = image.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QByteArray byteArray;
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
if (!resizedImage.save(&buffer, "PNG", 100)) {
qDebug() << "Failed to resize image:" << fileName;
continue;
}
QString outputFileName = fileInfo.path() + "/" + fileInfo.baseName() + ".png";
qDebug()<<outputFileName;
if (!resizedImage.save(outputFileName, "PNG", 100)) {
qDebug() << "Failed to save image:" << outputFileName;
continue;
}
}
QString thunbnail = cachedir.absolutePath()+"/40.png";
emit updateThumbnail(thunbnail);
}