Show FFmpeg driver errors when hardware encoding fails

This commit is contained in:
evgeny committed 2026-11-01 08:24:43 +01:00
1 parent d8db018166
commit c889928e52
8 files changed
+115 -2

No files matched your search

+10
View File
@@ -2,6 +2,7 @@
#include "video_codec_log.h"
#include <QElapsedTimer>
#include <QPainter>
#include <QStringList>
#include <algorithm>
#include <cstdlib>
#include <cstring>
@@ -151,11 +152,13 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) {
}
#ifdef HAVE_FFMPEG
video_ffmpeg_init();
QStringList failures;
for (const auto& name : encoders(config.codec)) {
if (!matchesBackend(name, backend)) continue;
if (!config.backend.isEmpty() && name != config.backend.toLatin1()) continue;
const AVCodec* encoder = avcodec_find_encoder_by_name(name.constData());
if (!encoder) continue;
VideoCodecErrors diagnostics;
// Проба не оставляет references/PTS в live-контексте: после двух KEY encoder открывается заново.
for (int pass = 0; pass < 2; pass++) {
close(); m->config = config; m->name = QString::fromLatin1(name);
@@ -365,7 +368,14 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) {
c->thread_count, c->active_thread_type);
return true;
}
QString reason = m->error;
const QString details = QString::fromUtf8(diagnostics.text()).trimmed();
if (!details.isEmpty() && details != reason) reason += '\n' + details;
failures.append(QString::fromLatin1(name) + ": " + reason);
CODEC_LOG(DEBUG_LEVEL_WARN, DEBUG_CATEGORY_VIDEO, "desktop encoder attempt failed name=%s reason=%s",
name.constData(), qPrintable(reason));
}
if (!failures.isEmpty()) m->error = failures.join("\n\n");
if (m->error.isEmpty()) m->error = "No working encoder for " + codecName(config.codec);
#else
m->error = "FFmpeg is unavailable";