Update live x264 bitrate and exclude encoders without forced key support

This commit is contained in:
evgeny committed 2026-10-14 12:32:33 +02:00
1 parent e4f9a48c2c
commit 7ad0aa61af
3 files changed
+36 -6

No files matched your search

+14 -1
View File
@@ -406,6 +406,7 @@ void StreamPublishEngine::audioLoop() {
void StreamPublishEngine::videoLoop() {
#ifdef HAVE_STREAM_CAPTURE
std::unique_ptr<StreamVideoEncoder> encoder;
StreamPublishConfig encoding;
QImage lastImage; uint64_t current = 0; uint32_t revision = 0;
int64_t lastPts = -1, lastKey = -1000000, next = 0, report = 0; unsigned count = 0, skipped = 0;
while (m->running) {
@@ -416,6 +417,17 @@ void StreamPublishEngine::videoLoop() {
if (m->frameGeneration == generation) { frame = m->frame; capture = m->framePts; m->frame = {}; }
else capture = -1; }
if (generation != current) {
auto comparable = config.video; comparable.bitrate = encoding.video.bitrate;
bool onlyBitrate = encoder && comparable == encoding.video && config.source.kind == encoding.source.kind
&& config.source.id == encoding.source.id && config.source.window == encoding.source.window;
if (onlyBitrate && encoder->setBitrate(config.video.bitrate)) {
current = generation; encoding = config;
{ std::lock_guard<std::mutex> guard(m->lock);
if (m->generation == generation) { m->good = config; m->hasGood = true; m->confirmedGeneration = generation; } }
QMetaObject::invokeMethod(this, [this, generation] {
if (generation == m->generation) { emit configurationChanged(); emit stateChanged(text("Live")); }
});
} else {
auto candidate = std::make_unique<StreamVideoEncoder>();
if (!candidate->open(config.video)) {
QString error = candidate->error();
@@ -424,9 +436,10 @@ void StreamPublishEngine::videoLoop() {
m->wake.wait_for(lock, std::chrono::milliseconds(100), [this, generation] { return !m->running || m->generation != generation; });
continue;
}
encoder = std::move(candidate); current = generation; revision++; lastImage = {}; lastKey = -1000000;
encoder = std::move(candidate); current = generation; encoding = config; revision++; lastImage = {}; lastKey = -1000000;
DEBUG_INFO(DEBUG_CATEGORY_VIDEO, "desktop video prepared generation=%llu revision=%u encoder=%s",
(unsigned long long)generation, revision, qPrintable(encoder->name()));
}
}
bool screen = config.source.kind != StreamVideoSource::Camera;
if (frame.isValid()) {