win-native-media-0.1.0 has been yanked.
win-native-media
A native Windows media capture, encode, record, and stream pipeline in Rust — no FFmpeg required.
Captures the screen via Windows.Graphics.Capture, encodes to H.264 via Media Foundation, records to MP4, and streams via RTMP. Audio capture (WASAPI loopback + microphone) and AAC encoding are included. Frames stay on the GPU through the encode stage; no per-frame readbacks.
Features
- Screen capture: Windows Graphics Capture (WGC) with cursor toggle and monitor/window selection.
- Video encoding: Hardware-accelerated H.264 (with software fallback) via Media Foundation MFT.
- Audio capture: WASAPI system loopback and microphone with AAC encoding.
- Recording: MP4 muxing with separate audio tracks (loopback + mic) via IMFSinkWriter.
- Streaming: RTMP publish client (hand-rolled, no external RTMP library) with FLV container.
- Forking: Single encoded stream to both record and stream consumers with asymmetric drop policy (record lossless, stream drops non-keyframes under backpressure).
- Public API:
Pipelinetype hides all Windows COM/Media Foundation details; configurable viaPipelineConfig.
Usage
Add to Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt", "macros", "sync"] }
Minimal example:
use ;
async
See examples/ for runnable demonstrations of each milestone (capture, encode, record, stream, fork, audio, full API).
Configuration
All settings are PipelineConfig fields:
capture_target:Monitor(index)orWindow(hwnd).capture_cursor: Include mouse cursor in frames.- Video:
width,height,fps,bitrate(bits/sec),keyframe_interval(frames). - Audio: Optional
AudioConfigwithloopback,microphone,bitrateflags. Set toNonefor video-only. record: OptionalRecordConfigwithoutput_pathfor MP4.Noneto disable.stream: OptionalStreamConfigwith RTMPurlandstream_key.Noneto disable.
At least one of record or stream must be enabled.
See the API configuration docs for detailed field reference and presets.
Architecture
Capture (WGC) → Encode (MF H.264) → Fork → Record (MP4 muxing)
↘ Stream (RTMP client)
- Capture (
capture.rs): Direct3D11 device, frame pool with resize handling, QPC timestamps. - Encode (
encoder/mf_h264.rs): Media Foundation H.264 MFT (async event loop for hardware, sync for software); output via Annex-B NAL units. - Convert (
convert.rs): BGRA→NV12 via D3D11 Video Processor (GPU-resident). - Fork (
fork.rs): Broadcast encoded samples to record and stream branches; backpressure handling. - Mux (
mux.rs): IMFSinkWriter MP4 output with optional audio tracks. - Stream (
stream/): Hand-rolled RTMP client (handshake, AMF0, chunking, FLV tags). - Audio (
audio/): WASAPI capture + Media Foundation AAC encoder; optional loopback+mic mixing. - Pipeline (
pipeline.rs): Orchestrator; public API hides COM and MF types.
Platform Requirements
- Windows 10+ (Windows 11 recommended).
- GPU with H.264 encoding support (Intel Quick Sync, NVIDIA NVENC, AMD VCE) or software fallback.
- Default audio device (loopback and/or microphone).
Known Limitations
- 4K@30 fps on the software encoder may not sustain; the hardware async MFT zero-copy path (M2b) is in progress for efficiency at 4K.
- RTMP only: no RTMPS or other protocols yet.
- MP4 only for recording: no WebM, MKV, or other containers in v1.
- Single RTMP stream: no multi-bitrate or adaptive streaming yet.
Testing
Run examples:
Run unit tests:
Crate Details
- Edition: 2021
- Dependencies:
windows(0.62, with graphics/media features),tokio(async runtime),thiserror(error handling),tracing(instrumentation). - No FFmpeg, no external RTMP library: All encoding, muxing, and streaming are native.
License
(Add your license here.)