FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Merge M8 (LUTs, colour management, Colour Match) into M4.6 playback; project schema v5 for colour management; architecture §5.3
Brandon Thomasa9af6fac718d
diff --cc Cargo.lockindex 82948334c,d38f40b97..1fc40a8cd--- a/Cargo.lock+++ b/Cargo.lock@@@ -1658,6 -1658,6 +1661,7 @@@ dependencies ="filmcraft-time","image","rayon",++ "rustix 1.1.5","serde","serde_json",]diff --cc ROADMAP.mdindex 33c667578,998f711f3..037b3306a--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -35,8 -35,8 +35,8 @@@ Status: ✅ done · 🟡 in progress �| M4 | Playback | 🟡 | Audio-clock master, prefetch, J/K/L, dropped-frame stats, playback resolution | Render previews, render bar, 4K/8K tuning | 8–12 || M5 | Effects, keyframes, GPU | 🟡 | ~60 CPU effects, 30 transitions, keyframes + value/velocity graphs, wgpu compositor | Full ~150-effect catalogue, WGSL parity for all, masks + tracking, adjustment layers, presets, Warp Stabilizer, Morph Cut | 30–45 || M6 | Export | ✅ | Own H.264 encoder (High/Main/Baseline, B-frames, VBR/CBR/2-pass) → MP4 + own AAC; ProRes, MJPEG, PNG, GIF, WAV; background jobs | Preset library, queue UI, smart render | 6–8 |-| M7 | Audio | 🟡 | Mixer graph (tracks → submixes → Mix, pre/post-fader inserts and sends, latency-compensated, sample-accurate, ~6× realtime for 24 tracks × 3 effects on one core), Audio Track Mixer + Audio Clip Mixer panels, track automation (Off/Read/Latch/Touch/Write, recorded live while playing, thinned to keyframes, timeline lanes with pen editing), solo/solo-safe, channel mapping basics, peak + BS.1770 loudness meters (match ffmpeg), DSP crate with 12 clip/track effects, Audio Gain (set/adjust/normalize), Constant Power / Constant Gain / Exponential Fade | Essential Sound, 5.1 panner and multichannel buses, voice-over record, effect editor windows (EQ curve), remaining effects (multiband, convolution reverb), clip-mixer automation recording | 6–9 |+| M7 | Audio | 🟡 | Mixer graph (tracks → submixes → Mix, pre/post-fader inserts and sends, latency-compensated, sample-accurate, ~6× realtime for 24 tracks × 3 effects on one core), Audio Track Mixer + Audio Clip Mixer panels, track automation (Off/Read/Latch/Touch/Write, recorded live while playing, thinned to keyframes, timeline lanes with pen editing), solo/solo-safe, channel mapping basics, peak + BS.1770 loudness meters (match ffmpeg), DSP crate with 16 clip/track effects, Audio Gain (set/adjust/normalize), Constant Power / Constant Gain / Exponential Fade, Essential Sound (types, Loudness auto-match, Repair incl. DeEss/DeReverb, Clarity, Creative, Ducking keyframes, presets; full Dialogue chain 22× realtime) | Music duration remix, ML speech enhancement, 5.1 panner and multichannel buses, voice-over record, effect editor windows (EQ curve), remaining effects (multiband, convolution reverb), clip-mixer automation recording | 6–9 |- | M8 | Colour | 🟡 | Lumetri: basic, creative + looks, RGB & hue curves, wheels, HSL secondary, vignette; basic scopes | LUT import UI, colour match, colour management + HDR (PQ/HLG, log, tone mapping) | 8–12 |+ | M8 | Colour | 🟡 | Lumetri: basic, creative + looks, RGB & hue curves, wheels, HSL secondary, vignette, section bypass; Input LUT / Look LUT (.cube 1D/3D/shaper, .3dl; tetrahedral CPU + WGSL; project LUT library; built-in camera conversions); Colour Match (Oklab tonal-range statistics, skin protection, solved in Lumetri wheels); colour management: Rec. 709 / Rec. 2100 PQ / HLG working spaces + wide gamut, Interpret Footage colour space (S-Log3, V-Log, Canon Log 2/3, LogC3/4, Apple Log, D-Log from published specs), metadata auto-detect, BT.2390 tone mapping, gamut mapping, HDR export signalling (VUI/colr/mdcv/clli/SEI, ffprobe-verified); scopes incl. HDR nits waveform | Parade/histogram/HLS scopes, HDR-aware Lumetri maths, macOS EDR monitors, mastering metadata → tone-map peak, D-Log M (no published formula), HSL Secondary refine | 3–5 || M9 | More codecs | 🟡 | ProRes decode+encode, AAC decode+encode, HEVC Main/Main 10 decoder (bit-exact on 41 fixtures, ~225 fps 1080p), VP9 decoder (profiles 0–3, 8/10/12-bit, bit-exact on 50+ fixtures; WebM/MKV `V_VP9` and MP4 `vp09` import with key-frame-checked seeking), Matroska/WebM import (H.264/HEVC/VP9/ProRes/MJPEG + AAC/Opus/FLAC/MP3/Vorbis/PCM), Opus decoder (SILK/CELT/hybrid, 5.1/7.1 multistream; all RFC 8251 vectors range-exact; WebM/MKV/MP4) | VP9 frame threading, Ogg Opus files, AV1 (rav1d), DNxHR, MXF, hardware decode | 12–20 || M10 | Graphics & captions | 🟡 | Caption tracks (Subtitle/CEA-608/708/Teletext formats, track style), SRT/WebVTT/SCC import+export (frame-exact, property-tested), caption editing (add/split/merge/trim/move, sync-locked insert/extract), Text panel Captions tab, burn-in in Program monitor and export; text engine (`crates/text`: bundled + system fonts, harfrust shaping, bidi, line breaking, paragraph layout, glyph cache; 3-line 1080p title ≈ 0.15 ms warm); graphic clips with text + shape layers (fill, 2 strokes, background, shadow, keyframable transform), Type tool with on-monitor editing, shape/pen tools, Properties/Essential Graphics editor, align/distribute | Responsive design pins, rolls/crawls, per-character styles, motion graphics templates, MCC/STL/TTML, 608/708 embedding, speech-to-text | 12–18 || M11 | Interchange & project management | 🟡 | `.fcproj` schema versions + migrations, atomic saves, Save a Copy/Revert, auto-save ring + crash-recovery journal (Preferences ▸ Auto Save, recovery prompt), FCP7 XML, FCPXML, EDL, OTIO | Relink/offline, project manager, proxies | 8 |@@@ -48,7 -48,7 +48,8 @@@## Log+- **2026-10-01 (M7.4):** Essential Sound panel: Dialogue/Music/SFX/Ambience types, Loudness auto-match (BS.1770, exact to the target), Repair (noise, rumble, hum, new DeEsser and spectral DeReverb), Clarity (dynamics, EQ presets, Enhance Speech DSP chain), Creative reverb / stereo width, ducking that writes Volume keyframes, presets; all `essentialSound.*` commands, effects visible and keyframable in Effect Controls.+ - **2026-10-01 (night):** M8 colour: camera log curves and gamuts from published specs, colour-managed pipeline (PQ/HLG working spaces, Interpret Footage, BT.2390 tone mapping), HDR export signalling verified with ffprobe, LUTs (.cube/.3dl, tetrahedral CPU + WGSL, project library, Lumetri Input LUT / Look), Colour Match, Lumetri section bypass, HDR scopes.- **2026-10-01 (later):** text engine (shaping, bidi, line breaking) + Type/Shape/Pen tools + graphic clips + graphics panel; Trim Monitor + dynamic trimming; Keyboard Shortcuts editor; audio mixer with automation. Fixed: MP4 muxer wrote unreadable all-empty sample tables; system font scan race.diff --cc crates/engine/src/commands.rsindex 978ed43fa,ed5616d05..6dc4fa6a4--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@@ -1849,7 -1855,7 +1855,8 @@@ fn build() -> Vec<CommandSpec>];v.extend(crate::captions::commands());v.extend(crate::mixer::commands());+ v.extend(crate::essential_sound::commands());+ v.extend(crate::color::commands());v.extend(crate::graphics::commands());v.extend(crate::shortcuts::commands());// Labels as individual commands (Edit ▸ Label ▸ <name>)diff --cc crates/engine/src/lib.rsindex 54ae949cb,f2936ceaa..15cea6811--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@@ -10,9 -10,9 +10,10 @@@pub mod autosave;pub mod captions;+ pub mod color;pub mod commands;pub mod demo;+pub mod essential_sound;pub mod graphics;pub mod interchange;pub mod media_pool;@@@ -556,8 -565,8 +566,10 @@@ pub fn media_duration(p: &Project, _poo#[cfg(test)]mod autosave_tests;#[cfg(test)]+ mod color_tests;+ #[cfg(test)]+mod essential_sound_tests;+#[cfg(test)]mod file_tests;#[cfg(test)]mod mixer_tests;diff --cc crates/format/src/lib.rsindex 208ec6c9d,d81da80e6..3fedfeefa--- a/crates/format/src/lib.rs+++ b/crates/format/src/lib.rs@@@ -22,8 -22,6 +22,10 @@@//! - **v3** (M10.2): graphic clips (`ItemKind::Graphic`, text/shape layers). The shape of older//! data is unchanged (no-op step); the bump makes builds without graphics refuse such files//! cleanly instead of failing to parse them.+//! - **v4** (M7.4): Essential Sound (clip audio types and settings, `EffectInstance::essential`).+//! No-op step; older builds would otherwise drop these fields silently when saving.++//! - **v5** (M8.8): colour management (sequence working space, Interpret Footage colour space,++//! project LUT library). No-op step, for the same reason.pub mod atomic;pub mod autosave;@@@ -42,7 -40,7 +44,7 @@@ pub type Migration = fn(Value) -> Resul/// `MIGRATIONS[i]` upgrades schema `i + 1` to `i + 2`. Append one function per schema bump; never/// edit a shipped one.- pub const MIGRATIONS: &[Migration] = &[v1_to_v2, v2_to_v3, v3_to_v4];-pub const MIGRATIONS: &[Migration] = &[v1_to_v2, v2_to_v3];++pub const MIGRATIONS: &[Migration] = &[v1_to_v2, v2_to_v3, v3_to_v4, v4_to_v5];/// The schema version this build writes (and the newest it reads).pub const SCHEMA_VERSION: u32 = MIGRATIONS.len() as u32 + 1;@@@ -221,18 -219,13 +223,23 @@@ fn v2_to_v3(doc: Value) -> Result<ValueOk(doc)}+/// v3 → v4: Essential Sound fields added; existing data needs no change.+fn v3_to_v4(doc: Value) -> Result<Value, String> {+ Ok(doc)+}+++/// v4 → v5: colour-management fields added; existing data needs no change.++fn v4_to_v5(doc: Value) -> Result<Value, String> {++ Ok(doc)++}++#[cfg(test)]mod tests {use super::*;#[test]fn schema_version_matches_table() {- assert_eq!(SCHEMA_VERSION, 4);- assert_eq!(SCHEMA_VERSION, 3);++ assert_eq!(SCHEMA_VERSION, 5);}#[test]diff --cc crates/render/src/lib.rsindex a0ab6060c,399b7b14b..f34713563--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@@ -260,11 -271,8 +275,11 @@@ pub(crate) fn item_layer};let px_scale = layer.w as f32 / src_size.0.max(1) as f32;if opts.effects {- let cx = effects::FxCtx { t: mt, px_scale, seconds: (t - item.start).seconds(), timecode: tc, clip_name: &item.name };+ let cx = effects::FxCtx { t: mt, px_scale, seconds: (t - item.start).seconds(), timecode: tc, clip_name: &item.name, project: Some(project) };for e in item.effects.iter().filter(|e| e.def().is_some_and(|d| !d.intrinsic) && !filmcraft_project::graphic::is_layer(e)) {+ if filmcraft_media::cancel::cancelled() {+ return None;+ }effects::apply(&mut layer, e, &cx);}}diff --cc crates/ui-egui/src/panels/misc.rsindex 4a21f8b91,b0b8850fd..53659aa0e--- a/crates/ui-egui/src/panels/misc.rs+++ b/crates/ui-egui/src/panels/misc.rs@@@ -205,9 -205,12 +205,14 @@@ pub fn scopes(app: &mut FilmcraftApp, ulet frame = rate.frame_at(app.session.playhead());let key = FrameKey { target: Target::Sequence(seq_id), frame, size: 250, revision: app.session.revision };let project = app.session.project.clone();- app.frames.request(key, rate.tick_of(frame), 0.25, &project, 2);+ // While playing, scopes come after the Program monitor's prefetch.+ let prio = if app.playback.playing { 40 } else { 2 };+ app.frames.request(key, rate.tick_of(frame), 0.25, &project, prio);+ let pipe = app.session.active_sequence().map(|q| q.settings.color).unwrap_or(filmcraft_color::ColorPipeline::REC709);+ if pipe.working.is_hdr() {+ hdr_scopes(app, ui, rect, (seq_id.0, frame, app.session.revision));+ return;+ }let Some(img) = app.frames.get(&key) else {crate::dock::placeholder(ui, rect, &t, "…");return;diff --cc docs/architecture.mdindex f49a10e32,185085893..a98015555--- a/docs/architecture.md+++ b/docs/architecture.md@@@ -269,43 -259,46 +269,83 @@@ Mix: bus sum → pre-fader inserts �mix (Track Mixer and Audio Meters read them) and the newest project snapshot, which the audiocallback uses, so edits made during playback are heard.-### 5.2 Colour management+### 5.2 Essential Sound++```text+clip.essential (type + settings) ──apply()──► clip effects marked `essential`, clip gain, Volume, Panner+essentialSound.autoMatch BS.1770 integrated loudness of render::audio::clip_signal → match gain (clip gain)+essentialSound.generateDucking trigger clips' summed level (10 ms hops) → activity regions → Volume keyframes+```++- **Model** (`project::essential`). A clip's `essential: Option<EssentialSound>` holds its audio type+ (Dialogue / Music / SFX / Ambience) and per-type sections: Loudness (match gain, measured and target+ LUFS), Repair (Reduce Noise, Reduce Rumble, DeHum 50/60 Hz, DeEss, Reduce Reverb), Clarity+ (Dynamics, EQ preset + amount, Enhance Speech), Creative (Reverb preset + amount, Stereo Width for+ Ambience), Ducking (against types, sensitivity, reduce by, fades), Pan, Clip Volume and Mute.+- **Effects under the hood.** `essential::apply(item, old, t)` turns the settings into ordinary clip+ effects (Highpass, DeNoise, DeHummer, DeEsser, DeReverb, Dynamics Processing, Parametric Equalizer,+ Enhance Speech, Stereo Width, Studio Reverb) flagged `EffectInstance::essential`, in that order, ahead+ of the user's own effects. Only parameters whose derived value changed are written (at the playhead),+ so keyframes added in Effect Controls survive. A section switch bypasses its effects, a slot switch+ removes its effect, clearing the type removes them all. Auto-match gain, Clip Volume (an offset on+ the Volume level or on all its keyframes) and Pan are applied as deltas, so clearing restores the+ clip. Because these are normal effects, playback, the mixer and export need nothing special.+- **Loudness.** The clip signal (clip gain + effects, before Volume) is measured with the BS.1770+ meter; the gain is linear after the effects, so one measurement hits the target exactly. Targets are+ preferences (`audio.dialogueTargetLufs` −23, `musicTargetLufs` −25, `sfxTargetLufs` −21,+ `ambienceTargetLufs` −30).+- **Ducking.** Sensitivity 0…10 maps to a threshold −20 − 4·s dBFS on the summed trigger signal (50 ms+ window); regions shorter than 100 ms are dropped and pauses under 250 ms bridged; each region gets a+ fade-down before it and a fade-up after it (`audio_dsp::ducking::duck_keyframes`), written as Volume+ level keyframes that replace earlier ones.+- **Presets** (our own names and values) per type; user presets are saved in preferences+ (`essentialSound.userPresets`). Music remixing to a duration is out of scope (the Duration section+ says so).+- **Enhance Speech** is a DSP chain (high-pass, de-mud, presence and air EQ, expander, compressor), not a+ model: no speech-enhancement model with an open licence that we could ship and verify is bundled.+ DeepFilterNet (MIT/Apache-2.0, Rust inference via tract) is the candidate for a future optional+ integration behind a trait.+++### 5.3 Colour management++ ```text+ frame (Y'CbCr/RGB + metadata) ─► source colour space: Interpret Footage override, else VUI/colr/MKV Colour+ ─► decode table (sRGB/BT.709, PQ, HLG scene light, camera log) ─► HLG OOTF ─► 3×3 to working gamut+ ─► BT.2390 tone map (HDR/log into an SDR sequence, Auto Tone Map Media) ─► gamut compression+ ─► effects + compositing in working linear (1.0 = reference white = SDR white = 203 cd/m²)+ ─► monitors: working → SDR BT.709 (tone map from HDR, gamut map from BT.2020)+ ─► HDR export: working → PQ/HLG BT.2020 R'G'B' → Y'CbCr (BT.2020 NCL) + VUI/colr/mdcv/clli/SEI+ ```++ - **Model.** `SequenceSettings::color` (`ColorPipeline`: working space Rec. 709 / Rec. 2100 PQ /+ Rec. 2100 HLG, wide gamut, auto tone map) and `Interpretation::color_space` (per media item;+ `None` = from metadata). Commands: `sequence.colorSettings`, `clip.interpretFootage`,+ `color.spaces`, `media.colorInfo`.+ - **Maths** in `filmcraft-color` (`transform`, `log`, `spaces`; formulas and sources in+ [crates/color/README.md](../crates/color/README.md)); the renderer side is `render::colorman`.+ - **Fast path.** A Rec. 709 sequence without wide gamut and media whose metadata says Rec. 709 /+ sRGB decodes exactly as before, and its layers stay on the GPU. Log, HDR or wide-gamut media,+ and every layer of an HDR/wide-gamut sequence, are converted on the CPU (the GPU path draws them+ as pre-rendered images, like layers with effects).+ - **Outputs.** `RenderOptions::working_output` returns working-space pixels (HDR exports,+ scopes); otherwise the top-level render is converted for an SDR monitor. Lumetri and the other+ colour effects work on display-encoded values clamped to 0..1, so in an HDR sequence they clip+ highlights above reference white (HDR-aware grading is future work).+ - **HDR export.** H.264 and ProRes exports of a PQ/HLG sequence encode BT.2020 PQ/HLG (ProRes+ 10-bit; our H.264 encoder is 8-bit, so H.264 HDR is 8-bit) and signal it in the VUI / ProRes+ frame header, `colr`, and for PQ `mdcv` (BT.2020 / D65, 1000 / 0.0001 cd/m²) and `clli`+ (MaxCLL/MaxFALL 0 = unknown, they are not measured) plus the matching H.264 SEI. `sdr: true`+ exports the tone-mapped SDR picture instead; render previews always do.+ - **Monitors / display colour management.** The monitors are SDR (sRGB-encoded RGBA8 textures):+ HDR sequences are shown tone mapped. macOS EDR (extended-range `CAMetalLayer` output) is not+ wired up: there is no `platform` crate yet and eframe/wgpu do not expose an EDR surface, so HDR+ values above SDR white are never sent to the display. The scopes of an HDR sequence show the+ working-space values (waveform in cd/m² on a PQ scale, BT.2020 vectorscope).+ - **LUTs.** Lumetri Input LUT and Creative Look reference `lib:<id>` (the project's LUT library,+ `Project::luts`, embedded `.cube`/`.3dl` text) or `builtin:<id>` (code-generated camera+ conversions and looks). `filmcraft-gpu::GpuLut` is the WGSL tetrahedral counterpart, tested for+ parity.+## 6. Export jobs (`filmcraft-export`)```textdiff --cc docs/project-files.mdindex 4da57a125,9b6dfc6ae..827c97295--- a/docs/project-files.md+++ b/docs/project-files.md@@@ -8,7 -8,7 +8,7 @@@ writing them is `crates/format` (`filmc```json{"format": "filmcraft.project",- "schema_version": 4,- "schema_version": 3,++ "schema_version": 5,"generator": "FilmCraft 0.1.0","project": { "name": "…", "settings": { … }, "root": { … }, "items": { … }, "next_id": 48 }}@@@ -27,7 -27,6 +27,8 @@@| 1 | M0 | the bare `Project` object with a `"version": 1` field || 2 | M11.1 | the envelope above; the project's own `version` field is gone || 3 | M10.2 | graphic clips (`ItemKind::Graphic` with text/shape layers); a no-op step for older data |+| 4 | M7.4 | Essential Sound: clip audio types and settings; no-op step |++| 5 | M8.8 | colour management: working space, Interpret Footage colour space, LUT library; no-op step |### Migrations@@@ -55,8 -53,8 +56,8 @@@ on disk is unchanged until you save. ThA file with a `schema_version` newer than the build supports is **refused**, not half-read:- > this project was saved by a newer version of FilmCraft (project schema v5); this build reads up to- > v4. Update FilmCraft to open it.-> this project was saved by a newer version of FilmCraft (project schema v4); this build reads up to-> v3. Update FilmCraft to open it.++> this project was saved by a newer version of FilmCraft (project schema v6); this build reads up to++> v5. Update FilmCraft to open it.Reading it partially and saving it back would silently drop whatever the newer version added.diff --cc docs/testing.mdindex 2c74ba3a8,32c9d18a0..342168768--- a/docs/testing.md+++ b/docs/testing.md@@@ -133,19 -136,19 +136,31 @@@ keyframes and the Audio Gain dialog byover several frames, release). With `FILMCRAFT_UI_SNAPSHOT_DIR=<dir>` it also renders the windowoffscreen through wgpu (`Harness::render`) and writes `mixer-*.png`; this works without a visiblewindow (for example on a locked screen, where `ui.screenshot` cannot capture).+`crates/ui-egui/tests/essential_sound_ui.rs` does the same for the Essential Sound panel (type buttons,+switches, a slider drag as one undo step, section bypass, Auto-Match, ducking, Browse presets;+`essential-sound-*.png`).++Essential Sound engine tests (`crates/engine/src/essential_sound_tests.rs`) build projects from+generated speech-like and tonal WAVs: Auto-Match lands within ±0.5 LU of the target (measured: 0.000 LU,+with and without a repair/clarity chain); ducking on a dialogue + music project gives keyframes within+60 ms of the expected times (measured 20 ms) and −15.00 dB in the mix; each repair stage improves its+metric through the render path (hum −39 dB, rumble −22 dB, noise floor −13 dB, sibilance −19 dB,+reverb tail −10 dB); the mix is bit-identical however requests are cut and the WAV export equals it.+`perf_full_dialogue_chain_realtime_factor` (ignored; run with `--release`) prints the realtime factor of+all nine Dialogue effects on one clip (22× on one core).+ `crates/ui-egui/tests/color_ui.rs` drives colour features the same way (`color-*.png` snapshots):+ Lumetri Input/Look LUT menus and section switches, the Interpret Footage ▸ Color Management and+ Sequence Color Management dialogs, and the HDR scopes of a PQ sequence.++ Colour science tests: `filmcraft-color` (curve round trips and published reference values per+ camera log curve, BT.709/BT.2087 matrices, BT.2390 EETF, gamut mapping, LUT tetrahedral vs a+ brute-force barycentric reference, `.cube`/`.3dl` round trips), `filmcraft-gpu`+ (`gpu_lut_matches_cpu_tetrahedral`: WGSL vs CPU, max |Δ| ≈ 2e-7), `render::colorman`,+ `render::color_match`, engine `color_tests.rs`, and `export::tests::hdr_exports_signal_pq_and_hlg`+ (PQ/HLG exports read back by our demuxer and by ffprobe: `color_transfer`, `color_primaries`,+ `color_space`, mastering display and content light side data).+Not covered headless: `ui.screenshot` (needs a real viewport), the wgpu monitor path (the harnessruns the CPU texture path), audio output, and wall-clock playback advance (kittest frames do notadvance real time). Use `Driver` for new UI regressions: `d.exec(command, params)`,