Link the persistent preview cache and keep image preparation free of temporary files

This commit is contained in:
evgeny committed 2026-10-28 15:04:03 +01:00
1 parent e85cb022e2
commit 41d5df798e
3 files changed
+15 -5

No files matched your search

+6 -4
View File
@@ -13,6 +13,7 @@
#include <QTemporaryDir>
#include <QTransform>
#include <cmath>
#include <optional>
extern "C" {
#include "video/video.h"
#ifdef HAVE_FFMPEG
@@ -65,7 +66,7 @@ int videoRotation(const QString& path) {
int index = av_find_best_stream(format, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0); int rotation = 0;
const uint8_t* matrix = nullptr; size_t size = 0;
if (index >= 0) {
#if LIBAVFORMAT_VERSION_MAJOR >= 60
#if LIBAVFORMAT_VERSION_MAJOR >= 61
const auto* parameters = format->streams[index]->codecpar;
const auto* side = av_packet_side_data_get(parameters->coded_side_data, parameters->nb_coded_side_data, AV_PKT_DATA_DISPLAYMATRIX);
if (side) { matrix = side->data; size = side->size; }
@@ -85,11 +86,12 @@ int videoRotation(const QString& path) {
}
QImage prepare(const QString& path, Kind kind, QString& error) {
QTemporaryDir temporary;
std::optional<QTemporaryDir> temporary;
QString input = path; int rotation = 0;
if (kind == Kind::Video) {
if (!temporary.isValid()) { error = temporary.errorString(); return {}; }
input = temporary.filePath(QStringLiteral("first-frame.jpg"));
temporary.emplace();
if (!temporary->isValid()) { error = temporary->errorString(); return {}; }
input = temporary->filePath(QStringLiteral("first-frame.jpg"));
if (video_extract_thumbnail(path.toUtf8().constData(), input.toUtf8().constData(), MaxSide) != 0) {
error = QStringLiteral("cannot decode first video frame"); return {};
}