Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(wgc-capture): drop pre-flight H.264 MFT check, keep sink-failure diagnostic
EtienneLescot0819961aecd4
diff --git a/electron/native/README.md b/electron/native/README.mdindex 4d475759e..cda6c9f55 100644--- a/electron/native/README.md+++ b/electron/native/README.md@@ -83,7 +83,7 @@ Current V2 JSON shape:The current helper implementation supports display/window video capture, system audio loopback, selected-microphone capture, Media Foundation webcam capture, and a DirectShow webcam fallback for virtual cameras that are not exposed through Media Foundation. Webcam frames are currently composed into the primary MP4 as a bottom-right picture-in-picture overlay. Browser `deviceId` values do not always map to Media Foundation symbolic links or WASAPI endpoint IDs, so the renderer passes both browser IDs and user-visible device names. For microphones, the helper tries the requested WASAPI endpoint ID first, then resolves an active capture endpoint by `microphoneDeviceName`, then falls back to the default endpoint. For webcams, Electron resolves a matching DirectShow filter CLSID for the selected label; the helper uses Media Foundation first, then that exact DirectShow filter when the requested camera is absent from Media Foundation.-Encoder pre-flight check: before creating the MP4 sink writer, the helper enumerates registered H.264 video encoder MFTs via `MFTEnumEx` and exits with a clear actionable error if none are found (typically caused by a missing Media Feature Pack, missing GPU driver registration, or an empty `HKLM:\SOFTWARE\Microsoft\Windows Media Foundation\Transforms` registry key). If the sink writer itself fails, the helper also logs the registered H.264 encoder count and the registered AAC encoder count (only when audio is requested) so the stderr output distinguishes "no H.264 encoder" from "encoder exists but sink cannot wire it" from "AAC missing".+Encoder diagnostic on sink-writer failure: when `MFCreateSinkWriterFromURL` fails, the helper logs the registered H.264 video encoder MFT count (via `MFTEnumEx`), the registered AAC encoder count when audio was requested, and the hex HRESULT. If no H.264 encoder is registered, it additionally emits the four-bullet actionable error (missing Media Feature Pack / GPU driver registration / empty `HKLM:\SOFTWARE\Microsoft\Windows Media Foundation\Transforms` / reboot). If an H.264 encoder IS registered but the sink writer still failed, it logs a hint pointing at invalid output path, missing MP4 mux, or GPU driver incompatibility. The diagnostic runs only on the failure path — there is no pre-flight gating check, because `MFTEnumEx` and `MFCreateSinkWriterFromURL` can disagree about which H.264 encoders are "available" in non-interactive / Session 0 contexts, and a pre-flight zero-count would block a recording the sink writer can otherwise complete.Smoke-test the helper with:diff --git a/electron/native/wgc-capture/src/mf_encoder.cpp b/electron/native/wgc-capture/src/mf_encoder.cppindex 5d15d3c1b..738a29b58 100644--- a/electron/native/wgc-capture/src/mf_encoder.cpp+++ b/electron/native/wgc-capture/src/mf_encoder.cpp@@ -199,17 +199,14 @@ bool MFEncoder::initialize(device_ = device;context_ = context;- // Pre-flight H.264 encoder check (issue #15): the MP4 sink writer fails- // with hr=0x80070003 (ERROR_PATH_NOT_FOUND) when no H.264 encoder MFT is- // registered on the system. Fail fast with an actionable message instead- // of letting the sink writer crash with HRESULT noise. This must run- // before MFStartup so that a missing Media Feature Pack is reported with- // a clear error rather than a confusing MFStartup failure.- const UINT32 h264EncoderCount = countRegisteredH264VideoEncoders();- if (h264EncoderCount == 0) {- logMissingH264EncoderError();- return false;- }+ // No H.264 encoder pre-flight check here. MFTEnumEx and+ // MFCreateSinkWriterFromURL can disagree about which H.264 encoders are+ // "available" in non-interactive / Session 0 contexts (NVENC et al. are+ // registered but their COM server may not fully activate from a service+ // session). A pre-flight that fails fast on a zero MFTEnumEx count would+ // therefore break a recording that the sink writer can complete+ // successfully. The diagnostic dump below runs only on the failure path,+ // so a healthy MFTEnumEx result never blocks a working recording.if (!succeeded(MFStartup(MF_VERSION), "MFStartup")) {return false;@@ -227,20 +224,19 @@ bool MFEncoder::initialize(setFrameRate(outputType.Get(), static_cast<UINT32>(fps_));setPixelAspectRatio(outputType.Get());- // AAC count is only useful if the caller wants audio; compute it lazily- // so a screen-only recording does not pay for an enumeration it does not- // need. Used purely for diagnostics on the sink-writer failure path.- const UINT32 aacEncoderCount = (audioFormat != nullptr)- ? countRegisteredAacAudioEncoders()- : 0;-HRESULT sinkWriterHr = MFCreateSinkWriterFromURL(outputPath.c_str(), nullptr, nullptr, &sinkWriter_);if (FAILED(sinkWriterHr)) {// The HRESULT alone is not actionable. Tell the user whether an H.264// encoder is registered at all (no H.264 == the MFP missing-MFT path),// whether AAC is registered (only when audio is requested), and the- // hex HRESULT so the exact failure is greppable.+ // hex HRESULT so the exact failure is greppable. Encoder counts are+ // computed lazily here, only on the failure path, so a healthy+ // recording does not pay for an MFTEnumEx call.+ const UINT32 h264EncoderCount = countRegisteredH264VideoEncoders();+ const UINT32 aacEncoderCount = (audioFormat != nullptr)+ ? countRegisteredAacAudioEncoders()+ : 0;std::cerr << "ERROR: MFCreateSinkWriterFromURL failed (hr=0x"<< std::hex << sinkWriterHr << std::dec << ")" << std::endl;std::cerr << " Registered H.264 video encoder MFTs: " << h264EncoderCount@@ -249,7 +245,9 @@ bool MFEncoder::initialize(std::cerr << " Registered AAC audio encoder MFTs: " << aacEncoderCount<< std::endl;}- if (h264EncoderCount > 0) {+ if (h264EncoderCount == 0) {+ logMissingH264EncoderError();+ } else {std::cerr<< " An H.264 encoder MFT is registered but the sink writer "<< "still failed. Possible causes: invalid output path or "