Expose AMF driver diagnostics and effective encoder settings

This commit is contained in:
evgeny committed 2026-10-18 18:50:20 +02:00
1 parent b8bc9b409a
commit 78b147f806
4 files changed
+86 -14

No files matched your search

+19 -4
View File
@@ -8,6 +8,7 @@
extern "C" {
#include "../../../src/stream/stream_media.h"
#include "../../../src/call/call_video_bitstream.h"
#include "../../../src/video/video.h"
#ifdef HAVE_FFMPEG
#include <libavcodec/avcodec.h>
#include <libavcodec/bsf.h>
@@ -143,6 +144,7 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) {
m->error = "Invalid video configuration"; DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop encoder invalid configuration"); return false;
}
#ifdef HAVE_FFMPEG
video_ffmpeg_init();
for (const auto& name : encoders(config.codec)) {
if (!matchesBackend(name, backend)) continue;
if (!config.backend.isEmpty() && name != config.backend.toLatin1()) continue;
@@ -333,6 +335,21 @@ bool LiveVideoEncoder::open(const LiveVideoConfig& config, Backend backend) {
}
continue;
}
if (name.endsWith("_amf")) {
QByteArray settings;
for (const char* option : {"usage", "rc", "quality", "enforce_hrd", "filler_data", "skip_frame",
"min_qp_i", "max_qp_i", "min_qp_p", "max_qp_p"}) {
int64_t value = 0;
int result = av_opt_get_int(c->priv_data, option, 0, &value);
if (!settings.isEmpty()) settings += ' ';
settings += QByteArray(option) + '=' + (result >= 0 ? QByteArray::number(value) : QByteArray("unavailable"));
}
DEBUG_INFO(DEBUG_CATEGORY_DEBUG,
"AMF effective settings encoder=%s %s target_bps=%lld max_bps=%lld vbv_bits=%d qmin=%d qmax=%d "
"time_base=%d/%d framerate=%d/%d; driver trace requires debug=trace",
name.constData(), settings.constData(), (long long)c->bit_rate, (long long)c->rc_max_rate, c->rc_buffer_size,
c->qmin, c->qmax, c->time_base.num, c->time_base.den, c->framerate.num, c->framerate.den);
}
DEBUG_INFO(DEBUG_CATEGORY_VIDEO,
"desktop encoder ready name=%s codec=%d size=%dx%d fps=%d bitrate=%d level=%d refs=%d vbv=%d profile_verified=%d forced_keys=%d",
name.constData(), config.codec, config.width, config.height, config.fps, config.bitrate,
@@ -378,9 +395,6 @@ bool LiveVideoEncoder::encode(const QImage& image, uint64_t pts, bool key, QList
qPrintable(m->name), m->timestamps.size(), (unsigned long long)pts); return false;
}
bool forceKey = key && (m->forcedKeys || m->submittedFrames == 0);
if (key && !forceKey) DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO,
"desktop AMF ignores forced key request; periodic GOP IDR remains active name=%s submitted=%lld",
qPrintable(m->name), (long long)m->submittedFrames);
m->frame->pts = av_rescale_q(static_cast<int64_t>(pts), AVRational{1, 1000000}, m->codec->time_base);
m->frame->pict_type = forceKey ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_NONE;
if (forceKey) m->frame->flags |= AV_FRAME_FLAG_KEY; else m->frame->flags &= ~AV_FRAME_FLAG_KEY;
@@ -420,7 +434,8 @@ bool LiveVideoEncoder::encode(const QImage& image, uint64_t pts, bool key, QList
}
encoded.pts = m->timestamps.front().second; m->timestamps.pop_front();
}
if (key) DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "desktop requested KEY name=%s input_PTS=%llu output_PTS=%llu key=%d flags=%x bytes=%d",
if (key && (encoded.key || m->forcedKeys)) DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO,
"desktop requested KEY name=%s input_PTS=%llu output_PTS=%llu key=%d flags=%x bytes=%d",
qPrintable(m->name), (unsigned long long)pts, (unsigned long long)encoded.pts, encoded.key, packet->flags, packet->size);
if (encoded.key) {
const uint8_t* config = m->filter ? m->filter->par_out->extradata : m->codec->extradata;