From 413b0fcb6ed15052302f879d51c4a1cc17ac14b9 Mon Sep 17 00:00:00 2001 From: renbin Date: Fri, 4 Aug 2023 11:15:10 +0800 Subject: [PATCH] fix: Crash when not found libffmpegthumbnailer.so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 软件调整环境变量,可能未查找到库,解析接口时, 遗漏判空处理,导致访问越界; 同时调整创建临时图片的方式,改为 QTemporaryDir 的方式. Log: 修复未查找到ffmpeg依赖包时崩溃的问题 Bug: https://pms.uniontech.com/bug-view-213565.html Influence: MovieCover --- libimageviewer/movieservice.cpp | 13 +++++++++---- libimageviewer/service/ffmpegvideothumbnailer.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libimageviewer/movieservice.cpp b/libimageviewer/movieservice.cpp index c5d61dce..50f6186f 100644 --- a/libimageviewer/movieservice.cpp +++ b/libimageviewer/movieservice.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "unionimage/baseutils.h" #include "service/ffmpegvideothumbnailer.h" @@ -211,12 +212,16 @@ QImage MovieService::getMovieCover_ffmpegthumbnailer(const QUrl &url, const QStr } QString path = url.toLocalFile(); + QString savePath; QFileInfo info(path); + QTemporaryDir tempDir; + // 此处临时文件创建后被删除,调整为使用tmp目录 + if (tempDir.isValid()) { + savePath = tempDir.filePath(info.fileName() + ".png"); + } else { + savePath = QString(bufferPath + info.fileName() + ".png"); + } - //QString savePath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QDir::separator() + info.fileName() + ".png"); - QString savePath(bufferPath + info.fileName() + ".png"); - - QByteArray output; try { QProcess ffmpegthumbnailer; QStringList cmds{"-i", path, "-o", savePath}; diff --git a/libimageviewer/service/ffmpegvideothumbnailer.cpp b/libimageviewer/service/ffmpegvideothumbnailer.cpp index a789f271..909ca65d 100644 --- a/libimageviewer/service/ffmpegvideothumbnailer.cpp +++ b/libimageviewer/service/ffmpegvideothumbnailer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -38,6 +39,12 @@ bool initFFmpegVideoThumbnailer() m_mvideo_thumbnailer_create_image_data = reinterpret_cast(library.resolve("video_thumbnailer_create_image_data")); m_mvideo_thumbnailer_destroy_image_data = reinterpret_cast(library.resolve("video_thumbnailer_destroy_image_data")); m_mvideo_thumbnailer_generate_thumbnail_to_buffer = reinterpret_cast(library.resolve("video_thumbnailer_generate_thumbnail_to_buffer")); + + if (nullptr == m_creat_video_thumbnailer) { + qWarning() << QString("Resolve libffmpegthumbnailer.so data failed, %1").arg(library.errorString()); + resolveSuccessed = false; + return false; + } m_video_thumbnailer = m_creat_video_thumbnailer(); if (m_mvideo_thumbnailer_destroy == nullptr