Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge pull request #141 from SaymonMaster14/feat/windows-media-foundation-hwdecode

Brandon Thomasfcf1c45583f2
diff --cc README.md
index f879b6c73,e0751d465..37cdca72d
--- a/README.md
+++ b/README.md
@@@ -286,7 -286,7 +286,7 @@@ We track two numbers ([ROADMAP.md](ROAD
The biggest gaps today:
- - **Speed on big footage.** Hardware decoding works on macOS; Windows and Linux have no hardware path yet. Blend modes and the most common effects run on the GPU, but Lumetri, keys and export rendering still run on the CPU; H.264 encoding can use the hardware encoder on macOS (opt-in), and H.265 export is hardware-only there ([#30](https://github.com/storytold/filmcraft/issues/30)).
-- **Speed on big footage.** Hardware decoding works on macOS and Windows; Linux has no hardware path yet. Blend modes and the most common effects run on the GPU, but Lumetri, keys, export and encoding still run on the CPU ([#30](https://github.com/storytold/filmcraft/issues/30)).
++- **Speed on big footage.** Hardware decoding works on macOS and Windows; Linux has no hardware path yet. Blend modes and the most common effects run on the GPU, but Lumetri, keys and export rendering still run on the CPU; H.264 encoding can use the hardware encoder on macOS (opt-in), and H.265 export is hardware-only there ([#30](https://github.com/storytold/filmcraft/issues/30)).
- **No plugins.** No VST3 / Audio Units or OpenFX hosting.
- **Delivery codecs.** H.264 is our only delivery-codec export; no HEVC or AV1 export yet.
- **Real-world media and platforms.** Our decoders are bit-exact on conformance streams, but camera and phone files in the wild are less tested. Windows and Linux get far less testing than macOS.
diff --cc ROADMAP.md
index 57cb28f45,8a3934200..6a36cd9e1
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -36,7 -36,7 +36,7 @@@ before choosing work
| **Correctness in depth** | not tracked | **~60–70%** | A first-time contributor found four real bugs in core paths within hours (#5–#8: AIFF import failed, Slide left linked audio behind, transitions didn't follow ripple trims, export ignored start/end times). User reports: Color Matte always grey with no picker (#29); ALSA audio error on Linux (#23). Settings are "most wired", not all. |
| **Codecs and media** | ~90% | **~75%** | Our decoders are bit-exact on conformance streams. Real camera and phone media (variable frame rate, damaged files, unusual containers) is far less tested. No camera RAW (RED, BRAW, ARRIRAW), no E-AC-3. |
| **Export** | ~92% | **~70%** | Delivery: H.264 only (ProRes, DNxHR and image sequences cover mastering). No HEVC or AV1 export. AAF and OMF have never been validated in Avid Media Composer or Pro Tools. Export renders and encodes on the CPU only. |
- | **Performance and hardware** | ~62% | **~35–40%** | Premiere runs effects, decoding and encoding on the GPU and the hardware media engines. Here, hardware decode works on macOS only (VideoToolbox, #33; active in the desktop app only since #41, so releases up to 0.2.1 decoded in software). The GPU does compositing, blend modes (#32) and 31 common effects (GPU2): colour adjustments, crop/flip/transform, blurs, sharpen. Lumetri, keys, masks, the remaining effects and export rendering are CPU; H.264 encoding can use VideoToolbox on macOS (opt-in per export, no B-frames), and H.265 (HEVC) export exists there only, through the same hardware encoder. Linux and Windows have no hardware path. 8K and AV1 aren't real-time. The effect list shows Premiere's "GPU accelerated" badge, but only 31 effect ids run on the GPU here; the rest, Lumetri included, run on the CPU. |
-| **Performance and hardware** | ~62% | **~35–40%** | Premiere runs effects, decoding and encoding on the GPU and the hardware media engines. Here, hardware decode works on macOS (VideoToolbox, #33; active in the desktop app only since #41, so releases up to 0.2.1 decoded in software) and Windows (Media Foundation / Direct3D 11 DXVA, H.264 and HEVC Main / Main 10, #30). The GPU does compositing, blend modes (#32) and 31 common effects (GPU2): colour adjustments, crop/flip/transform, blurs, sharpen. Lumetri, keys, masks, the remaining effects, export and encoding are CPU. Linux has no hardware path. 8K and AV1 aren't real-time. The effect list shows Premiere's "GPU accelerated" badge, but only 31 effect ids run on the GPU here; the rest, Lumetri included, run on the CPU. |
++| **Performance and hardware** | ~62% | **~35–40%** | Premiere runs effects, decoding and encoding on the GPU and the hardware media engines. Here, hardware decode works on macOS (VideoToolbox, #33; active in the desktop app only since #41, so releases up to 0.2.1 decoded in software) and Windows (Media Foundation / Direct3D 11 DXVA, H.264 and HEVC Main / Main 10, #30). The GPU does compositing, blend modes (#32) and 31 common effects (GPU2): colour adjustments, crop/flip/transform, blurs, sharpen. Lumetri, keys, masks, the remaining effects and export rendering are CPU; H.264 encoding can use VideoToolbox on macOS (opt-in per export, no B-frames), and H.265 (HEVC) export exists there only, through the same hardware encoder. Linux has no hardware path. 8K and AV1 aren't real-time. The effect list shows Premiere's "GPU accelerated" badge, but only 31 effect ids run on the GPU here; the rest, Lumetri included, run on the CPU. |
| **Stability** | not tracked | **improving, unproven** | The never-crash pass (no panics in product code, last-resort guards) landed on 2026-10-04. There's no field record from real users' projects yet. |
| **Plugins and pro ecosystem** | not tracked | **~0–10%** | No audio plugin hosting (VST3 / Audio Units) and no third-party video effects (OpenFX). For many professional editors this alone rules FilmCraft out. Team Projects and Productions are out of scope by design. |
| **AI features** | partial | **~25–35%** | Speech to text exists but is off in default builds (the `whisper` feature). Enhance Speech is a DSP chain, not a model. Auto Reframe is approximate. No Generative Extend, and no media-intelligence search or auto colour. |
@@@ -48,10 -48,10 +48,10 @@@
In priority order. Agents should prefer this work over adding more checklist items.
1. **Hardware acceleration** (#30), the most visible gap to users:
- - hardware decode on Linux (VA-API) and Windows (Media Foundation);
+ - hardware decode on Linux (VA-API); VP9 / AV1 on Windows;
- zero-copy decoded frames into wgpu;
- the remaining effects on the GPU: Lumetri, keys, Vignette, Video Limiter, masks (31 common effects are done);
- - GPU export, then hardware encode (H.264 / HEVC).
+ - GPU export, then hardware encode: H.264 and H.265 on macOS are in (H.264 opt-in; H.265 has no other encoder); other systems remain.
2. **A measured parity number.** Add `cargo xtask parity`, run in CI. It should cover menus,
commands, effects, transitions, panels, preferences and formats against the Premiere snapshot in
`plan/premiere/`. It should report presence and fidelity separately (exact, approximate, stub).
diff --cc crates/platform/Cargo.toml
index 9ca850cc2,128b1b0c0..af42028f1
--- a/crates/platform/Cargo.toml
+++ b/crates/platform/Cargo.toml
@@@ -26,10 -29,6 +29,7 @@@ filmcraft-time = { workspace = true
log = { workspace = true }
[target.'cfg(target_os = "macos")'.dependencies]
- filmcraft-color = { workspace = true }
+filmcraft-export = { workspace = true }
- filmcraft-frame = { workspace = true }
- filmcraft-time = { workspace = true }
objc2-core-foundation = "0.3.2"
objc2-core-media = "0.3.2"
objc2-core-video = "0.3.2"
diff --cc crates/platform/src/lib.rs
index ed759ff57,e89f4fedb..706da0c38
--- a/crates/platform/src/lib.rs
+++ b/crates/platform/src/lib.rs
@@@ -25,9 -22,11 +25,13 @@@
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]
+ mod annexb;
+ mod biplanar;
+#[cfg(target_os = "macos")]
+pub mod hardware_encode;
pub mod hybrid;
+ #[cfg(target_os = "windows")]
+ pub mod media_foundation;
#[cfg(target_os = "macos")]
#[allow(unsafe_code)]
pub mod videotoolbox;
@@@ -53,11 -49,16 +57,18 @@@ pub fn register() -> Availability
#[cfg(target_os = "macos")]
{
filmcraft_codecs::register_video_decoder(videotoolbox_factory);
+ filmcraft_export::register_encoder(hardware_encode::videotoolbox_encoder_factory);
+ filmcraft_export::register_format_probe(filmcraft_export::Format::Hevc, hardware_encode::hevc_available);
+ filmcraft_codecs::hw::set_hw_backend("VideoToolbox");
Availability::Available("VideoToolbox")
}
- #[cfg(not(target_os = "macos"))]
+ #[cfg(target_os = "windows")]
+ {
+ filmcraft_codecs::register_video_decoder(media_foundation_factory);
+ filmcraft_codecs::hw::set_hw_backend("Media Foundation");
+ Availability::Available("Media Foundation")
+ }
+ #[cfg(not(any(target_os = "macos", target_os = "windows")))]
{
Availability::Unavailable("no hardware video decoder for this system yet")
}
diff --cc docs/architecture.md
index 34fb36cea,987862034..2917ea5ec
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@@ -72,7 -72,7 +72,7 @@@ and `filmcraft-cli`
| `engine` | L4 | `Session`, command registry, undo history, media pool, jobs, interchange glue |
| `ui-egui` | L5 | the egui frontend: docking, panels, timeline, monitors, playback, control-channel handlers |
| `automation` | L5 | MCP server (`rmcp`, stdio), headless or bridged to the running app |
- | `platform` | L5 | OS media FFI only: hardware video decoding (VideoToolbox H.264 / HEVC on macOS; a no-op elsewhere) behind `codecs::VideoDecoder`, with transparent fallback to our decoders, and hardware H.264 encoding (VideoToolbox, opt-in) and H.265 encoding (VideoToolbox, the only H.265 encoder; the format exists only where a hardware encoder does) behind `export::VideoEncoder`; H.264 declines to the built-in encoder for what the hardware does not take. The one crate allowed `unsafe` ([ADR 0001](adr/0001-platform-ffi.md), [README](../crates/platform/README.md)) |
-| `platform` | L5 | OS media FFI only: hardware video decoding (VideoToolbox H.264 / HEVC on macOS; Media Foundation / Direct3D 11 H.264 / HEVC on Windows; a no-op elsewhere) behind `codecs::VideoDecoder`, with transparent fallback to our decoders. The one crate allowed `unsafe` ([ADR 0001](adr/0001-platform-ffi.md), [README](../crates/platform/README.md)) |
++| `platform` | L5 | OS media FFI only: hardware video decoding (VideoToolbox H.264 / HEVC on macOS; Media Foundation / Direct3D 11 H.264 / HEVC on Windows; a no-op elsewhere) behind `codecs::VideoDecoder`, with transparent fallback to our decoders, and hardware H.264 encoding (VideoToolbox, opt-in) and H.265 encoding (VideoToolbox, the only H.265 encoder; the format exists only where a hardware encoder does) behind `export::VideoEncoder`; H.264 declines to the built-in encoder for what the hardware does not take. The one crate allowed `unsafe` ([ADR 0001](adr/0001-platform-ffi.md), [README](../crates/platform/README.md)) |
| `filmcraft` | L6 | desktop binary: eframe/wgpu window, cpal audio output, file dialogs, native macOS menu, TCP control server |
| `filmcraft-cli` | L6 | headless CLI: `exec`, `run`, `inspect`, `describe`, `commands`, `import`, `export`, `render`, `probe`, `mcp`; `--bridge` targets the running app |
| `filmcraft-web` | L6 | the browser app (wasm32): eframe web runner on WebGPU/WebGL2, Blob-backed services, OPFS recovery, WebAudio, WebCodecs, `window.filmcraft` API ([web.md](web.md)) |
diff --cc docs/performance.md
index e75d6980a,4082248f7..5aed9b431
--- a/docs/performance.md
+++ b/docs/performance.md
@@@ -161,99 -125,53 +161,146 @@@ the draft plan's box decimation of the
CPU cost. Zero-copy upload of the decoded `CVPixelBuffer` into wgpu (no copy-out at all) is the
next step (issue #30).
+## Results (HW2: VideoToolbox hardware H.264 encoding, built-in → hardware)
+
+Apple M1 (8 cores, 16 GB), 2026-10-06, single runs on an otherwise idle machine, release build.
+Hardware encoding is opt-in per export (`hardware_encoding: auto`); the built-in encoder is unchanged.
+
+### The encoder alone (100 frames of 1920×1080 25 fps camera footage, High, one-pass VBR, keyframe every 50)
+
+Frames go in as planar Y'CbCr and out as compressed frames (NV12 fill, `VTCompressionSessionEncodeFrame`,
+flush); quality is the luma PSNR of our software decoder's output against the input.
+
+| target | B-frames | real bitrate | luma PSNR | frames/s |
+|---|---|---|---|---|
+| 4 Mb/s | off | 3982 kb/s | 41.66 dB | 202 |
+| 8 Mb/s | off | 7987 kb/s | 43.44 dB | 202 |
+| 16 Mb/s | off | 15972 kb/s | 45.55 dB | 202 |
+| 4 Mb/s | on | 4220 kb/s | 41.37 dB | 183 |
+| 8 Mb/s | on | 8268 kb/s | 43.41 dB | 197 |
+| 16 Mb/s | on | 16388 kb/s | 45.66 dB | 199 |
+
+B-frames buy nothing measurable here (±0.3 dB) and overshoot the target by up to 5 %, so the hardware
+encoder runs without them: frames come out in presentation order and the muxer needs no composition
+offsets or edit list.
+
+### Whole exports (1080p25 camera clip with ProRes 4444 overlays with alpha, AAC, loudness normalised to −14 LUFS)
+
+A 9:29 timeline (569 s, 14 227 frames): the camera clip, an intro, six banners, three subscribe bars
+and an outro.
+
+| encoder | wall time | frames/s | vs real time | file |
+|---|---|---|---|---|
+| built-in (`filmcraft-h264enc`) | 793 s | 17.9 | 1.4× slower | 1445 MB, 20.0 Mb/s |
+| hardware (VideoToolbox) | **311 s** | **45.7** | 1.8× faster | 1417 MB, 19.6 Mb/s |
+
+2.5× faster. The first 134 s of the same timeline, where the overlays are densest (intro, a banner, a
+subscribe bar and the outro in 134 s):
+
+| encoder | wall time | frames/s | vs real time | file |
+|---|---|---|---|---|
+| built-in (`filmcraft-h264enc`) | 395 s | 8.5 | 2.9× slower | 340 MB, 20.0 Mb/s |
+| hardware (VideoToolbox) | **84 s** | **39.9** | 1.6× faster | 312 MB, 18.3 Mb/s |
+
+4.7× faster there. The gain depends on what else an export spends its time on: with the encoder
+off the CPU, what is left is decoding the camera clip, the CPU compositor (every layer, alpha
+included) and the RGBA → Y'CbCr conversion.
+
+The pairs of files have the same frame count and duration, decode in ffmpeg without a message, and
+compare at SSIM 0.990 / PSNR 46.7 dB over the 134 s (lowest frame: 45.1 dB) and SSIM 0.989–0.990 /
+PSNR 46.3–46.6 dB at six 3-second spots of the full export. Audio is identical.
+
+Where the built-in export's time goes (`sample` on the process during a 20 s export, inclusive CPU
+time in the call tree; the figures overlap because work-stealing mixes the tasks): about two thirds
+of the busy CPU is in the encoder, about a third in compositing and layer decoding. Moving the encoder to
+the media engine removes most of the first and lets the next batch render while the previous one
+encodes (the exporter renders a batch of frames in parallel, then encodes it). What is left is the
+CPU compositor, the next target of #30 ("GPU export").
+
+## Results (HW3: VideoToolbox hardware H.265 (HEVC) encoding, against hardware H.264)
+
+Apple M1 (8 cores, 16 GB), 2026-10-07, single runs on an otherwise idle machine, release build. Both
+encoders are the M1's media engine. H.265 is `Format::Hevc` (Main, 8-bit 4:2:0, one-pass VBR, no
+B-frames); H.264 is the opt-in hardware encoder of HW2 (High).
+
+### Speed
+
+The raw encoders (ffmpeg's `hevc_videotoolbox` and `h264_videotoolbox` on a 1080p25 test pattern, 500
+frames): 166 and 189 frames/s. H.265 is the codec that compresses further, not the faster one to encode.
+
+The 9:29 timeline of HW2 (camera clip, ProRes 4444 overlays, AAC, loudness normalised to −14 LUFS), 20 Mb/s
+H.264 and 10 Mb/s H.265: **204 s and 195 s** (CPU 1042 s and 1029 s), files of 1417 MB and 719 MB. The
+same time: the same H.264 export took 193 s and 200 s on other runs. The export is bound by the CPU
+compositor and the decoders, not by the encoder, so a different hardware codec does not change it.
+
+### Quality per bit
+
+30 s with a banner (15–45 s of that timeline), exported by FilmCraft as ProRes 422 HQ (the reference)
+and by each encoder at several bitrates; ffmpeg's `psnr` and `ssim` of the decoded 4:2:0 pictures against
+the reference. Average PSNR over the three planes, and SSIM (higher is better):
+
+| Mb/s | H.264 | H.265 | difference | H.264 Mb/s for H.265's PSNR |
+|---|---|---|---|---|
+| 20 | 46.88 dB, 0.9902 | 46.91 dB, 0.9903 | +0.03 dB | beyond the range measured |
+| 10 | 44.96 dB, 0.9863 | 45.09 dB, 0.9863 | +0.13 dB | 10.5 |
+| 6 | 43.72 dB, 0.9833 | 44.31 dB, 0.9843 | +0.59 dB | 7.7 |
+| 4 | 42.91 dB, 0.9807 | 43.64 dB, 0.9825 | +0.73 dB | 5.8 |
+| 3 | 42.37 dB, 0.9786 | 43.05 dB, 0.9807 | +0.68 dB | 4.3 |
+
+At 10 Mb/s and above the two give the same picture. At 3–6 Mb/s H.265 reaches the same PSNR with 22–31 %
+less bitrate. Its worst frame is better at every bitrate (lowest per-frame PSNR 45.9 against 42.1 dB at
+20 Mb/s, 43.1 against 41.5 dB at 10, 39.5 against 37.8 dB at 3).
+
+So there is no case for a lower default bitrate: the two formats start at the same 20 Mb/s. H.265
+pays off where the file size matters, at 3–6 Mb/s; that 9:29 timeline is 428 MB at 6 Mb/s.
+
+ ## Results (HW2: Windows Media Foundation / Direct3D 11 hardware decoding, Off → Auto)
+
+ Same binary (release build of the HW2 commit), Settings ▸ Playback ▸ Hardware decoding switched
+ with `--hw off` / `--hw auto`, 2026-10-07: Intel Xeon E5-2680 v4 (14 cores / 28 threads, 2.4 GHz),
+ NVIDIA GeForce RTX 5060 8 GB (driver 617.14), Windows 11 Pro 26200, idle machine. Two alternating
+ rounds; the table gives the range of the two (decode: best of 3 within each). Reproduce with
+ `cargo xtask bench --sections decode --only dec_h264 --repeat 3 --hw off|auto` (likewise `dec_hevc`)
+ and `--sections playback --only "h264-2160 full" --hw off|auto`; set `FILMCRAFT_FFMPEG` if ffmpeg is not
+ on `PATH` for the fixture generator. Pictures are identical either way (bit-exact parity tests,
+ `crates/platform/tests/media_foundation.rs`). The decoder MFTs were Microsoft's H.264 decoder
+ (`Microsoft H264 Video Decoder MFT`) and the `HEVCVideoExtension` decoder, both decoding with DXVA
+ on the RTX 5060's NVDEC: `nvidia-smi dmon -s u` showed the decoder engine at 18–27 % during an
+ Auto run and 0 % otherwise, and every picture came back as a Direct3D 11 texture.
+
+ ### Decode (every frame through the media stack)
+
+ | codec | size | CPU ms/frame Off → **Auto** | fps Off → **Auto** |
+ |---|---|---|---|
+ | H.264 | 1080p | 77–80 → **3.3** | 162–166 → **347–353** |
+ | H.264 | 2160p | 310–315 → **11.9** | 39–43 → **93** |
+ | HEVC Main | 1080p | 69–73 → **3.5** | 89–93 → **307–308** |
+ | HEVC Main | 2160p | 315–348 → **12–13** | 26–28 → **87–90** |
+ | HEVC Main 10 | 2160p | 314–336 → **17.6** | 32 → **57** |
+
+ Counters: every Auto row had `hw frames` = frames × 3 repeats (360 at 1080p, 216 at 2160p), 3
+ sessions, 0 fallbacks, 0 declined; every Off row had 0 hardware frames and 0 sessions.
+
+ What is left on the CPU is the readback: `examples/mfprobe.rs --time` splits a 2160p H.264 picture
+ into 1.1 ms DXVA decode (feeding the MFT), 2.8 ms GPU to CPU copy (staging texture + map) and 7 ms
+ CPU conversion (Annex B, biplanar to planar Y'CbCr); Main 10 is 1.4 / 4.5 / 10 ms (twice the bytes).
+ A zero-copy path removes the last two.
+
+ ### Program-monitor playback (8 s, GPU path)
+
+ | case | shown/dropped Off → **Auto** | CPU ms/frame Off → **Auto** |
+ |---|---|---|
+ | H.264 1080p Full | 192/0 → **192/0** | 86–89 → **8.5–8.8** |
+ | H.264 2160p Full | 192/0 → **189–190/2–3** | 338–353 → **17–20** |
+ | H.264 2160p 1/2 | 192/0 → **190/2** | 355–361 → **22** |
+ | HEVC 2160p Full | 112–152/40–80 → **191–192/0–1** | 355–364 → **18** |
+
+ This machine has 28 software-decoding threads, so Off keeps up with 4K H.264 (at 340 ms of CPU per
+ frame, about 8 cores busy); Auto uses a twentieth of that CPU but drops 2–3 of 192 frames
+ (readback latency at the start of the run). 4K HEVC is where Off drops frames and Auto does not.
+ Draft playback (1/2 draft: 410–416 → 93–105 CPU ms/frame) is dominated by the draft plan's decimation,
+ as on macOS, because the hardware ignores draft mode.
+
## Results (GPU1: blend modes on the GPU compositor, #30, before → after)
Before = this change with the old whole-frame CPU fallback for non-Normal blend modes put back