FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Merge origin/main into feat/nvenc-export
Brandon Thomasf267a941fb75
diff --cc README.mdindex 0c91ed07b,58389ba1a..8c498e3de--- a/README.md+++ b/README.md@@@ -185,7 -185,7 +185,7 @@@ No FFmpeg inside. The video codecs, AAC| **Matroska / WebM** | ✓ | | Lacing, Cues, header stripping, HDR colour metadata || **Stills** | ✓ | ✓ | Import PNG, JPEG, GIF, WebP, TIFF and BMP; export PNG sequences and animated GIF |- Also imported: MPEG-2 / MPEG-1 video, AC-3, MP2, MXF (OP1a / OP-Atom), MPEG transport and program streams (AVCHD, broadcast, DVD), Ogg and image sequences. Not yet: HEVC and AV1 export, camera RAW, E-AC-3. Hardware decoding works on macOS (VideoToolbox) and Windows (Media Foundation), with Linux to follow; H.264 export can use NVIDIA's encoder on Windows (opt-in) ([#30](https://github.com/storytold/filmcraft/issues/30)).-Also imported: MPEG-2 / MPEG-1 video, AC-3, MP2, MXF (OP1a / OP-Atom), MPEG transport and program streams (AVCHD, broadcast, DVD), Ogg and image sequences. Not yet: AV1 export, camera RAW, E-AC-3. Hardware decoding works on macOS (VideoToolbox), Windows (Media Foundation) and, for H.264 and HEVC, Linux (VA-API); H.264 export can use NVIDIA's encoder on Windows (opt-in), and H.265 (HEVC Main, 8-bit) export works through it (NVENC on Windows, VideoToolbox on macOS) ([#30](https://github.com/storytold/filmcraft/issues/30)).++Also imported: MPEG-2 / MPEG-1 video, AC-3, MP2, MXF (OP1a / OP-Atom), MPEG transport and program streams (AVCHD, broadcast, DVD), Ogg and image sequences. Not yet: AV1 export, camera RAW, E-AC-3. Hardware decoding works on macOS (VideoToolbox), Windows (Media Foundation) and, for H.264 and HEVC, Linux (VA-API); H.264 export can use NVIDIA's encoder on Windows and Linux (opt-in), and H.265 (HEVC Main, 8-bit) export works through it (NVENC on Windows, VideoToolbox on macOS) ([#30](https://github.com/storytold/filmcraft/issues/30)).<br>@@@ -287,9 -287,9 +287,9 @@@ We track two numbers ([ROADMAP.md](ROADThe biggest gaps today:- - **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 and on Windows with an NVIDIA GPU (opt-in, Export ▸ Hardware encoding), 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, and for H.264 and HEVC on Linux (VA-API; VP9 and AV1 decode in software there). 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 and on Windows with an NVIDIA GPU (opt-in, Export ▸ Hardware encoding), and H.265 export is hardware-only on both (HDR sequences export Main 10 PQ / HLG with NVENC; VideoToolbox writes 8-bit SDR) ([#30](https://github.com/storytold/filmcraft/issues/30)).++- **Speed on big footage.** Hardware decoding works on macOS and Windows, and for H.264 and HEVC on Linux (VA-API; VP9 and AV1 decode in software there). 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 and on Windows and Linux with an NVIDIA GPU (opt-in, Export ▸ Hardware encoding), and H.265 export is hardware-only on both (HDR sequences export Main 10 PQ / HLG with NVENC; VideoToolbox writes 8-bit SDR) ([#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.+ - **Delivery codecs.** H.264 is our only software delivery-codec export; H.265 exports only through a hardware encoder (NVIDIA on Windows: Main 8-bit SDR and Main 10 HDR PQ / HLG; VideoToolbox on macOS: 8-bit Main, SDR); no 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.- **AI features.** Few so far; speech to text is optional and off by default.diff --cc ROADMAP.mdindex 29c0409fb,2640adb6a..7ead98f51--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -35,8 -35,8 +35,8 @@@ before choosing work| **Feature breadth** (menus, commands, panels) | ~86–95% | **~85%** | Menu diff against Premiere 26.5; effect, transition and audio-effect catalogues complete by test. The long tail is mostly there. || **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 (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, HEVC Main / Main 10, VP9 and AV1 4:2:0 8/10-bit, #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 NVENC on Windows with an NVIDIA GPU (opt-in per export), and H.265 (HEVC) export exists there only, through the same hardware encoder. Linux has no hardware path. 8K isn't real-time (AV1 is on Windows with a hardware decoder). 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. |+ | **Export** | ~92% | **~70%** | Delivery: H.264, plus H.265 through a hardware encoder only (NVENC on Windows: Main 8-bit SDR and Main 10 HDR PQ / HLG; VideoToolbox on macOS: Main 8-bit SDR); ProRes, DNxHR and image sequences cover mastering. No AV1 export, no 10-bit / HDR HEVC on macOS. 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 (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, HEVC Main / Main 10, VP9 and AV1 4:2:0 8/10-bit, #30), and for H.264 and HEVC on Linux (VA-API: 4K H.264 at 11 ms of CPU per frame instead of 417 ms, 4K HEVC at 10 ms instead of 203 ms). 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 NVENC on Windows with an NVIDIA GPU (opt-in per export), and H.265 (HEVC) export exists there only, through the same hardware encoders (macOS and Windows). Linux decodes H.264 and HEVC in hardware (VP9 and AV1 there are software) and has no hardware encoder. 8K isn't real-time (AV1 is on Windows with a hardware decoder). 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, HEVC Main / Main 10, VP9 and AV1 4:2:0 8/10-bit, #30), and for H.264 and HEVC on Linux (VA-API: 4K H.264 at 11 ms of CPU per frame instead of 417 ms, 4K HEVC at 10 ms instead of 203 ms). 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 NVENC on Windows and Linux with an NVIDIA GPU (opt-in per export), and H.265 (HEVC) export exists on macOS and Windows only, through the same hardware encoders. Linux decodes H.264 and HEVC in hardware (VP9 and AV1 there are software); its only hardware encoder is NVENC H.264. 8K isn't real-time (AV1 is on Windows with a hardware decoder). 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. |diff --cc crates/platform/README.mdindex 9f1be37c2,e55d25f46..58df2f6ea--- a/crates/platform/README.md+++ b/crates/platform/README.md@@@ -61,11 -61,9 +61,11 @@@ let availability = filmcraft_platform::- After a `flush` (which drains the MFT) the MFT only restarts at an IDR picture; the GOP cachealways seeks after a flush, and a caller that continues from the middle of a GOP gets an errorthat `HybridDecoder` answers by replaying the run in software.- - **Windows and 64-bit Linux: NVIDIA NVENC H.264 encoding** (`nvenc/`), 8-bit SDR 4:2:0 for Export. The driver's-- **Windows: NVIDIA NVENC H.264 and H.265 (HEVC) encoding** (`nvenc/`), 8-bit SDR 4:2:0 for Export. The driver's- `nvEncodeAPI64.dll` (API 12.1, no CUDA or SDK) is loaded at run time, so machines without NVIDIA- still start. RGBA is converted with the software encoder's own BT.709 limited conversion into NV12++- **Windows and 64-bit Linux: NVIDIA NVENC H.264 encoding, and H.265 (HEVC) on Windows** (`nvenc/`), 8-bit SDR 4:2:0 for Export. The driver's+ `nvEncodeAPI64.dll` (Windows) or `libnvidia-encode.so.1` (Linux), API 12.1, is loaded at run time,+ so machines without NVIDIA still start. Windows uses a Direct3D 11 device; Linux retains a primary+ CUDA context through the runtime-loaded `libcuda.so.1`, released after the encoder is destroyed.+ No SDK, CUDA toolkit or NVIDIA binaries are bundled or required at build time. RGBA is converted with the software encoder's own BT.709 limited conversion into NV12input buffers (a ring of eight); the encoder runs preset P5 with high-quality tuning, CABAC (CAVLCfor Baseline), one B-frame when the profile and GPU allow it, and an IDR at every keyframedistance; the parameter sets go into `avcC`. Export ▸ Hardware encoding (off by default) selects it.@@@ -161,9 -275,20 +277,20 @@@ level 4 High tier, which many hardware| `tests/fallback.rs` (every OS) | `HybridDecoder` with a stand-in hardware decoder failing after N samples (every sync sample ± a few, first / last sample, after a seek): output identical to the software decoder; in-band parameter sets identical to the sample entry's stay in hardware, different ones switch to software || `tests/setting.rs` | Hardware decoding Off gives the software decoder through `make_video_decoder` and the media stack (no hardware frames); Auto gives VideoToolbox where available || `tests/hardware_encode.rs` (macOS) | what the hardware path takes and declines; round trip through our software decoder (every picture, in order, luma PSNR above 30 dB, keyframes no further apart than asked, no composition offsets); an export through `filmcraft_export` that decodes in our decoder and in ffmpeg / ffprobe (profile, size, frame count, BT.709); the built-in encoder still exporting everything hardware declines; exact output size at sizes that are not multiples of 16; hostile configurations (zero, huge, odd sizes, frame rates, bitrates, keyframe intervals, wrong planes) give errors and never panic; encoders dropped at any point do not crash or hang. The same for **HEVC**: Main profile, 8-bit 4:2:0, `hvc1` entry with VPS / SPS / PPS and 4-byte lengths, MP4 and QuickTime, AAC audio, two-pass refused, the format list agreeing with the probe, ffprobe reading `codec_name=hevc`, `profile=Main`, `codec_tag_string=hvc1`, `pix_fmt=yuv420p`, BT.709 |-| `tests/nvenc.rs` (Windows, NVIDIA) | H.264 from NVENC (1280×720, 6 Mbps, 72 frames) decodes with our decoder at worst 46.9 dB luma PSNR; IDR at 0, 24 and 48; dts / pts right |-| `tests/nvenc_export.rs` (Windows, NVIDIA) | Export with hardware encoding against the software encoder through the export pipeline: the two decoded files at worst 54.8 dB luma PSNR; ffmpeg decodes the file without errors; declined cases go to the software encoder; the counters |+| `tests/nvenc.rs` (Windows / Linux, NVIDIA) | H.264 from NVENC (1280×720, 6 Mbps, 72 frames) decodes with our decoder at worst 46.9 dB luma PSNR; IDR at 0, 24 and 48; dts / pts right |+| `tests/nvenc_export.rs` (Windows / Linux; fallback also tested without NVIDIA) | Export with hardware encoding against the software encoder through the export pipeline: the two decoded files at worst 54.8 dB luma PSNR; ffmpeg decodes the file without errors; declined cases go to the software encoder; the counters |- | `src/nvenc/abi_tests.rs` (Windows / Linux) | FFI structs' sizes, alignments, field offsets, constants and GUIDs against a C compiler's view of NVIDIA's `nvEncodeAPI.h` (12.1) |+ | `tests/nvenc_hevc.rs` (Windows, NVIDIA with HEVC) | HEVC from NVENC (1280×720, 6 Mbps, 72 frames, keyframe every 24) decodes with our HEVC decoder at worst 48.9 dB luma / 51.0 dB chroma PSNR; IDR at 0, 24, 48; dts strictly increasing, pts a permutation, `sps_max_num_reorder_pics` within the dts shift; no parameter sets in the samples; the `hvcC`'s profile / tier / level bytes are the SPS's own; VUI BT.709 limited and timing `(1, 24)`; hostile configurations, sizes, planes and encoders dropped mid-stream give errors, never panics; keyframes every 1–2 pictures without B-frames |+ | `tests/nvenc_hevc_export.rs` (Windows, NVIDIA with HEVC) | H.265 export through the real pipeline, MP4 and QuickTime, toggle Auto and Off: counters (72 frames, 1 session, 0 declined), our decoder against the software H.264 export at worst 54.8 dB luma PSNR, ffprobe `codec_name=hevc`, `profile=Main`, `codec_tag_string=hvc1`, `pix_fmt=yuv420p`, BT.709 limited, 72 frames, 24/1, keyframes at 0 and 48, start 0, `ffmpeg -xerror` clean; with AAC audio; 1920×1080 and 642×362 cropped back from the coded size; every decline (HDR, analysis pass, two-pass, interlaced, non-square pixels, MXF, sizes over 65535, odd sizes, sizes outside the GPU's limits) an error naming NVENC, counted once; H.264 with hardware encoding Off never touches NVENC |+ | `tests/nvenc_hevc_probe.rs` (Windows) | the HEVC probe in a fresh process: its cost, the cached answer, `available(Hevc)` following it after `register()` (twice) |+ | `tests/nvenc_hevc_warm.rs` (Windows) | `register()` answers the HEVC and the Main 10 questions on a thread of its own, before anyone asks; the answers are kept and `hdr_available(Hevc)` follows the Main 10 probe |+ | `tests/nvenc_hevc_main10.rs` (Windows, NVIDIA with 10-bit HEVC) | HEVC Main 10 in process, PQ and HLG: a float picture (grey ramp to peak white, a moving box, saturated BT.2020 bars) is converted with `rgbf_to_yuv420_10`, encoded and decoded with our HEVC decoder (`Yuv16`, 10 bits, codes below 1024): worst 71.1 dB luma / 70.6 dB chroma PSNR on the 10-bit scale, 803 distinct luma levels on a ramp row, peak code 940 survives; IDR at 0 and 24; the VUI is BT.2020 / 16 or 18 / BT.2020 NCL / limited; the IDR samples carry two prefix SEI NAL units whose messages are byte-for-byte the expected 137 / 144 payloads (HLG: none; other pictures: none); Main and Main 10 refuse each other's pictures; hostile sizes, bitrates, signals, huge or empty SEI payloads, encoders dropped with SEI in flight |+ | `tests/nvenc_hevc_hdr_export.rs` (Windows, NVIDIA with 10-bit HEVC) | HDR sequences through the real export job (PQ MP4, HLG MP4, PQ QuickTime): 24 frames, 1 session, 0 declined; ffprobe `hevc` / `Main 10` / `hvc1` / `yuv420p10le`, `bt2020` / `smpte2084` or `arib-std-b67` / `bt2020nc` / `tv`; PQ first-frame side data Mastering display (max 10000000/10000, min 1/10000) and Content light level, HLG none; `ffmpeg -xerror` clean; ffmpeg's yuv420p10le picture equals our decoder's, code for code; our importer reads PQ / HLG, BT.2020, 10-bit, and the `colr` / `mdcv` / `clli` boxes; luma PSNR against a ProRes HDR export of the same sequence 62.6 dB (PQ) / 61.8 dB (HLG); `settings.sdr` and SDR sequences stay Main 8-bit BT.709 with no HDR boxes; the factory rejects mismatched or wrong-length pictures and clamps NaN / infinity |-| `src/nvenc/abi_tests.rs` (Windows) | FFI structs' sizes, alignments, field offsets, constants, GUIDs and the bit-field masks of the `flags` words (H.264, HEVC, and the HEVC picture parameters with the SEI payload array) against a C compiler's view of NVIDIA's `nvEncodeAPI.h` (12.1) |++| `src/nvenc/abi_tests.rs` (Windows / Linux) | FFI structs' sizes, alignments, field offsets, constants, GUIDs and the bit-field masks of the `flags` words (H.264, HEVC, and the HEVC picture parameters with the SEI payload array) against a C compiler's view of NVIDIA's `nvEncodeAPI.h` (12.1) |+ | `src/nvenc/{mod,hevc,export}.rs` unit tests (Windows) | HEVC NAL types, stripping and parameter-set splitting (including `IDR_N_LP`, whose header byte reads as a PPS in H.264, and one-byte or truncated NAL units); the `hvcC` built from real VPS / SPS / PPS (Main and Main 10: accepted as what was asked for, refused as the other, other depths refused), every truncation and bit flip of the SPS, wrong profile, size and NAL types; HEVC levels; P010 layout (shift, little-endian, interleaving, pitch in bytes, narrow pitches and short buffers); the 10-bit capability decline; the SEI messages |+ | `crates/export/src/hdr_tests.rs` | `rgbf_to_yuv420_10`: exact codes for black, white, grey and the BT.2020 primaries and secondaries, NaN / infinity / out-of-range, odd sizes, wrong lengths and overflowing sizes; the HDR probe registry; which exports are HDR (HEVC SDR without a probe, HDR with one, `settings.sdr` forcing SDR); the SEI of the software H.264 encoder equals `ColorSignal::static_metadata` |+ | `tests/vaapi.rs` (Linux, VA-API) | HEVC Main (open GOP: CRA + RASL), Main 10, scaling lists, 3 slices with WPP (10-bit), weighted prediction with 4 references, transform skip + AMP + B-pyramid (10-bit, open GOP), Main / Main 10 at 1080p and 2160p (compared picture by picture, little memory); H.264 High (B-pyramid), Constrained Baseline with 3 slices per picture, Main with explicit weighted prediction (P and B) and 4 references, temporal direct, custom scaling matrices (JVT) with the 8x8 transform and 2 slices, an open-GOP stream, and 1080p / 2160p, 640×360 (coded 368: cropping): every picture **bit-exact** with our software decoder, same pts order, count, colour and aspect, also after `reset` + reseek to every later sync sample (after an open-GOP I picture, from the seek point on), a mid-stream `flush` with decoding carrying on, and a full pass after resets; forced mid-stream failures (`VaDecoder::fail_after`) at five points continue with the software decoder's exact output; interlaced and 10-bit H.264, 4:2:2 HEVC and the Off setting are declined; an HEVC mid-GOP flush is not checked (it ends the stream, as in software); seeded mutation of samples (through the hybrid and straight into the hardware decoder) and of `avcC` records never panics or hangs; 40 decoders created and dropped; concurrent decoders; a decoder moving between threads |+ | `src/vaapi/tests.rs` (every OS) | The H.264 and HEVC front ends with a recording stand-in for the hardware, on x264 streams (B-pyramid, weighted prediction, 4 slices, open GOP with temporal direct) and x265 streams (open GOP with RASL, B-pyramid, Main 10 with 2 slices and weighted prediction): output order and pts are the software decoder's, also after seeks and a mid-stream flush; every buffer is consistent (current surface free, references decoded and listed once, reference lists of the active length, slice data offsets inside the slice); damaged samples are errors |+ | `src/vaapi/abi_tests.rs` | FFI structs' sizes, alignments, field offsets, constants and bit-field positions against a C compiler's view of libva's `va.h` and `va_dec_hevc.h` (VA-API 1.23) |Fixtures are made with ffmpeg into `target/fixtures/platform/` (generator only, never linked);tests skip without ffmpeg or without a hardware decoder.@@@ -190,17 -320,8 +322,19 @@@ Details in [docs/performance.md](../../## Not yetZero-copy upload of decoded pictures into wgpu textures (`CVPixelBuffer`s on macOS, Direct3D 11- textures on Windows); B-frames and 10-bit / HDR HEVC (Main 10) in hardware encoding; VA-API (Linux)- decoders; field-coded H.264; HEVC, 10-bit and HDR encoding with NVENC, and encoders from other- vendors on Windows (through Media Foundation); VP9 / AV1 4:4:4 and 12-bit on Windows.+ textures on Windows); B-frames in the VideoToolbox encoders and 10-bit / HDR HEVC (Main 10) in+ VideoToolbox; VP9 and AV1 through VA-API (Linux), and VA-API encoding; field-coded H.264; 4:4:4 and 4:2:2 encoding with NVENC, HDR+ H.264 with NVENC (HDR H.264 stays with the software encoder), HDR10 MaxCLL / MaxFALL measured from+ the pictures (they are written as 0, unknown), AV1 with NVENC, H.265 with the other Windows vendors and on Linux, and encoders+ from other vendors on Windows (through Media Foundation); VP9 / AV1 4:4:4 and 12-bit on Windows.++### Linux NVENC sources and limits++The device binding uses NVIDIA's [CUDA Driver API 12.1 primary-context reference](https://docs.nvidia.com/cuda/archive/12.1.0/cuda-driver-api/group__CUDA__PRIMARY__CTX.html)+and the existing [Video Codec SDK 12.1 encode API](https://docs.nvidia.com/video-technologies/video-codec-sdk/12.1/nvenc-video-encoder-api-prog-guide/index.html).- It uses the first CUDA device. This backend handles H.264 only, on NVIDIA hardware, on Windows and- 64-bit Linux; other formats and unsupported H.264 settings use the existing encoder selection.++It uses the first CUDA device. On Linux this backend handles H.264 only (H.265 through NVENC is++Windows-only for now); other formats and unsupported H.264 settings use the existing encoder selection.+Linux registers the export factory even without a driver; `register()`'s return value and+`registered()` still describe hardware **decoding**, which this backend does not provide.+Absent / old drivers decline once per export, with an informational log and+`perf.stats` → `export.hardware.declined`; hardware encoding Off never opens the driver.diff --cc crates/platform/src/lib.rsindex 4219d9a1e,835e3054d..da0164e29--- a/crates/platform/src/lib.rs+++ b/crates/platform/src/lib.rs@@@ -35,8 -39,10 +39,10 @@@ pub mod hardware_encodepub mod hybrid;#[cfg(target_os = "windows")]pub mod media_foundation;-#[cfg(target_os = "windows")]+#[cfg(any(target_os = "windows", all(target_os = "linux", target_pointer_width = "64")))]pub mod nvenc;+ #[cfg_attr(not(target_os = "linux"), allow(dead_code))]+ pub mod vaapi;#[cfg(target_os = "macos")]#[allow(unsafe_code)]pub mod videotoolbox;diff --cc crates/platform/src/nvenc/abi_tests.rsindex 20b9e9907,7ed9f0b98..1d6980fb4--- a/crates/platform/src/nvenc/abi_tests.rs+++ b/crates/platform/src/nvenc/abi_tests.rs@@@ -2,7 -2,9 +2,17 @@@//! alignments, field offsets, constants and GUIDs. Generated by running a C program (built with//! MSVC from the NVIDIA header) that prints them; the header itself is not in this repository.//! To regenerate, put NVIDIA's MIT-licensed `nvEncodeAPI.h` 12.1 in `ffnvcodec/` next to a program- //! printing `sizeof` / `offsetof` of the structures of `src/nvenc/ffi.rs` and the constants it uses.+ //! printing `sizeof` / `alignof` / `offsetof` of the structures of `src/nvenc/ffi.rs`, the constants+ //! and GUIDs it uses and, for the bit-fields of the `flags` words (`offsetof` cannot take those), the+ //! word with that one field set (see docs/testing.md). H.264 and HEVC are both covered.++//!++//! The expectations were generated with MSVC (Windows x64, LLP64) and also hold on Linux x86_64++//! (LP64), where these tests run too: every field the structures use is a fixed-width integer++//! (`uint32_t`, `int32_t`, `uint64_t`, ...), `int` / an enum (32 bits on both), a pointer (64 bits on++//! both) or a GUID (four fixed-width members, 16 bytes, aligned to 4). None is a `long` /++//! `unsigned long`, the one C type whose size differs between the two (32 bits on Windows, 64 on++//! Linux). The `flags` bit-fields are all `uint32_t` fields of one `uint32_t` word, which MSVC and++//! GCC / Clang lay out the same way (from the least significant bit) on x86_64.#![allow(clippy::unreadable_literal)]use super::ffi::*;diff --cc crates/platform/src/nvenc/export.rsindex fc77fe280,8f2f67ced..2acd3ab2d--- a/crates/platform/src/nvenc/export.rs+++ b/crates/platform/src/nvenc/export.rs@@@ -110,15 -183,18 +186,18 @@@ fn config(format: Format, w: u32, h: u3height: h,fps,bitrate_kbps: kbps,- max_bitrate_kbps: s.max_bitrate_kbps.filter(|m| *m >= kbps).unwrap_or(kbps / 2 * 3),+ max_bitrate_kbps: s.max_bitrate_kbps.filter(|m| *m >= kbps).unwrap_or_else(|| kbps.saturating_add(kbps / 2)),cbr: s.bitrate_mode == BitrateMode::Cbr,keyint: s.keyframe_distance.filter(|k| *k > 0).unwrap_or_else(|| (f64::from(fps.0) / f64::from(fps.1) * 2.0).round().max(1.0) as u32),- profile: match s.h264_profile {- H264Profile::Baseline => Profile::Baseline,- H264Profile::Main => Profile::Main,- H264Profile::High => Profile::High,+ profile: match (hevc, s.h264_profile) {+ (true, _) if hdr => Profile::HevcMain10,+ (true, _) => Profile::HevcMain,+ (false, H264Profile::Baseline) => Profile::Baseline,+ (false, H264Profile::Main) => Profile::Main,+ (false, H264Profile::High) => Profile::High,},- level: s.h264_level,+ // the H.264 level setting means nothing for H.265: the encoder picks the level+ level: if hevc { None } else { s.h264_level },sar: s.pixel_aspect,bframes: true,})@@@ -126,17 -202,9 +205,22 @@@/// The Export encoder factory (see the module documentation).pub fn factory(format: Format, w: u32, h: u32, rate: FrameRate, s: &ExportSettings) -> Option<Result<Box<dyn VideoEncoder>>> {- factory_with(format, w, h, rate, s, NvencH264::new)+ if format == Format::Hevc {- return hevc_factory(w, h, rate, s);++ // H.265 through NVENC is Windows-only for now; on Linux this backend takes H.264 only++ return if cfg!(target_os = "windows") { hevc_factory(w, h, rate, s) } else { None };+ }++ factory_with(format, w, h, rate, s, Nvenc::new)+}+++/// The H.264 side of [`factory`], with the driver call (`open`) passed in so tests can stand in for it.+fn factory_with(+ format: Format,+ w: u32,+ h: u32,+ rate: FrameRate,+ s: &ExportSettings,- open: impl FnOnce(&Config) -> std::result::Result<NvencH264, String>,++ open: impl FnOnce(&Config) -> std::result::Result<Nvenc, String>,+) -> Option<Result<Box<dyn VideoEncoder>>> {if s.hardware_encoding != HardwareEncoding::Auto || format != Format::H264 {return None;}@@@ -149,10 -217,36 +233,36 @@@Ok(c) => c,Err(why) => return declined(&why),};- match Nvenc::new(&cfg) {+ match open(&cfg) {Ok(enc) => {filmcraft_export::note_hw_encode_session();- Some(Ok(Box::new(NvencEncoder { enc, w, h, rate, y: Vec::new(), u: Vec::new(), v: Vec::new() })))+ Some(Ok(Box::new(new_encoder(enc, w, h, rate, s.signal))))+ }+ Err(why) => declined(&why),+ }+ }++ /// The H.265 side of [`factory`]: FilmCraft's only HEVC encoder on Windows, so the Hardware encoding toggle+ /// does not apply and a request NVENC cannot take is an error, not a fall-through.+ fn hevc_factory(w: u32, h: u32, rate: FrameRate, s: &ExportSettings) -> Option<Result<Box<dyn VideoEncoder>>> {+ let declined = |why: &str| {+ log::info!("hardware H.265 encoding declined: {why}");+ filmcraft_export::note_hw_encode_declined();+ Some(Err(ExportError::Unsupported(format!("H.265 export with NVENC: {why}"))))+ };+ let cfg = match config(Format::Hevc, w, h, rate, s) {+ Ok(c) => c,+ Err(why) => return declined(&why),+ };+ match Nvenc::with_signal(&cfg, &nvenc_signal(&s.signal)) {+ Ok(enc) => {+ filmcraft_export::note_hw_encode_session();+ Some(Ok(Box::new(new_encoder(enc, w, h, rate, s.signal))))+ }+ // no HEVC encoder here at all: not a hardware attempt, the export's own "encoder not available" error+ Err(why) if !super::hevc_available() => {+ log::info!("no hardware H.265 encoder: {why}");+ None}Err(why) => declined(&why),}diff --cc crates/platform/src/nvenc/ffi.rsindex 6fb6b72b0,c53042fd6..c3e479f42--- a/crates/platform/src/nvenc/ffi.rs+++ b/crates/platform/src/nvenc/ffi.rs@@@ -89,9 -70,10 +89,11 @@@ pub const NV_ENC_ERR_ENCODER_BUSY: NvStpub const NV_ENC_ERR_LOCK_BUSY: NvStatus = 13;pub const NV_ENC_DEVICE_TYPE_DIRECTX: u32 = 0;+pub const NV_ENC_DEVICE_TYPE_CUDA: u32 = 1;pub const NV_ENC_MEMORY_HEAP_SYSMEM_CACHED: u32 = 2;pub const NV_ENC_BUFFER_FORMAT_NV12: u32 = 0x1;+ /// P010: 10-bit 4:2:0, 16-bit little-endian samples with the value in the high 10 bits.+ pub const NV_ENC_BUFFER_FORMAT_YUV420_10BIT: u32 = 0x10000;pub const NV_ENC_PARAMS_RC_VBR: u32 = 1;pub const NV_ENC_PARAMS_RC_CBR: u32 = 2;pub const NV_ENC_TUNING_INFO_HIGH_QUALITY: u32 = 1;@@@ -116,12 -119,15 +139,15 @@@ pub const NV_ENC_CAPS_HEIGHT_MAX: u32pub const NV_ENC_CAPS_WIDTH_MIN: u32 = 45;pub const NV_ENC_CAPS_HEIGHT_MIN: u32 = 46;-pub const NV_ENC_CODEC_H264_GUID: GUID = GUID::from_values(0x6bc82762, 0x4e63, 0x4ca4, [0xaa, 0x85, 0x1e, 0x50, 0xf3, 0x21, 0xf6, 0xbf]);-pub const NV_ENC_CODEC_HEVC_GUID: GUID = GUID::from_values(0x790cdc88, 0x4522, 0x4d7b, [0x94, 0x25, 0xbd, 0xa9, 0x97, 0x5f, 0x76, 0x03]);-pub const NV_ENC_H264_PROFILE_BASELINE_GUID: GUID = GUID::from_values(0x0727bcaa, 0x78c4, 0x4c83, [0x8c, 0x2f, 0xef, 0x3d, 0xff, 0x26, 0x7c, 0x6a]);-pub const NV_ENC_H264_PROFILE_MAIN_GUID: GUID = GUID::from_values(0x60b5c1d4, 0x67fe, 0x4790, [0x94, 0xd5, 0xc4, 0x72, 0x6d, 0x7b, 0x6e, 0x6d]);-pub const NV_ENC_H264_PROFILE_HIGH_GUID: GUID = GUID::from_values(0xe7cbc309, 0x4f7a, 0x4b89, [0xaf, 0x2a, 0xd5, 0x37, 0xc9, 0x2b, 0xe3, 0x10]);-pub const NV_ENC_HEVC_PROFILE_MAIN_GUID: GUID = GUID::from_values(0xb514c39a, 0xb55b, 0x40fa, [0x87, 0x8f, 0xf1, 0x25, 0x3b, 0x4d, 0xfd, 0xec]);-pub const NV_ENC_HEVC_PROFILE_MAIN10_GUID: GUID = GUID::from_values(0xfa4d2b6c, 0x3a5b, 0x411a, [0x80, 0x18, 0x0a, 0x3f, 0x5e, 0x3c, 0x9b, 0xe5]);-pub const NV_ENC_PRESET_P4_GUID: GUID = GUID::from_values(0x90a7b826, 0xdf06, 0x4862, [0xb9, 0xd2, 0xcd, 0x6d, 0x73, 0xa0, 0x86, 0x81]);-pub const NV_ENC_PRESET_P5_GUID: GUID = GUID::from_values(0x21c6e6b4, 0x297a, 0x4cba, [0x99, 0x8f, 0xb6, 0xcb, 0xde, 0x72, 0xad, 0xe3]);+pub const NV_ENC_CODEC_H264_GUID: Guid = Guid::from_values(0x6bc82762, 0x4e63, 0x4ca4, [0xaa, 0x85, 0x1e, 0x50, 0xf3, 0x21, 0xf6, 0xbf]);++pub const NV_ENC_CODEC_HEVC_GUID: Guid = Guid::from_values(0x790cdc88, 0x4522, 0x4d7b, [0x94, 0x25, 0xbd, 0xa9, 0x97, 0x5f, 0x76, 0x03]);+pub const NV_ENC_H264_PROFILE_BASELINE_GUID: Guid = Guid::from_values(0x0727bcaa, 0x78c4, 0x4c83, [0x8c, 0x2f, 0xef, 0x3d, 0xff, 0x26, 0x7c, 0x6a]);+pub const NV_ENC_H264_PROFILE_MAIN_GUID: Guid = Guid::from_values(0x60b5c1d4, 0x67fe, 0x4790, [0x94, 0xd5, 0xc4, 0x72, 0x6d, 0x7b, 0x6e, 0x6d]);+pub const NV_ENC_H264_PROFILE_HIGH_GUID: Guid = Guid::from_values(0xe7cbc309, 0x4f7a, 0x4b89, [0xaf, 0x2a, 0xd5, 0x37, 0xc9, 0x2b, 0xe3, 0x10]);++pub const NV_ENC_HEVC_PROFILE_MAIN_GUID: Guid = Guid::from_values(0xb514c39a, 0xb55b, 0x40fa, [0x87, 0x8f, 0xf1, 0x25, 0x3b, 0x4d, 0xfd, 0xec]);++pub const NV_ENC_HEVC_PROFILE_MAIN10_GUID: Guid = Guid::from_values(0xfa4d2b6c, 0x3a5b, 0x411a, [0x80, 0x18, 0x0a, 0x3f, 0x5e, 0x3c, 0x9b, 0xe5]);+pub const NV_ENC_PRESET_P4_GUID: Guid = Guid::from_values(0x90a7b826, 0xdf06, 0x4862, [0xb9, 0xd2, 0xcd, 0x6d, 0x73, 0xa0, 0x86, 0x81]);+pub const NV_ENC_PRESET_P5_GUID: Guid = Guid::from_values(0x21c6e6b4, 0x297a, 0x4cba, [0x99, 0x8f, 0xb6, 0xcb, 0xde, 0x72, 0xad, 0xe3]);pub type Handle = *mut c_void;diff --cc crates/platform/src/nvenc/mod.rsindex 74e39bd90,3a960c9e6..e03ed0cfa--- a/crates/platform/src/nvenc/mod.rs+++ b/crates/platform/src/nvenc/mod.rs@@@ -1,22 -1,27 +1,32 @@@- //! NVIDIA NVENC H.264 hardware encoding (Windows and 64-bit Linux).-//! NVIDIA NVENC hardware encoding, H.264 and H.265 (HEVC) Main / Main 10 (Windows).++//! NVIDIA NVENC hardware encoding: H.264 (Windows and 64-bit Linux) and H.265 (HEVC) Main / Main 10++//! (Windows).//!- //! The encoder runs through the driver's `nvEncodeAPI64.dll` on Windows or- //! `libnvidia-encode.so.1` on Linux (API 12.1, [`ffi`]; no SDK to install): pictures go in as NV12 input buffers, the Annex B output- //! comes back as length-prefixed H.264 samples with the parameter sets split out for the `avcC`.- //! [`export`] plugs it into Export as an alternative to the software encoder.-//! The encoder runs on the GPU's NVENC engine through the driver's `nvEncodeAPI64.dll` (API 12.1,-//! [`ffi`]; no CUDA, no SDK to install): pictures go in as NV12 input buffers, the Annex B output++//! The encoder runs on the GPU's NVENC engine through the driver's `nvEncodeAPI64.dll` on Windows++//! (on a Direct3D 11 device) or `libnvidia-encode.so.1` on Linux (on the CUDA driver's primary++//! context, `libcuda.so.1`) (API 12.1, [`ffi`]; no CUDA toolkit, no SDK to install): pictures go in as NV12 input buffers, the Annex B output+ //! comes back as length-prefixed samples with the parameter sets split out for the `avcC` (H.264)+ //! or the `hvcC` (HEVC, see [`hevc`]). One session, ring and NV12 path serves both codecs; the+ //! codec only chooses the GUIDs, the codec configuration and how NAL units are told apart.+ //! [`export`] plugs it into Export: as an alternative to the software encoder for H.264, and as the+ //! only encoder of the H.265 format (which has no software encoder).//!//! ```text//! RGBA (the export pipeline) ──► BT.709 limited 4:2:0 (the software encoder's conversion)- //! ──► NV12 input buffer ──NVENC──► Annex B ──► length-prefixed samples + avcC+ //! ──► NV12 input buffer ──NVENC──► Annex B ──► length-prefixed samples + avcC / hvcC+ //!+ //! HDR (PQ / HLG) HEVC Main 10:+ //! encoded BT.2020 R'G'B' floats ──► 10-bit limited 4:2:0 (`filmcraft_export::rgbf_to_yuv420_10`)+ //! ──► P010 input buffer ──NVENC──► same path; VUI BT.2020 + transfer, HDR10 SEI on every IDR (PQ)//! ```//!- //! `unsafe` is confined to `ffi` (data), `device` (device lifetime) and `session` (driver calls); this module is safe- //! code. Hardware encoding never replaces an export that works in software: the factory declines- //! what NVENC cannot do (no NVIDIA GPU or driver, sizes, HDR, two-pass, MXF...) and the software- //! encoder takes over.-//! `unsafe` is confined to `ffi` (data) and `session` (every driver call); this module is safe++//! `unsafe` is confined to `ffi` (data), `device` (the device's lifetime) and `session` (every driver++//! call); this module is safe+ //! code. Hardware H.264 encoding never replaces an export that works in software: the factory+ //! declines what NVENC cannot do (no NVIDIA GPU or driver, sizes, HDR, two-pass, MXF...) and the+ //! software encoder takes over. A declined HEVC export is an error that says why.+#[allow(unsafe_code)]+mod device;pub mod export;#[allow(unsafe_code)]mod ffi;diff --cc crates/platform/src/nvenc/session.rsindex 5c0a69b41,50ae16563..1791c017c--- a/crates/platform/src/nvenc/session.rs+++ b/crates/platform/src/nvenc/session.rs@@@ -1,4 -1,4 +1,4 @@@- //! An NVENC H.264 encode session: the driver library, the device it is opened on, the-//! An NVENC (H.264 or HEVC) encode session: the driver library, the Direct3D 11 device it is opened on, the++//! An NVENC (H.264 or HEVC) encode session: the driver library, the device it is opened on, the//! encoder configuration, and the input / output buffers (every call into the driver).//!//! FFI module (docs/adr/0001-platform-ffi.md): every `unsafe` block has a `// SAFETY:` comment, the@@@ -61,34 -64,85 +61,75 @@@ fn load() -> Result<Api, String>}}-/// A Direct3D 11 device on the first NVIDIA adapter (what an NVENC session is opened on).-fn nvidia_device() -> Result<ID3D11Device, String> {- // SAFETY: plain COM / D3D calls with valid out-pointers; the adapter outlives the call.+#[cfg(target_os = "linux")]+fn load() -> Result<Api, String> {+ // SAFETY: runtime-load NVIDIA's driver and use the signatures from nvEncodeAPI.h.+ // The library lives alongside the immutable function table, for the process lifetime.unsafe {- let factory: IDXGIFactory1 = CreateDXGIFactory1().map_err(|e| format!("no DXGI: {e}"))?;- let mut i = 0;- while let Ok(adapter) = factory.EnumAdapters1(i) {- i += 1;- let Ok(desc) = adapter.GetDesc1() else { continue };- if desc.VendorId != NVIDIA {- continue;- }- let mut device = None;- let adapter: IDXGIAdapter = adapter.cast().map_err(|e| e.to_string())?;- if D3D11CreateDevice(- &adapter,- D3D_DRIVER_TYPE_UNKNOWN,- HMODULE::default(),- D3D11_CREATE_DEVICE_FLAG(0),- None,- D3D11_SDK_VERSION,- Some(&mut device),- None,- None,- )- .is_ok()- && let Some(d) = device- {- return Ok(d);- }+ let library = libloading::Library::new("libnvidia-encode.so.1").map_err(|e| format!("no NVIDIA encoder driver: {e}"))?;+ let version: libloading::Symbol<MaxSupportedVersionFn> = library.get(b"NvEncodeAPIGetMaxSupportedVersion\0").map_err(|e| e.to_string())?;+ let create: libloading::Symbol<CreateInstanceFn> = library.get(b"NvEncodeAPICreateInstance\0").map_err(|e| e.to_string())?;+ let mut v = 0;+ if version(&mut v) != NV_ENC_SUCCESS {+ return Err("cannot query the NVENC version".into());+ }+ let ours = (NVENCAPI_VERSION & 0xf) << 4 | ((NVENCAPI_VERSION >> 24) & 0xf);+ if v < ours {+ return Err(format!("the NVIDIA driver's NVENC ({}.{}) is older than {}.{}", v >> 4, v & 0xf, ours >> 4, ours & 0xf));+ }+ let mut list: NV_ENCODE_API_FUNCTION_LIST = std::mem::zeroed();+ list.version = NV_ENCODE_API_FUNCTION_LIST_VER;+ if create(&mut list) != NV_ENC_SUCCESS {+ return Err("NvEncodeAPICreateInstance failed".into());}+ Ok(Api { list, _library: library })}- Err("no NVIDIA adapter".into())}- /// What the encoder says it can do for H.264.+ /// The codec a session encodes.+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]+ pub enum Codec {+ H264,+ Hevc,+ }++ impl Codec {- fn guid(self) -> windows::core::GUID {++ fn guid(self) -> Guid {+ match self {+ Codec::H264 => NV_ENC_CODEC_H264_GUID,+ Codec::Hevc => NV_ENC_CODEC_HEVC_GUID,+ }+ }+ }++ /// One SEI message the encoder writes in front of every IDR picture (HEVC): its payload type and bytes.+ #[derive(Clone, Debug, PartialEq, Eq)]+ pub struct Sei {+ pub payload_type: u32,+ pub payload: Vec<u8>,+ }++ /// The colour description of a stream (ITU-T H.273 code points, limited range) and the SEI messages+ /// that go with it. The default is BT.709 without SEI.+ #[derive(Clone, Debug, PartialEq, Eq)]+ pub struct Signal {+ pub primaries: u8,+ pub transfer: u8,+ pub matrix: u8,+ pub sei: Vec<Sei>,+ }++ impl Default for Signal {+ fn default() -> Self {+ Signal { primaries: 1, transfer: 1, matrix: 1, sei: Vec::new() }+ }+ }++ /// What the encoder says it can do for a codec.#[derive(Clone, Copy, Debug)]pub struct Caps {+ /// 10-bit encoding (Main 10) is supported.+ pub ten_bit: bool,pub max_bframes: u32,pub min_size: (u32, u32),pub max_size: (u32, u32),diff --cc docs/adr/0001-platform-ffi.mdindex 91e6c2c41,808a1a6bf..3dd438368--- a/docs/adr/0001-platform-ffi.md+++ b/docs/adr/0001-platform-ffi.md@@@ -25,10 -25,12 +25,12 @@@ Containment rules1. The crate does not use `lints.workspace = true`. Its own `[lints]` table copies the workspacelints except `unsafe_code = "deny"` (not `forbid`), and adds- `clippy::undocumented_unsafe_blocks = "deny"`. Only the FFI modules (`videotoolbox`, `media_foundation::gpu` / `media_foundation::mft`, and- `nvenc::ffi` / `nvenc::session` / `nvenc::device` on Windows and 64-bit Linux) carry `#[allow(unsafe_code)]`; the rest of the crate+ `clippy::undocumented_unsafe_blocks = "deny"`. Only the FFI modules (`videotoolbox`, `media_foundation::gpu` / `media_foundation::mft`,- `nvenc::ffi` / `nvenc::session` on Windows, and `vaapi::va` on Linux) carry `#[allow(unsafe_code)]`; the rest of the crate++ `nvenc::ffi` / `nvenc::session` / `nvenc::device` on Windows and 64-bit Linux, and `vaapi::va` on Linux) carry `#[allow(unsafe_code)]`; the rest of the crate(the fallback logic in `hybrid`, the decoder logic in `media_foundation`, `annexb`, `biplanar`,- the encoder logic in `nvenc`) has no `unsafe`.+ the encoder logic in `nvenc`, H.264 and H.265 alike) has no `unsafe`. NVENC's H.265 support+ added no `unsafe` module: it reuses `nvenc::ffi` and `nvenc::session` (new data declarations and+ a second codec-configuration member of an existing union).2. Every `unsafe` block has a `// SAFETY:` comment saying why it is sound.3. The public API is safe: no `pub unsafe fn`, no raw pointers or FFI types in public signatures;failures are `Result`s. The crate keeps the never-crash `deny(clippy::unwrap_used, …)`@@@ -102,12 -112,27 +112,37 @@@ OS has a hardware encoder. Choosing thprobe the platform crate registers, and what the hardware path does not take (two-pass, odd sizes,a machine without the encoder) is an error naming the reason instead of a different encoder.+ ## Addendum (2026-10-08): VA-API hardware decoding on Linux++ The Linux backend this decision named: H.264 and HEVC decoding through VA-API (`vaapi/`). The rules above+ hold; VA-API differs from the other two backends in three ways.++ - **libva is loaded at run time** (`libva.so.2`, `libva-drm.so.2`, through `libloading`: ISC, already+ in the lockfile through wgpu). Building needs no libva headers, and a system without libva, a DRM+ render node or a working driver starts as before and decodes in software (`register()` reports+ `Unavailable`). The declarations (`vaapi/ffi.rs`) are transcribed from libva's MIT-licensed+ `va.h`, and `vaapi/abi_tests.rs` checks sizes, offsets, constants and bit-field positions against a+ C compiler's view of it, as for NVENC. Only `vaapi::va` carries `#[allow(unsafe_code)]`; the+ declarations, the H.264 front end (`vaapi::h264`) and the decoder (`VaDecoder`) are safe code.+ - **Decoding is stateless:** the host parses the stream and keeps the decoded picture buffer; the GPU+ only decodes slice data. FilmCraft does that host side with the software decoders' own parsers and+ DPBs (`filmcraft_h264::dpb` and `filmcraft_hevc::dpb` are generic over what a picture is), so the two decoders decide alike by+ construction, and the front end is tested on every OS against a stand-in for the hardware. The+ one place they cannot agree is concealment: pictures predicted from frames that were never decoded+ (the leading pictures of an open H.264 GOP after a seek) are concealed by both but can differ;+ HEVC pictures with references that were never decoded go to the software decoder instead.+ - **One callback into Rust:** libva's error messages go to our log through a callback that runs under+ `catch_unwind`; its info messages are turned off.++ The fallback guarantee is unchanged: what the hardware path does not take is declined up front or,+ mid-stream, handed to the software decoder by `HybridDecoder`.+++## Addendum: Linux NVENC H.264 encoding++The existing NVENC session is shared with 64-bit Linux. Only device acquisition and driver loading+are platform-specific: Windows retains the Direct3D device; Linux retains the first CUDA device's+primary context through `libcuda.so.1`. `cuDevicePrimaryCtxRetain` does not push a context onto the+calling thread's stack. The retained reference is released after the NVENC session and its buffers;+other users' references are not reset. `libnvidia-encode.so.1` stays loaded with its function table.+Both libraries come from the installed NVIDIA driver, not this project. Export registration on+Linux does not claim that a hardware decoder is available. The same opt-in and fallback rules apply.diff --cc docs/architecture.mdindex fc51325a5,985c6a0ab..055033cb0--- 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; 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) and NVIDIA NVENC H.264 encoding (Windows, opt-in) 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 / VP9 / AV1 on Windows; VA-API H.264 / HEVC on Linux, with our own parsers and DPBs driving the stateless hardware; 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) and NVIDIA NVENC H.264 (Windows, opt-in) and H.265 (Windows, FilmCraft's only H.265 encoder there) encoding 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 / VP9 / AV1 on Windows; VA-API H.264 / HEVC on Linux, with our own parsers and DPBs driving the stateless hardware; 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) and NVIDIA NVENC H.264 (Windows and 64-bit Linux, opt-in) and H.265 (Windows, FilmCraft's only H.265 encoder there) encoding 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)) |