Skip to content

Give the encoder time to start before stopping the take - #43

Open
0xBreadguy wants to merge 1 commit into
omacom:masterfrom
0xBreadguy:fix/encoder-startup-budget
Open

0xBreadguy wants to merge 1 commit into
omacom:masterfrom
0xBreadguy:fix/encoder-startup-budget

Conversation

@0xBreadguy

@0xBreadguy 0xBreadguy commented Nov 13, 2026 •

Copy link
Copy Markdown

A 4K take can stop before the GPU encoder is ready. On the Intel/NVIDIA laptop in #42, Writer hits its queue limit about 0.52 seconds after recording starts. NVENC opens successfully at about 0.98 seconds, after Monologue has already stopped the take.

This gives the encoder a short startup allowance. For the first two seconds, Writer can queue up to 60 video frames and two seconds of audio. After that, the existing limits of six frames and 500 ms of audio apply again.

The queues stay bounded, and frames keep their order and capture timestamps. Recording stays at the selected resolution, including the start of the take. The tradeoff is a larger temporary budget for native-frame references during those first two seconds.

Fixes #42.

What was checked

  • A new regression test delays the first JPEG frame's mapping on Qt's encoder thread for one second, using the real encoder. It fails on unmodified master with the encoding warning and passes with this change, keeping all 90 frames and audio.
  • The same one-second stall after recording has been running for two seconds still triggers the queue limit.
  • The full CTest suite passed in omabox: 31 backend checks and 3 UI checks.
  • With the actual Main.qml preview, an Insta360 Link and RØDE PodMic USB, the original v0.4.0 build stopped after 0.333 seconds. The patched build completed a 7.567-second take at 4K30, keeping all 227 frames and audio. NVENC took about a second to open, and the full MP4 decoded without errors.

The hardware check used an Intel Core Ultra 7 155H / RTX 4050 Laptop with Qt 6.12 and FFmpeg 9.0.2. It's a short check on one laptop/camera combination; longer takes and other encoder startup times still need testing.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects the recording path and how takes respond to slow encoder startup.

The PR appears safe to merge, with two non-blocking improvements to the new recording tests.

Findings

  1. P2 Unrelated errors pass the test ▶
  2. P2 Shortened audio passes the test ▶

Summary

Gives the encoder a bounded startup allowance before restoring normal recording limits.

  • Recordings keep more queued media while the encoder starts.

Reviews (1) · Last reviewed commit: "Allow a bounded backlog while the encode..." · Reviewed by Greptile

Comment thread tests/backend_tests.cpp
QTest::qWait(35);
}
writer.finish(); QTRY_VERIFY_WITH_TIMEOUT(ended.count()>0,15000);
if(delayedFrame) { QVERIFY(!errors.isEmpty()); return; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unrelated errors pass the test

The already-recording case passes on any Writer::failed signal, even if recording fails before frame 60 reaches the encoder. That can hide an unrelated failure instead of checking that the later stall still stops recording. Assert that recording stays error-free until the delayed frame, then check for the expected backlog error.

Comment thread tests/backend_tests.cpp
if(delayedFrame) { QVERIFY(!errors.isEmpty()); return; }
QVERIFY2(errors.isEmpty(),errors.isEmpty()?"":qPrintable(errors.first().first().toString()));
auto p=media::probe(directory.filePath("take.mp4")); QVERIFY2(p.ok,qPrintable(p.error));
QVERIFY(p.audio); QVERIFY(std::abs(p.duration-3)<.1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Shortened audio passes the test

The startup case checks all 90 video frames, but checks audio only through p.audio and the overall file duration. media::probe takes that duration from the file, not the audio stream, so shortened audio can still pass alongside three seconds of video. Check the audio stream duration or decoded sample count as well.

@0xBreadguy 0xBreadguy changed the title Allow the encoder to initialize before enforcing recording backlog limits Give the encoder time to start before stopping the take Nov 13, 2026
@RemyDuijkeren

Copy link
Copy Markdown

Works on my machine too, in the audio form of the same problem. On plain 0.4.0, both takes I tried stopped after about 0.4 s with "Audio encoding cannot keep up, so the take was stopped." That happened with and without EasyEffects on the microphone.

With this PR applied on top of 0.4.0, every take records to the end. I made about ten takes today at 1920 × 1080 and 1280 × 720, between 5 and 10 s each, and none stopped.

  • AMD Ryzen 7 8845HS, Radeon 780M (no NVIDIA)
  • Logitech C920 (MJPEG 1080p30), fifine USB microphone through PipeWire
  • Omarchy 4.5.0, kernel 7.2.15-1-omarchy, qt6-multimedia 6.12.0

@arjenbloemsma

Copy link
Copy Markdown

I tested this branch on a Framework Laptop 13 Pro (Core Ultra X7 358H, Arc B390, qt6-multimedia 6.12.0-1), where Qt falls back to libx264 at 1080p. In the power-saver profile, 6 of 9 bin/test-camera takes were stopped with "Video encoding cannot keep up", against 5 of 9 on master in the same setting. The stops came at 3.75 to 4.03 s into the take, after the two-second startup allowance, so this looks like a different case from #42. Details of the machine are in #46.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4K recording stops before NVENC is ready on an Intel/NVIDIA laptop (0.4.0)

3 participants