fix(recording): use hardware H.264 on Windows by default - #489
Conversation
…en asked MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS defaults to FALSE, and the "default" sink-writer path (no preferSoftwareEncoder, no OPENSCREEN_WGC_ENABLE_DXGI_INPUT) never set it. So every plain recording ran on the software H.264 encoder regardless of what GPU the machine had -- the DXGI path was the only one that ever asked for hardware. On a fast CPU that's invisible; on the older machines in #460 (a 6th-gen i3, an i5-4590 with HD 4600) it's slow enough to blow the 50-60s stop-shutdown budget and lose the whole recording to a "Timed out waiting for native Windows capture to stop" failure. createSinkWriter now asks for hardware transforms whenever software is not forced, DXGI device manager or not. Verified against the real compiled helper: the default path went from videoEncoderRuntime "software" to "hardware" on this machine, with no other flags set. That uncovered a second, known issue the DXGI path had already fixed once: hardware MFTs default to constant bitrate, which spends the full configured budget doing nothing on a static screen. applyHardwareRateControl's VBR fix was gated on the DXGI path alone; it now runs whenever hardware transforms were requested, matching the wider condition above. Added videoEncoderRuntime ("hardware"/"software"/"unknown") to the encoder-selection event so a bug report can tell these two failure shapes apart going forward: a real hardware encoder stalling on a bad driver, versus every recording quietly running through software regardless of what hardware is on the machine. It introspects the sink writer's own resolved transform pipeline (IMFSinkWriterEx::GetTransformForStream) rather than trusting which path was configured, since MF is free to hand back software even when hardware was requested. Verified end to end on real hardware: compiled with MSVC/CMake, ran the actual helper through the full test matrix (default, software-encoder, DXGI, window, system-audio, microphone, audio-timeline, mic-selection) with no regressions. One accepted trade-off, confirmed back-to-back on this machine: hardware output ran roughly 5x larger than software for the same content even with VBR correctly engaged (8.7 Mbps vs 1.7 Mbps) -- a real rate-distortion difference between the two encoders, not a rate-control bug, and worth the CPU relief and stop-reliability it buys on weak machines. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughWindows recording now detects the encoder runtime selected by Media Foundation. The native event, IPC response, TypeScript result, validation helper, and recording documentation expose the distinction between configured encoder selection and runtime encoder selection. ChangesWindows encoder runtime reporting
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change enables hardware H.264 encoding by default on Windows and reports the selected encoder runtime; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant MFEncoder
participant NativeEvent
participant IPCHandler
participant RecordingResult
MFEncoder->>NativeEvent: emit requested encoder and videoEncoderRuntime
NativeEvent->>IPCHandler: pass encoder-selection metadata
IPCHandler->>RecordingResult: return videoEncoderRuntime
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes the root cause behind #460 ("Timed out waiting for native Windows capture to stop" on Windows machines without a dedicated GPU).
MF_READWRITE_ENABLE_HARDWARE_TRANSFORMSdefaults toFALSEin Media Foundation, and the "default" sink-writer configuration path (nopreferSoftwareEncoder, noOPENSCREEN_WGC_ENABLE_DXGI_INPUT) never set it. So every plain Windows recording ran on the software H.264 encoder regardless of what GPU the machine had — only the opt-in DXGI path ever asked for hardware. That's invisible on a fast CPU, but on the older machines reported in #460 (a 6th-gen i3, an i5-4590 with HD 4600) it's slow enough that shutdown blows the 50-60s stop budget and the recording is lost.createSinkWriternow requests hardware transforms whenever software isn't explicitly forced, DXGI device manager or not.videoEncoderRuntimefield ("hardware"/"software"/"unknown") to the helper'sencoder-selectionevent, so a future bug report can tell "a real hardware encoder stalled on a bad driver" apart from "this machine is still silently on software" — it introspects the sink writer's actual resolved transform pipeline rather than trusting which path was configured.Verification
Compiled with the real MSVC/CMake toolchain and ran the actual helper end to end (not just
tsc/lint):videoEncoderRuntimeflipped from"software"to"hardware"on this machine, with no other flags set.--software-encoder,OPENSCREEN_WGC_ENABLE_DXGI_INPUT=1,--window,--system-audio,--microphone,test:wgc-audio-timeline:win,test:wgc-mic-selection:win.tsc --noEmitandbiome checkclean.One accepted trade-off, confirmed back-to-back on this machine: hardware output ran roughly 5x larger than software for the same content even with VBR correctly engaged (8.7 Mbps vs 1.7 Mbps) — a real rate-distortion difference between the two encoder implementations, not a rate-control bug. Worth it for the CPU relief and stop-reliability on the weak machines this is meant to fix.
Test plan
Save Diagnosticsnow includesvideoEncoderRuntimein theencoder-selectionline for a fresh recording🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests