Skip to content

feat(moq-video): native Windows Media Foundation capture, drop nokhwa#1716

Merged
kixelated merged 1 commit into
devfrom
claude/amazing-colden-8e676b
Jun 14, 2026
Merged

feat(moq-video): native Windows Media Foundation capture, drop nokhwa#1716
kixelated merged 1 commit into
devfrom
claude/amazing-colden-8e676b

Conversation

@kixelated

@kixelated kixelated commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements native Windows webcam capture via Media Foundation, replacing the last nokhwa dependency. Frame capture is now native on all three platforms: AVFoundation/ScreenCaptureKit (macOS), V4L2 (Linux), Media Foundation (Windows).

  • New capture/mediafoundation.rs drives an IMFSourceReader with the source reader's video processor enabled, so whatever the camera emits (MJPEG / YUY2 / NV12) is coerced to NV12. Each sample is copied to a tightly-packed CPU I420 (new I420::from_nv12, a chroma deinterleave with no color conversion) for the openh264 / NVENC path.
  • Devices are enumerated via MFEnumDeviceSources and selected by index or a friendly-name substring (--camera).
  • COM + Media Foundation init/teardown is balanced per open/close on the single blocking capture thread; Drop calls IMFMediaSource::Shutdown so the camera releases promptly (LED off) when the last viewer leaves, preserving the on-demand open/close model that the rest of moq-video relies on.
  • Removes the nokhwa dep; adds windows = "0.62" (resolves to the 0.62.2 already in the tree via netwatch, so no duplicate version). webcam.rs deleted.
  • Docs: DESIGN-native-codecs.md, crate-level docs, and doc/bin/cli.md (which still had stale ffmpeg-era "dshow / h264_videotoolbox" capture wording).

Public API

No public API or wire change. Capture is internal to moq-video; this swaps the Windows backend implementation and removes a dependency. Config, Encoder, Producer, publish_capture, and Error are unchanged. Targets dev, where the rest of the moq-video native-codecs overhaul (#1691, #1704) lives and which the DESIGN doc designates for this work.

Test plan

  • cargo clippy -p moq-video clean (host/macOS)
  • cargo test -p moq-video — 10/10 pass
  • moq-cli --features capture builds (host)
  • Full Media Foundation FFI type-checks against x86_64-pc-windows-msvc (verified in a scratch crate; the whole crate can't cross-compile from the dev Mac because openh264's vendored C++ build needs MSVC)
  • Real Windows + webcam run — not yet done. Needs to confirm (1) the video processor delivers NV12 for common cameras, (2) IMF2DBuffer::ContiguousCopyTo yields unpadded NV12 so the deinterleave is correct, (3) the open / Shutdown / reopen cycle releases and reacquires the camera cleanly. Tracked in the DESIGN doc's "unverified" section.

Remaining DESIGN cleanup after this: re-introduce VAAPI once cros-codecs builds against libva ≥ 2.23.

🤖 Generated with Claude Code

(Written by Claude)

Replace the last nokhwa dependency with a native Media Foundation webcam
capture on Windows, so frame capture is now native on all three platforms
(AVFoundation/ScreenCaptureKit on macOS, V4L2 on Linux, Media Foundation
on Windows).

The new capture drives an IMFSourceReader with the source reader's video
processor enabled, so whatever the camera emits (MJPEG / YUY2 / NV12) is
coerced to NV12, which we deinterleave to CPU I420 for the encoder. Devices
are enumerated via MFEnumDeviceSources and selected by index or a
friendly-name substring. The COM/MF lifecycle is balanced per open/close on
the single blocking capture thread, and Drop calls IMFMediaSource::Shutdown
so the camera releases promptly (LED off) when a viewer leaves, preserving
the on-demand open/close model.

The Windows FFI is type-checked against the x86_64-pc-windows-msvc target,
but the path is not yet exercised on real Windows hardware. See the
DESIGN-native-codecs.md "unverified" section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kixelated
kixelated changed the base branch from main to dev June 14, 2026 02:36
@kixelated
kixelated enabled auto-merge (squash) June 14, 2026 02:53
@kixelated
kixelated disabled auto-merge June 14, 2026 02:54
@kixelated
kixelated merged commit 8396359 into dev Jun 14, 2026
@kixelated
kixelated deleted the claude/amazing-colden-8e676b branch June 14, 2026 02:54
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.

1 participant