Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

updates

Jareeracc02106be54
diff --git a/.github/workflows/ffmpeg.yml b/.github/workflows/ffmpeg.yml
new file mode 100644
index 00000000..889d247a
--- /dev/null
+++ b/.github/workflows/ffmpeg.yml
@@ -0,0 +1,127 @@
+name: Build FFmpeg
+
+# Builds the cut-down FFmpeg that Relay ships.
+#
+# Run by hand, not on every push. The output only changes when the version or
+# the feature list below changes, which is roughly never - so this produces an
+# artifact you download once and commit to the release, rather than something
+# that runs on your time.
+#
+# Why not build locally: the reduced build takes 20-35 minutes on a 4-core
+# machine, and most of that is `configure` spawning thousands of tiny probes,
+# which Windows is bad at. Here it runs while you do something else, and the
+# exact source and configure line are recorded in the log.
+on:
+ workflow_dispatch:
+ inputs:
+ version:
+ description: "FFmpeg release tag (e.g. n8.1.2)"
+ required: true
+ default: "n8.1.2"
+
+jobs:
+ windows:
+ runs-on: windows-latest
+ defaults:
+ run:
+ shell: msys2 {0}
+
+ steps:
+ - uses: msys2/setup-msys2@v2
+ with:
+ msystem: UCRT64
+ update: true
+ # nasm is not optional: without it the x86 assembly is skipped and
+ # decoding runs several times slower.
+ install: >-
+ base-devel
+ git
+ diffutils
+ make
+ pkgconf
+ nasm
+ yasm
+ mingw-w64-ucrt-x86_64-gcc
+ mingw-w64-ucrt-x86_64-x264
+
+ - name: Fetch FFmpeg source
+ run: |
+ git clone --depth 1 --branch "${{ inputs.version }}" \
+ https://github.com/FFmpeg/FFmpeg.git ffmpeg
+ cd ffmpeg && git rev-parse HEAD > ../SOURCE-COMMIT.txt
+
+ - name: Configure
+ run: |
+ cd ffmpeg
+ #
+ # Everything off, then only what Relay actually invokes turned back
+ # on. This is where the size comes from: a full avcodec carries some
+ # five hundred codecs, and an editor opens perhaps a dozen.
+ #
+ # If you add a format to the app, add it here too - the failure mode
+ # is "could not open", not a crash.
+ #
+ ./configure \
+ --prefix=../out \
+ --disable-everything \
+ --disable-doc \
+ --disable-debug \
+ --disable-network \
+ --disable-autodetect \
+ --disable-ffplay \
+ --disable-shared \
+ --enable-static \
+ --enable-small \
+ --enable-gpl \
+ --enable-libx264 \
+ --enable-decoder=h264,hevc,vp8,vp9,av1,mpeg4,mjpeg,prores,dnxhd,png,webp,bmp,tiff,gif,aac,mp3,flac,opus,vorbis,alac,pcm_s16le,pcm_s24le,pcm_s32le,pcm_f32le \
+ --enable-encoder=libx264,aac,mjpeg,png,pcm_s16le \
+ --enable-demuxer=mov,matroska,avi,mp3,wav,flac,ogg,aac,image2,gif,rawvideo,concat,lavfi \
+ --enable-muxer=mp4,mov,mp3,wav,ipod,mjpeg,image2,rawvideo,null \
+ --enable-parser=h264,hevc,vp8,vp9,av1,aac,mpegaudio,flac,vorbis,png,mjpeg \
+ --enable-bsf=h264_mp4toannexb,hevc_mp4toannexb,aac_adtstoasc \
+ --enable-protocol=file,pipe \
+ --enable-filter=scale,tile,fps,format,null,copy,setpts,trim,transpose,crop,overlay \
+ --enable-filter=aresample,asetrate,atempo,aformat,anull,atrim,asetpts,adelay,amix,apad,afade,volume \
+ --enable-filter=highpass,lowpass,equalizer,bass,treble,compand,deesser,aecho,alimiter,aphaser,flanger \
+ --enable-filter=abuffer,abuffersink,buffer,buffersink,anullsrc,aevalsrc,testsrc2,sine
+
+ - name: Build
+ run: cd ffmpeg && make -j"$(nproc)" && make install
+
+ - name: Verify it can do the work
+ run: |
+ set -e
+ BIN=out/bin
+ "$BIN/ffmpeg.exe" -hide_banner -version | head -1
+ "$BIN/ffprobe.exe" -hide_banner -version | head -1
+
+ # Not a smoke test of the binary - a check that the *feature list*
+ # above is sufficient. Each of these mirrors something the app does.
+ "$BIN/ffmpeg.exe" -hide_banner -loglevel error -y \
+ -f lavfi -i testsrc2=size=320x240:rate=30 -t 1 \
+ -c:v libx264 -pix_fmt yuv420p probe.mp4
+ "$BIN/ffprobe.exe" -v error -show_streams -of json probe.mp4 > /dev/null
+ "$BIN/ffmpeg.exe" -hide_banner -loglevel error -y -i probe.mp4 \
+ -vf "fps=4,scale=-2:72,tile=4x1" -frames:v 1 -f mjpeg strip.jpg
+ "$BIN/ffmpeg.exe" -hide_banner -loglevel error -y -i probe.mp4 \
+ -f rawvideo -pix_fmt rgba - > /dev/null
+ "$BIN/ffmpeg.exe" -hide_banner -loglevel error -y \
+ -f lavfi -i sine=frequency=220:duration=1 \
+ -af "aresample=48000,asetrate=52000,aresample=48000,atempo=0.92,highpass=f=85,equalizer=f=4200:t=q:w=0.8:g=3,compand=attacks=0.01:decays=0.18:points=-80/-80|0/-1.5,deesser=i=0.3,aecho=0.8:0.82:38:0.02,alimiter=limit=0.94" \
+ -f wav filtered.wav
+ echo "every path the app uses is present"
+
+ - name: Report size
+ run: |
+ ls -l out/bin
+ du -sh out/bin
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: ffmpeg-${{ inputs.version }}-win64
+ path: |
+ out/bin/ffmpeg.exe
+ out/bin/ffprobe.exe
+ SOURCE-COMMIT.txt
+ if-no-files-found: error
diff --git a/.gitignore b/.gitignore
index f4d43db9..15ee3376 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,3 +62,7 @@ desktop.ini
# FFmpeg development build for the FFI decoder (headers + import libs).
# Large, machine-specific, and not needed for a normal build - see BUILD.md.
/vendor/
+
+# Bundled FFmpeg, staged for packaging. Produced by .github/workflows/ffmpeg.yml
+# or copied from a dev build - either way it is a binary artifact, not source.
+desktop/src-tauri/ffmpeg/
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
new file mode 100644
index 00000000..ed419c2a
--- /dev/null
+++ b/ARCHITECTURE.md
@@ -0,0 +1,265 @@
+# How Relay works
+
+A map of the whole system. For *why* particular choices were made, see the
+decision logs in `engine/docs/decisions/` and `desktop/docs/decisions/`.
+
+## The two halves
+
+```mermaid
+graph TB
+ subgraph desktop["desktop/ — the editor"]
+ UI["React UI<br/>(runs in WebView2)"]
+ HOST["Tauri host<br/>relay-desktop.exe"]
+ end
+
+ subgraph engine["engine/ — the video engine"]
+ CORE["relay-core<br/>time · arena · frames · timeline"]
+ MEDIA["relay-media<br/>decode · encode · probe"]
+ RENDER["relay-render<br/>plan · composite"]
+ CLI["relay-cli<br/>headless driver"]
+ end
+
+ FF["ffmpeg / ffprobe<br/>(child processes)"]
+
+ UI -->|"invoke() — JSON"| HOST
+ HOST -.->|"events"| UI
+ HOST -->|"plain function calls"| MEDIA
+ HOST --> RENDER
+ MEDIA --> CORE
+ RENDER --> CORE
+ CLI --> MEDIA
+ CLI --> RENDER
+ MEDIA -->|spawn| FF
+ HOST -->|spawn| FF
+```
+
+The engine has **no idea a UI exists**. It builds, tests and versions on its
+own, `relay-cli` drives the identical code from a terminal, and every engine
+test runs headless. That is why `desktop/` depends on `engine/` by path and
+never the reverse.
+
+`relay-core` has **zero dependencies** — std only. It is the vocabulary
+everything else speaks, so a dependency there is a dependency everywhere.
+
+## The bridge
+
+There is no IPC between the host and the engine — they are one process, and
+calls are ordinary Rust. The only boundary is between the webview and the host,
+and it carries four different kinds of traffic for four different reasons.
+
+```mermaid
+graph LR
+ UI["React"]
+ HOST["Rust host"]
+ DISK[("files on disk")]
+
+ UI -->|"1. invoke — JSON commands"| HOST
+ HOST -->|"2. events — export progress"| UI
+ HOST -->|"3. ipc::Response — raw ArrayBuffer"| UI
+ DISK -->|"4. asset:// — straight to video/audio/img"| UI
+```
+
+1. **Commands** — `probe_media`, `export_project`, `save_project`… Every one
+ goes through `src/lib/engine.ts`; nothing else in the app calls `invoke`, so
+ a signature change has exactly one place to fix.
+2. **Events** — export runs on a blocking thread and emits `export://progress`.
+ A two-minute render that says nothing is indistinguishable from a hang.
+3. **Raw bytes** — filmstrips, audio, filtered renders. A few megabytes as a
+ JSON array of numbers would be unusable.
+4. **The asset protocol** — media files load straight into `<video>`/`<audio>`
+ without touching Rust. Preview playback is not bottlenecked on the bridge.
+
+## Two paths through everything
+
+This is the single most important thing to understand. **Preview and export are
+different code paths**, and they are allowed to be — but only where they
+cannot disagree about the *result*.
+
+```mermaid
+graph TB
+ MODEL["The edit<br/>lib/project.ts"]
+
+ subgraph preview["Preview — must be instant"]
+ VID["&lt;video&gt; element"]
+ AUD["&lt;audio&gt; + GainNode"]
+ end
+
+ subgraph export["Export — must be correct"]
+ PLAN["relay-render::plan_frame"]
+ COMP["CpuCompositor"]
+ MIX["ffmpeg filter_complex"]
+ end
+
+ MODEL --> VID
+ MODEL --> AUD
+ MODEL --> PLAN
+ PLAN --> COMP
+ MODEL --> MIX
+```
+
+| | Preview | Export |
+|---|---|---|
+| Picture | one `<video>`, top clip only | full multi-track composite |
+| Sound | media elements + gain nodes | ffmpeg `filter_complex` mix |
+| Compositing | **none** | real |
+| Clock | browser `requestAnimationFrame` | frame counter |
+
+The preview deliberately cannot composite. Two stacked clips show only the
+upper one. That is a known limit, not a bug — see
+`desktop/docs/decisions/0004`.
+
+**Where they must agree, there is only one source of truth.** Clip gain, fades,
+speed and filters are *numbers on the clip*, and both paths read the same
+numbers. Audio filters go further: `lib/filters.ts` produces one FFmpeg filter
+string, and the preview plays a render produced by that exact string. There is
+no second implementation to drift.
+
+## FFmpeg, in five places
+
+```mermaid
+graph LR
+ P["probe_media"] -->|ffprobe| A["stream info"]
+ F["extract_filmstrip"] -->|ffmpeg| B["clip thumbnails"]
+ R["render_filtered_audio"] -->|ffmpeg| C["filtered preview audio"]
+ E["export — picture"] -->|"relay-media pipe"| D["composited frames"]
+ M["export — sound"] -->|"ffmpeg filter_complex"| G["mixed track"]
+```
+
+All five spawn FFmpeg as a **child process** rather than linking it. The
+reasoning, its real costs, and the exit criteria are in
+`engine/docs/decisions/0002-ffmpeg-over-a-pipe.md`.
+
+Short version: a pipe carries no presentation timestamps and cannot seek to an
+exact frame. Those are correctness limits, not performance ones, and they are
+why a linked decoder exists —
+
+### The FFI decoder (built, tested, **not yet used**)
+
+`relay-media`'s optional `ffi` feature builds `FfiDecoder`, which links
+libav\* directly and provides the two things the pipe cannot:
+
+- `position()` — the real presentation timestamp, as an exact rational
+- `seek()` — frame-accurate, via keyframe-seek plus decode-forward
+
+It is off by default and nothing in the app enables it. It exists so that
+playback can be rewritten onto it; until then the subprocess path is what runs.
+
+The seam that made this cheap: `FrameSource` is the trait both implement, and
+`SeekableSource` is deliberately *separate* so the pipe cannot pretend to offer
+seeking it does not have.
+
+## The edit model
+
+```mermaid
+graph TB
+ PROJ["Project"]
+ MED["MediaItem[]<br/>path · kind · duration"]
+ TRK["Track[]<br/>name · visible · muted"]
+ CLIP["Clip[]<br/>start · duration · sourceStart<br/>volume · fades · speed · filters"]
+
+ PROJ --> MED
+ PROJ --> TRK
+ PROJ --> CLIP
+ CLIP -->|mediaId| MED
+ CLIP -->|trackId| TRK
+```
+
+Tracks are **untyped** — any media on any lane. A clip knows what it is; a
+track does not need to. Track order is bottom-first, matching the engine's
+compositing order, and the timeline draws it reversed.
+
+Every operation is a pure function `(project, args) => project`. That is the
+shape a command sent to the engine will have, so the call sites survive the
+migration when the engine takes ownership of the model.
+
+**This model is provisional.** `relay-core` already has a better version of
+these types — exact rational time, generational arena handles. The UI holds it
+only because the engine has no project *API* yet.
+
+## Time
+
+The engine works in **exact rationals**, never floats:
+
+```
+29.97 fps → Rational(30000, 1001) not 29.97
+frame 1800 → Rational(60060, 1000) exactly 60.06s
+```
+
+An `f64` accumulator drifts — add `1/29.97` for an hour and you are visibly
+off. `relay-core::time` is tested against exactly this: 107,892 accumulated
+frame durations still land on the right frame.
+
+The UI works in `f64` seconds, which is a real downgrade, and is acceptable
+only because nothing there is authoritative. **The conversion happens at the
+Rust boundary**, where `export.rs` quantises every value onto the frame grid.
+
+## Rendering the timeline
+
+The timeline is one `<canvas>` with a single `requestAnimationFrame` loop.
+A real edit is thousands of clips and keyframes; as DOM nodes that is thousands
+of elements restyled on every scrub, and layout — not React — is the wall.
+
+```mermaid
+graph LR
+ RAF["rAF loop"] --> READ["read view ref"]
+ READ --> LANES["lanes"] --> RULER["ruler"] --> CLIPS["clips + artwork"] --> PLAY["playhead"]
+```
+
+The loop reads props through a ref, so a prop change never tears it down. Clip
+artwork — waveforms and filmstrips — lives in a plain `Map` that the loop reads
+directly, so artwork arriving costs **no React render**.
+
+Canvas cannot resolve `var(--color-x)`, so the palette is copied out of the
+stylesheet whenever the theme changes.
+
+## Persistence
+
+```mermaid
+graph LR
+ A["Project (memory)"] -->|"save_project"| B["relay.json"]
+ B -->|"load_project"| A
+ C["recents.json<br/>(app config dir)"] --- D["launch screen"]
+ E["peaks · filmstrips · renders"] -.->|"regenerable"| F["cache"]
+```
+
+- **`relay.json`** lives in the project folder and holds the whole edit. Written
+ to a temp file and renamed into place, because a half-written save is worse
+ than no save.
+- **`recents.json`** lives in the *app config* directory, not in any project —
+ copying a project to another machine should not drag your history along.
+- **Caches** are derived data and belong nowhere near either.
+
+## Layout of the repository
+
+```
+engine/
+ crates/relay-core time, arena, frames, timeline model (no deps)
+ crates/relay-media probe, decode, encode, optional FFI
+ crates/relay-render frame plan, CPU compositor
+ crates/relay-cli headless driver
+ docs/decisions/ why the engine is the way it is
+
+desktop/
+ src/App.tsx shell, window state, keyboard map
+ src/components/ panels, timeline canvas, chrome
+ src/lib/engine.ts the ONLY file that calls invoke()
+ src/lib/project.ts the provisional edit model
+ src/lib/filters.ts filter catalogue → ffmpeg strings
+ src/lib/audio.ts preview playback and gain
+ src-tauri/src/ commands, export pipeline, project files
+ docs/decisions/ why the app is the way it is
+
+vendor/ FFmpeg dev build for the FFI feature (gitignored)
+BUILD.md how to build it
+```
+
+## Rules worth keeping
+
+1. **`lib/engine.ts` is the only file that calls `invoke`.**
+2. **The engine never learns about the UI.** If a command starts making
+ decisions about the edit, that logic belongs in `relay-core`.
+3. **No time arithmetic in TypeScript.** `lib/time.ts` formats; it does not
+ compute.
+4. **The timeline is not DOM.**
+5. **One source of truth per behaviour.** Where preview and export must agree,
+ they read the same numbers or run the same string.
diff --git a/desktop/src-tauri/src/export.rs b/desktop/src-tauri/src/export.rs
index 11385d3c..c00574eb 100644
--- a/desktop/src-tauri/src/export.rs
+++ b/desktop/src-tauri/src/export.rs
@@ -51,6 +51,16 @@ pub struct ExportClip {
/// FFmpeg filter chain from the Filters tab, or empty.
#[serde(default)]
pub filter_chain: String,
+ /// Playback rate. 1 is normal.
+ #[serde(default = "unity")]
+ pub speed: f64,
+ /// False lets pitch rise with the rate, like tape.
+ #[serde(default = "yes")]
+ pub preserve_pitch: bool,
+}
+
+fn yes() -> bool {
+ true
}
fn unity() -> f64 {
@@ -303,11 +313,31 @@ fn mix_audio(clips: &[&ExportClip], duration: f64, destination: &Path) -> Result
// Gain and fades sit between the restamp and the delay: after the
// restamp so the fade times are measured from the clip's own start,
// and before the delay so they are not pushed along with it.
+ // A sped-up clip covers more source than its timeline length, so the
+ // trim has to take `duration * speed` before the rate is applied.
+ let speed = clip.speed.clamp(0.1, 8.0);
let mut stage = format!(
"[{index}:a]atrim=start={:.6}:duration={:.6},asetpts=PTS-STARTPTS",
- clip.source_start, clip.duration
+ clip.source_start,
+ clip.duration * speed
);
+ if (speed - 1.0).abs() > f64::EPSILON {
+ if clip.preserve_pitch {
+ // atempo time-stretches, leaving pitch alone. Its per-instance
+ // range is limited, so a large change is split into stages
+ // that multiply out to the requested rate.
+ for factor in tempo_stages(speed) {
+ stage.push_str(&format!(",atempo={factor:.6}"));
+ }
+ } else {
+ // Resampling moves pitch and tempo together - the tape effect.
+ stage.push_str(&format!(
+ ",asetrate=48000*{speed:.6},aresample=48000"
+ ));
+ }
+ }
+
// Filters first: they are what the clip *is* now, and gain and fades
// are adjustments applied to that result. Reversing the order would
// let a compressor inside a filter chain undo the fade.
@@ -349,6 +379,27 @@ fn mix_audio(clips: &[&ExportClip], duration: f64, destination: &Path) -> Result
run_ffmpeg(command, "mixing audio")
}
+/// Splits a rate into `atempo` stages that each stay inside its valid range.
+///
+/// One filter instance is limited, so 4x has to become 2x then 2x. Multiplying
+/// the stages back together is what keeps the result exact.
+fn tempo_stages(speed: f64) -> Vec<f64> {
+ let mut stages = Vec::new();
+ let mut remaining = speed;
+
+ while remaining > 2.0 {
+ stages.push(2.0);
+ remaining /= 2.0;
+ }
+ while remaining < 0.5 {
+ stages.push(0.5);
+ remaining /= 0.5;
+ }
+
+ stages.push(remaining);
+ stages
+}
+
fn mux(video: &Path, audio: &Path, output: &Path) -> Result<(), String> {
let mut command = std::process::Command::new(relay_media::ffmpeg());
command
@@ -384,3 +435,31 @@ fn emit(app: &tauri::AppHandle, frame: i64, total: i64, stage: &'static str) {
// A dropped progress event is not worth failing an export over.
let _ = app.emit("export://progress", Progress { frame, total, stage });
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn tempo_stages_multiply_back_to_the_requested_rate() {
+ for speed in [0.25, 0.5, 0.9, 1.0, 1.5, 2.0, 3.0, 4.0, 8.0] {
+ let product: f64 = tempo_stages(speed).iter().product();
+ assert!(
+ (product - speed).abs() < 1e-9,
+ "stages for {speed} multiplied to {product}",
+ );
+ }
+ }
+
+ #[test]
+ fn every_stage_is_within_the_filter_range() {
+ for speed in [0.25, 0.5, 1.0, 4.0, 8.0] {
+ for factor in tempo_stages(speed) {
+ assert!(
+ (0.5..=2.0).contains(&factor),
+ "{factor} is outside atempo's range, from speed {speed}",
+ );
+ }
+ }
+ }
+}
diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs
index 2360ff11..f137aa6f 100644
--- a/desktop/src-tauri/src/lib.rs
+++ b/desktop/src-tauri/src/lib.rs
@@ -358,34 +358,57 @@ fn describe(error: relay_media::Error) -> String {
message
}
-/// Points the engine at the bundled FFmpeg, if there is one.
+/// Points the engine at the bundled FFmpeg.
///
-/// Tauri drops sidecar binaries next to the app executable with the target
-/// triple stripped, so this looks for them there and silently leaves the
-/// engine on its `PATH` default otherwise. That fallback is what keeps
-/// `cargo run` working without copying binaries into the build directory.
+/// Relay ships its own copy so that a fresh install works without the user
+/// having installed anything - "is FFmpeg on PATH?" is not a question anyone
+/// should have to answer to open a video file.
///
-/// Both must be present to switch: a bundled decoder paired with whatever
-/// `ffprobe` happens to be on PATH is a version mismatch waiting to happen.
-fn use_bundled_ffmpeg() {
- let Ok(executable) = std::env::current_exe() else { return };
- let Some(directory) = executable.parent() else { return };
+/// Searched in order: the bundled resource directory, then beside the
+/// executable (which is where a `cargo run` build finds it), then nothing -
+/// leaving the engine on its `PATH` default, which is what keeps development
+/// working without copying 170 MB into every build directory.
+///
+/// Both binaries must be present to switch. A bundled decoder paired with
+/// whatever `ffprobe` happens to be on PATH is a version mismatch waiting to
+/// happen, and it would be an intermittent one.
+fn use_bundled_ffmpeg(app: &tauri::App) {
+ use tauri::Manager;
let suffix = if cfg!(windows) { ".exe" } else { "" };
- let ffmpeg = directory.join(format!("ffmpeg{suffix}"));
- let ffprobe = directory.join(format!("ffprobe{suffix}"));
- if ffmpeg.is_file() && ffprobe.is_file() {
- relay_media::set_binaries(ffmpeg, ffprobe);
+ let mut candidates: Vec<std::path::PathBuf> = Vec::new();
+ if let Ok(resources) = app.path().resource_dir() {
+ candidates.push(resources.join("ffmpeg"));
+ }
+ if let Ok(executable) = std::env::current_exe() {
+ if let Some(directory) = executable.parent() {
+ candidates.push(directory.join("ffmpeg"));
+ candidates.push(directory.to_path_buf());
+ }
+ }
+
+ for directory in candidates {
+ let ffmpeg = directory.join(format!("ffmpeg{suffix}"));
+ let ffprobe = directory.join(format!("ffprobe{suffix}"));
+
+ if ffmpeg.is_file() && ffprobe.is_file() {
+ relay_media::set_binaries(ffmpeg, ffprobe);
+ return;
+ }
}
}
/// Builds and runs the editor window.
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
- use_bundled_ffmpeg();
-
tauri::Builder::default()
+ .setup(|app| {
+ // Resolved here rather than before the builder, because finding
+ // the resource directory needs the app to exist.
+ use_bundled_ffmpeg(app);
+ Ok(())
+ })
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![
diff --git a/desktop/src-tauri/tauri.conf.json b/desktop/src-tauri/tauri.conf.json
index a1f888ce..ef79878d 100644
--- a/desktop/src-tauri/tauri.conf.json
+++ b/desktop/src-tauri/tauri.conf.json
@@ -27,7 +27,9 @@
"csp": null,
"assetProtocol": {
"enable": true,
- "scope": ["**"]
+ "scope": [
+ "**"
+ ]
}
}
},
@@ -40,6 +42,9 @@
"icons/icon.icns",
"icons/icon.ico"
- ]
+ ],
+ "resources": {
+ "ffmpeg/*": "ffmpeg/"
+ }
}
}
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsx
index 3e610442..e4b23f05 100644
--- a/desktop/src/App.tsx
+++ b/desktop/src/App.tsx
@@ -6,7 +6,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";
import { ContextMenu, type ContextTarget } from "./components/ContextMenu";
import { ExportDialog } from "./components/ExportDialog";
import { Icon } from "./components/Icon";
-import { MediaBin, type BinTab } from "./components/MediaBin";
+import { ALL_MEDIA, MediaBin, type BinFilter } from "./components/MediaBin";
import { Preview, type PreviewSource } from "./components/Preview";
import { Resizer } from "./components/Resizer";
import { RightPanel, type RightTab } from "./components/RightPanel";
@@ -15,7 +15,13 @@ import { TitleBar } from "./components/TitleBar";
import { TimelinePanel, resolveDrop, type Tool } from "./components/TimelinePanel";
import { createAssets, requestAssets } from "./lib/assets";
import { AudioPreview } from "./lib/audio";
-import { engineVersion, probeMedia, type ExportClip } from "./lib/engine";
+import {
+ engineVersion,
+ loadProject,
+ probeMedia,
+ saveProject,
+ type ExportClip,
+} from "./lib/engine";
import {
addClip,
addMedia,
@@ -35,6 +41,7 @@ import {
removeClips,
removeTrack,
renameTrack,
+ setClipSpeed,
setTrackFlag,
snapTime,
splitClip,
@@ -47,6 +54,7 @@ import {
type Project,
} from "./lib/project";
import { buildChain, chainKey } from "./lib/filters";
+import { fromDocument, toDocument } from "./lib/persist";
import { useTheme, type Theme } from "./lib/theme";
import { useTransport } from "./lib/transport";
@@ -116,7 +124,7 @@ function Editor({
const [selectedMediaId, setSelectedMediaId] = useState<string | null>(null);
const [tool, setTool] = useState<Tool>("select");
const [snap, setSnap] = useState(true);
- const [tab, setTab] = useState<BinTab>("media");
+ const [binFilter, setBinFilter] = useState<BinFilter>(ALL_MEDIA);
const [version, setVersion] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -127,6 +135,9 @@ function Editor({
);
const [exporting, setExporting] = useState(false);
const [rightTab, setRightTab] = useState<RightTab>("details");
+ const [saveState, setSaveState] = useState<"idle" | "saving" | "saved" | "failed">("idle");
+ /** Blocks autosave until the project on disk has been read in. */
+ const [loaded, setLoaded] = useState(false);
// Panel geometry.
const [leftWidth, setLeftWidth] = useState(340);
@@ -153,6 +164,42 @@ function Editor({
// changes meaning when you import a 25fps file is worse than useless.
const frameRate = session.frameRate;
+ // Load the saved timeline before anything can autosave over it.
+ useEffect(() => {
+ let cancelled = false;
+ void loadProject(session.path)
+ .then((document) => {
+ const restored = fromDocument(document);
+ if (!cancelled && restored) setProject(restored);
+ })
+ .catch(() => undefined)
+ .finally(() => {
+ if (!cancelled) setLoaded(true);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [session.path]);
+
+ const save = useCallback(async () => {
+ setSaveState("saving");
+ try {
+ await saveProject(session.path, toDocument(session, latest.current.project));
+ setSaveState("saved");
+ } catch (cause) {
+ setSaveState("failed");
+ setError(String(cause));
+ }
+ }, [session]);
+
+ // Autosave, debounced. The edit is the thing people lose; making them
+ // remember a keystroke to keep it is a design decision nobody wants.
+ useEffect(() => {
+ if (!loaded) return;
+ const timer = window.setTimeout(() => void save(), 1500);
+ return () => clearTimeout(timer);
+ }, [project, loaded, save]);
+
useEffect(() => {
engineVersion()
.then(setVersion)
@@ -227,7 +274,11 @@ function Editor({
{
clipId: clip.id,
path: media.path,
- time: clip.sourceStart + (playhead - clip.start),
+ // Source advances at `speed`, so the same playhead maps further
+ // into the file on a sped-up clip.
+ time: clip.sourceStart + (playhead - clip.start) * clip.speed,
+ speed: clip.speed,
+ preservePitch: clip.preservePitch,
// A filtered clip plays a render of itself, produced by the same
// ffmpeg chain the exporter will use.
filter: chainFor(clip),
@@ -403,6 +454,36 @@ function Editor({
// Never steal keys from a text field.
if (event.target instanceof HTMLInputElement) return;
+ /*
+ * Modified shortcuts are handled separately and then we return.
+ *
+ * Without this the two sets ran together: Ctrl+S matched the bare `S`
+ * case and split the clip instead of saving, which is exactly the sort
+ * of thing that makes an app feel hostile.
+ */
+ if (event.ctrlKey || event.metaKey) {
+ switch (event.code) {
+ case "KeyS":
+ event.preventDefault();
+ void save();
+ break;
+ case "KeyB":
+ event.preventDefault();
+ splitAtPlayhead();
+ break;
+ case "KeyE":
+ event.preventDefault();
+ setExporting(true);
+ break;
+ default:
+ break;
+ }
+ return;
+ }
+
+ // Alt is left alone entirely; nothing here claims it.
+ if (event.altKey) return;
+
const step = event.shiftKey ? 10 : 1;
switch (event.code) {
case "Space":
@@ -447,7 +528,7 @@ function Editor({
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
- }, [deleteSelected, duration, frameRate, mergeSelected, splitAtPlayhead, transport]);
+ }, [deleteSelected, duration, frameRate, mergeSelected, save, splitAtPlayhead, transport]);
// Filters are rendered per clip, keyed so that returning a slider to a value
// you already heard reuses the render instead of producing it again.
@@ -486,6 +567,8 @@ function Editor({
fadeIn: clip.fadeIn,
fadeOut: clip.fadeOut,
filterChain: buildChain(clip.filters) ?? "",
+ speed: clip.speed,
+ preservePitch: clip.preservePitch,
},
];
}),
@@ -506,7 +589,17 @@ function Editor({
<div className="flex h-full flex-col overflow-hidden">
<TitleBar
projectName={session.name}
- status={version ? `engine ${version}` : undefined}
+ status={
+ saveState === "saving"
+ ? "saving..."
+ : saveState === "failed"
+ ? "save failed"
+ : saveState === "saved"
+ ? "saved"
+ : version
+ ? `engine ${version}`
+ : undefined
+ }
theme={theme}
onToggleTheme={onToggleTheme}
actions={
@@ -531,6 +624,12 @@ function Editor({
disabled: !selectedMediaId,
onSelect: () => selectedMediaId && addToTimeline(selectedMediaId),
},
+ {
+ label: "Save",
+ icon: "folder",
+ hint: "Ctrl+S",
+ onSelect: () => void save(),
+ },
{
label: "Export...",
icon: "export",
@@ -557,7 +656,7 @@ function Editor({
label: "Edit",
groups: [
[
- { label: "Split at playhead", icon: "razor", hint: "S", onSelect: splitAtPlayhead },
+ { label: "Split at playhead", icon: "razor", hint: "Ctrl+B", onSelect: splitAtPlayhead },
{
label:
selectedClipIds.length > 1
@@ -613,16 +712,16 @@ function Editor({
items={project.media}
assets={assets.current}
dropping={dropping}
- tab={tab}
+ filter={binFilter}
selectedId={selectedMediaId}
busy={busy}
error={error}
- onTab={setTab}
+ onFilter={setBinFilter}
onSelect={(id) => {
setSelectedMediaId(id);
setSelectedClipIds([]);
}}
- onImport={(path) => void importPaths([path])}
+ onImport={(paths) => void importPaths(paths)}
onRemove={(id) =>
setProject((current) => ({
...current,
@@ -675,6 +774,10 @@ function Editor({
if (selectedClipIds.length !== 1) return;
setProject((current) => updateClip(current, selectedClipIds[0], patch));
}}
+ onSpeedChange={(speed) => {
+ if (selectedClipIds.length !== 1) return;
+ setProject((current) => setClipSpeed(current, selectedClipIds[0], speed));
+ }}
/>
</div>
</div>
diff --git a/desktop/src/components/AdjustPanel.tsx b/desktop/src/components/AdjustPanel.tsx
index 5e626cb3..07240869 100644
--- a/desktop/src/components/AdjustPanel.tsx
+++ b/desktop/src/components/AdjustPanel.tsx
@@ -1,5 +1,5 @@
import type { Clip } from "../lib/project";
-import { Group, Slider } from "./controls";
+import { Group, Slider, Toggle } from "./controls";
import { Icon } from "./Icon";
import { Empty } from "./Panel";
@@ -48,9 +48,12 @@ function formatDecibels(decibels: number): string {
export function AdjustPanel({
clip,
onChange,
+ onSpeedChange,
}: {
clip: Clip | null;
onChange: (patch: Partial<Clip>) => void;
+ /** Separate, because changing speed also rescales the clip's duration. */
+ onSpeedChange: (speed: number) => void;
}) {
if (!clip) {
return (
@@ -86,6 +89,31 @@ export function AdjustPanel({
/>
</Group>
+ {clip.kind === "audio" && (
+ <Group title="Speed">
+ <Slider
+ label="Rate"
+ value={clip.speed}
+ min={0.25}
+ max={4}
+ step={0.05}
+ format={(value) => `${value.toFixed(2)}x`}
+ onReset={() => onSpeedChange(1)}
+ onChange={onSpeedChange}
+ />
+ <Toggle
+ label="Change pitch with speed"
+ hint="Off keeps the voice where it is. On is tape behaviour - faster also means higher."
+ checked={!clip.preservePitch}
+ onChange={(checked) => onChange({ preservePitch: !checked })}
+ />
+ <p className="-mt-1 mb-1 text-[11px] leading-snug text-tertiary">
+ The clip covers the same audio either way, so its length on the timeline
+ changes to match.
+ </p>
+ </Group>
+ )}
+
<Group title="Fades">
<Slider
label="Fade in"
diff --git a/desktop/src/components/Icon.tsx b/desktop/src/components/Icon.tsx
index 04a738f3..de58aef3 100644
--- a/desktop/src/components/Icon.tsx
+++ b/desktop/src/components/Icon.tsx
@@ -216,6 +216,7 @@ const GLYPHS = {
</>
),
moon: <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />,
+ check: <path d="m4 12.5 5 5 11-11" />,
chevronDown: <path d="m6 9 6 6 6-6" />,
chevronRight: <path d="m9 6 6 6-6 6" />,
search: (
diff --git a/desktop/src/components/Inspector.tsx b/desktop/src/components/Inspector.tsx
index e1396756..08f172f8 100644
--- a/desktop/src/components/Inspector.tsx
+++ b/desktop/src/components/Inspector.tsx
@@ -29,7 +29,7 @@ export function Inspector({
Select a clip or a bin item.
</Empty>
) : (
- <div className="px-3 py-2">
+ <div className="selectable px-3 py-2">
{clip && (
<Section title="Clip">
<Row label="Name" value={clip.name} />
diff --git a/desktop/src/components/MediaBin.tsx b/desktop/src/components/MediaBin.tsx
index 83d3e8de..a1643c35 100644
--- a/desktop/src/components/MediaBin.tsx
+++ b/desktop/src/components/MediaBin.tsx
@@ -1,15 +1,24 @@
import { useEffect, useRef, useState } from "react";
-import type { PointerEvent as ReactPointerEvent, ReactNode } from "react";
+import { open } from "@tauri-apps/plugin-dialog";
+import type { PointerEvent as ReactPointerEvent } from "react";
import type { MediaAssets } from "../lib/assets";
import { subscribeAssets } from "../lib/assets";
import type { MediaItem } from "../lib/project";
import { themeColor } from "../lib/theme";
import { shortDuration } from "../lib/time";
-import { Icon, IconButton } from "./Icon";
+import { Icon } from "./Icon";
+import { Menu } from "./Menu";
import { Empty, Panel } from "./Panel";
-export type BinTab = "media" | "audio";
+/** Which kinds of media the bin is showing. */
+export interface BinFilter {
+ video: boolean;
+ audio: boolean;
+ image: boolean;
+}
+
+export const ALL_MEDIA: BinFilter = { video: true, audio: true, image: true };
/**
* The media bin.
@@ -21,11 +30,11 @@ export type BinTab = "media" | "audio";
*/
export function MediaBin({
items,
- tab,
+ filter,
selectedId,
busy,
error,
- onTab,
+ onFilter,
onSelect,
onImport,
onRemove,
@@ -36,7 +45,7 @@ export function MediaBin({
dropping,
}: {
items: MediaItem[];
- tab: BinTab;
+ filter: BinFilter;
/** A file is being dragged over the window from outside. */
dropping: boolean;
/** Shared with the timeline, so a waveform is only ever computed once. */
@@ -44,16 +53,37 @@ export function MediaBin({
selectedId: string | null;
busy: boolean;
error: string | null;
- onTab: (tab: BinTab) => void;
+ onFilter: (filter: BinFilter) => void;
onSelect: (id: string) => void;
- onImport: (path: string) => void;
+ onImport: (paths: string[]) => void;
onRemove: (id: string) => void;
onDismissError: () => void;
/** Called once the pointer has moved far enough to count as a drag. */
onBeginDrag: (item: MediaItem, clientX: number, clientY: number) => void;
onAddToTimeline: (mediaId: string) => void;
}) {
- const [path, setPath] = useState("");
+ const browse = async () => {
+ if (busy) return;
+ const chosen = await open({
+ multiple: true,
+ title: "Import media",
+ filters: [
+ {
+ name: "Media",
+ extensions: [
+ "mp4", "mov", "mkv", "webm", "avi", "m4v",
+ "mp3", "wav", "flac", "aac", "m4a", "ogg", "opus",
+ "png", "jpg", "jpeg", "webp", "bmp", "tif", "tiff", "avif", "gif",
+ ],
+ },
+ { name: "All files", extensions: ["*"] },
+ ],
+ });
+
+ // The picker hands back a string for one file and an array for many.
+ if (Array.isArray(chosen)) onImport(chosen);
+ else if (typeof chosen === "string") onImport([chosen]);
+ };
/**
* Starts a drag using raw pointer events rather than HTML5 drag-and-drop.
@@ -85,20 +115,11 @@ export function MediaBin({
window.addEventListener("pointerup", cleanup);
};
- const visible = items.filter((item) => (tab === "audio" ? item.kind === "audio" : true));
-
- const submit = () => {
- // Windows' "Copy as path" wraps the path in quotes, and pasting that
- // straight in is the single most likely first action.
- const trimmed = path.trim().replace(/^"|"$/g, "");
- if (!trimmed || busy) return;
- onImport(trimmed);
- setPath("");
- };
+ const visible = items.filter((item) => filter[item.kind]);
return (
<Panel
- title={tab === "audio" ? "Audio" : "Media"}
+ title="Media"
// Dropped files land in the bin, so the bin is what lights up. A
// full-screen overlay would obscure the editor to say something that
// only concerns one panel.
@@ -109,33 +130,48 @@ export function MediaBin({
</span>
}
>
- <div className="flex gap-0.5 px-2 pb-2 pt-2">
- <TabButton active={tab === "media"} onClick={() => onTab("media")} icon="folder">
- All
- </TabButton>
- <TabButton active={tab === "audio"} onClick={() => onTab("audio")} icon="music">
- Audio
- </TabButton>
+ <div className="px-2 pb-2 pt-2">
+ <Menu
+ groups={[
+ (["video", "audio", "image"] as const).map((kind) => ({
+ label: KIND_LABELS[kind],
+ checked: filter[kind],
+ // Turning the last one off would leave a bin that shows nothing
+ // and gives no hint why, so the final kind stays on.
+ onSelect: () => {
+ const next = { ...filter, [kind]: !filter[kind] };
+ if (next.video || next.audio || next.image) onFilter(next);
+ },
+ })),
+ ]}
+ trigger={(open) => (
+ <span
+ className={`flex w-full items-center gap-1.5 rounded-lg px-2 py-1.5 text-xs
+ transition-colors ${
+ open ? "bg-active text-primary" : "text-secondary hover:bg-hover"
+ }`}
+ >
+ <Icon name="search" size={13} />
+ <span className="min-w-0 flex-1 truncate text-left">{summarise(filter)}</span>
+ <Icon name="chevronDown" size={12} />
+ </span>
+ )}
+ />
</div>
- <div className="flex gap-1.5 px-2 pb-2">
- <input
- value={path}
- onChange={(event) => setPath(event.target.value)}
- onKeyDown={(event) => event.key === "Enter" && submit()}
- placeholder="Paste a file path"
- spellCheck={false}
- className="min-w-0 flex-1 rounded-lg border border-hairline bg-sunken px-2 py-1.5
- text-xs text-primary placeholder:text-tertiary
- focus:border-accent focus:outline-none"
- />
- <IconButton
- icon="plus"
- label="Add media"
- size={7}
- onClick={submit}
- disabled={busy || path.trim() === ""}
- />
+ <div className="px-2 pb-2">
+ <button
+ type="button"
+ onClick={() => void browse()}
+ disabled={busy}
+ className="flex w-full cursor-pointer items-center justify-center gap-2 rounded-lg
+ border border-dashed border-hairline-strong px-3 py-2.5 text-xs text-secondary
+ transition-colors hover:border-accent hover:bg-hover hover:text-primary
+ disabled:cursor-not-allowed disabled:opacity-40"
+ >
+ <Icon name="import" size={14} />
+ {busy ? "Importing..." : "Import media"}
+ </button>
</div>
{error && (
@@ -170,49 +206,60 @@ export function MediaBin({
: "Drop video and audio files anywhere in the window, or paste a path above."}
</Empty>
) : (
- <ul className="flex flex-col gap-0.5 px-2 pb-2">
+ <ul className="grid grid-cols-2 gap-2 px-2 pb-2">
{visible.map((item) => (
<li
key={item.id}
onPointerDown={(event) => beginDrag(event, item)}
onClick={() => onSelect(item.id)}
onDoubleClick={() => onAddToTimeline(item.id)}
- title="Drag onto a track, or double-click to add at the playhead"
- className={`group flex cursor-grab select-none items-center gap-2.5 rounded-lg px-2 py-2
- transition-colors active:cursor-grabbing ${
- item.id === selectedId
- ? "bg-accent-soft ring-1 ring-accent"
- : "hover:bg-hover"
- }`}
+ // The details that used to sit on a second line live here now.
+ // They are worth having, but not worth a permanent row each.
+ title={`${item.name}
+${describe(item)}
+Drag onto a track, or double-click to add at the playhead`}
+ className="group cursor-grab select-none active:cursor-grabbing"
>
- <MediaThumb item={item} assets={assets} />
-
- <span className="min-w-0 flex-1">
- <span className="block truncate text-xs text-primary">{item.name}</span>
- <span className="block truncate font-technical text-[10px] text-secondary">
- {item.kind === "audio"
- ? (item.audioCodec ?? "audio")
- : item.kind === "image"
- ? `${item.width}x${item.height} still`
- : `${item.width}x${item.height} · ${item.frameRate?.toFixed(2)} fps`}
- {" · "}
- {shortDuration(item.duration)}
+ <div
+ className={`relative overflow-hidden rounded-lg transition-shadow ${
+ item.id === selectedId
+ ? "ring-2 ring-accent"
+ : "ring-1 ring-hairline group-hover:ring-hairline-strong"
+ }`}
+ >
+ <MediaThumb item={item} assets={assets} />
+
+ <span className="pointer-events-none absolute left-1 top-1 flex h-5 w-5
+ items-center justify-center rounded bg-black/55 text-white">
+ <Icon
+ name={item.kind === "video" ? "film" : item.kind === "image" ? "image" : "music"}
+ size={11}
+ />
</span>
- </span>
- <button
- type="button"
- aria-label={`Remove ${item.name}`}
- title="Remove from bin"
- onClick={(event) => {
- event.stopPropagation();
- onRemove(item.id);
- }}
- className="hidden shrink-0 cursor-pointer rounded p-1 text-secondary
- hover:bg-active hover:text-primary group-hover:block"
- >
- <Icon name="close" size={12} />
- </button>
+ <span className="pointer-events-none absolute bottom-1 right-1 rounded bg-black/55
+ px-1 py-px font-technical text-[10px] text-white">
+ {item.kind === "image" ? "still" : shortDuration(item.duration)}
+ </span>
+
+ <button
+ type="button"
+ aria-label={`Remove ${item.name}`}
+ title="Remove from bin"
+ onClick={(event) => {
+ event.stopPropagation();
+ onRemove(item.id);
+ }}
+ className="invisible absolute right-1 top-1 cursor-pointer rounded bg-black/55 p-1
+ text-white transition-colors hover:bg-danger group-hover:visible"
+ >
+ <Icon name="close" size={10} />
+ </button>
+ </div>
+
+ <span className="mt-1 block truncate text-[11px] leading-tight text-secondary">
+ {item.name}
+ </span>
</li>
))}
</ul>
@@ -221,6 +268,21 @@ export function MediaBin({
);
}
+const KIND_LABELS = { video: "Video", audio: "Audio", image: "Images" } as const;
+
+/** "All media" when nothing is filtered out, otherwise what is showing. */
+function summarise(filter: BinFilter): string {
+ const on = (["video", "audio", "image"] as const).filter((kind) => filter[kind]);
+ return on.length === 3 ? "All media" : on.map((kind) => KIND_LABELS[kind]).join(", ");
+}
+
+/** The second line that used to be shown for every item, now on hover. */
+function describe(item: MediaItem): string {
+ if (item.kind === "audio") return item.audioCodec ?? "audio";
+ const size = `${item.width}x${item.height}`;
+ return item.kind === "image" ? `${size} still` : `${size} · ${item.frameRate?.toFixed(2)} fps`;
+}
+
/**
* The bin preview for one item.
*
@@ -328,29 +390,3 @@ function MediaThumb({ item, assets }: { item: MediaItem; assets: MediaAssets })
);
}
-function TabButton({
- active,
- onClick,
- icon,
- children,
-}: {
- active: boolean;
- onClick: () => void;
- icon: "folder" | "music";
- children: ReactNode;
-}) {
- return (
- <button
- type="button"
- onClick={onClick}
- aria-pressed={active}
- className={`flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-2 py-1.5
- text-xs transition-colors ${
- active ? "bg-accent text-on-accent" : "text-secondary hover:bg-hover"
- }`}
- >
- <Icon name={icon} size={13} />
- {children}
- </button>
- );
-}
diff --git a/desktop/src/components/Menu.tsx b/desktop/src/components/Menu.tsx
index 42e1f4c7..3aba2046 100644
--- a/desktop/src/components/Menu.tsx
+++ b/desktop/src/components/Menu.tsx
@@ -11,6 +11,13 @@ export interface MenuOption {
hint?: string;
disabled?: boolean;
danger?: boolean;
+ /**
+ * Renders as a checkable row when set.
+ *
+ * A checkable row does not close the menu, because the whole point of one is
+ * turning several things on and off in a row.
+ */
+ checked?: boolean;
}
/**
@@ -82,14 +89,20 @@ export function Menu({
disabled={option.disabled}
onClick={() => {
option.onSelect();
- setOpen(false);
+ if (option.checked === undefined) setOpen(false);
}}
className={`flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5
text-left text-xs transition-colors hover:bg-hover
disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent
${option.danger ? "text-danger" : ""}`}
>
- {option.icon ? (
+ {option.checked !== undefined ? (
+ <Icon
+ name="check"
+ size={14}
+ className={`shrink-0 ${option.checked ? "text-accent" : "opacity-0"}`}
+ />
+ ) : option.icon ? (
<Icon name={option.icon} size={14} className="shrink-0 opacity-70" />
) : (
<span className="w-3.5 shrink-0" />
diff --git a/desktop/src/components/RightPanel.tsx b/desktop/src/components/RightPanel.tsx
index 2f9bd21e..b7c477c6 100644
--- a/desktop/src/components/RightPanel.tsx
+++ b/desktop/src/components/RightPanel.tsx
@@ -28,6 +28,7 @@ export function RightPanel({
media,
frameRate,
onChangeClip,
+ onSpeedChange,
rendering,
}: {
tab: RightTab;
@@ -36,6 +37,7 @@ export function RightPanel({
media: MediaItem | null;
frameRate: number;
onChangeClip: (patch: Partial<Clip>) => void;
+ onSpeedChange: (speed: number) => void;
/** True while the selected clip's filtered audio is being rendered. */
rendering: boolean;
}) {
@@ -62,7 +64,9 @@ export function RightPanel({
</div>
{tab === "details" && <Inspector clip={clip} media={media} frameRate={frameRate} />}
- {tab === "adjust" && <AdjustPanel clip={clip} onChange={onChangeClip} />}
+ {tab === "adjust" && (
+ <AdjustPanel clip={clip} onChange={onChangeClip} onSpeedChange={onSpeedChange} />
+ )}
{tab === "filters" && (
<FiltersPanel
clip={clip}
diff --git a/desktop/src/components/TimelinePanel.tsx b/desktop/src/components/TimelinePanel.tsx
index c8945363..0b24f25d 100644
--- a/desktop/src/components/TimelinePanel.tsx
+++ b/desktop/src/components/TimelinePanel.tsx
@@ -707,7 +707,7 @@ export function TimelinePanel({
onClick={() => onToolChange("razor")}
/>
<Divider />
- <IconButton icon="split" label="Split at playhead (S)" onClick={onSplitAtPlayhead} />
+ <IconButton icon="split" label="Split at playhead (Ctrl+B)" onClick={onSplitAtPlayhead} />
<IconButton
icon="merge"
// The reason lives in the tooltip: a button that greys out without
diff --git a/desktop/src/components/controls.tsx b/desktop/src/components/controls.tsx
index 46072841..c6a92c3b 100644
--- a/desktop/src/components/controls.tsx
+++ b/desktop/src/components/controls.tsx
@@ -102,6 +102,60 @@ export function Slider({
);
}
+/**
+ * A sliding on/off switch.
+ *
+ * A real `<button role="switch">` rather than a native checkbox: the platform
+ * control cannot be styled into this shape, and it looks like a form field
+ * dropped into a tool that has none. Being a button means keyboard and screen
+ * reader behaviour come for free, which a restyled `<div>` would have thrown
+ * away.
+ *
+ * The knob subtracts its own width as it travels so it stays inside the track
+ * at both ends - the same trick the Slider knob uses.
+ */
+export function Toggle({
+ label,
+ hint,
+ checked,
+ onChange,
+}: {
+ label: string;
+ hint?: string;
+ checked: boolean;
+ onChange: (checked: boolean) => void;
+}) {
+ return (
+ <div className="mb-3 flex items-start justify-between gap-3">
+ <span className="min-w-0">
+ <span className="block text-[12px] text-primary">{label}</span>
+ {hint && (
+ <span className="mt-0.5 block text-[11px] leading-snug text-tertiary">{hint}</span>
+ )}
+ </span>
+
+ <button
+ type="button"
+ role="switch"
+ aria-checked={checked}
+ aria-label={label}
+ onClick={() => onChange(!checked)}
+ className={`relative mt-0.5 h-[22px] w-[38px] shrink-0 cursor-pointer rounded-full
+ p-[3px] transition-colors duration-200 ${
+ checked ? "bg-accent" : "bg-tertiary/40"
+ }`}
+ >
+ <span
+ className={`block h-4 w-4 rounded-full bg-white shadow-[0_1px_2px_rgba(0,0,0,0.3)]
+ transition-transform duration-200 ${
+ checked ? "translate-x-4" : "translate-x-0"
+ }`}
+ />
+ </button>
+ </div>
+ );
+}
+
/** A labelled group of controls. */
export function Group({ title, children }: { title: string; children: React.ReactNode }) {
return (
diff --git a/desktop/src/lib/audio.ts b/desktop/src/lib/audio.ts
index e6a32419..4a81abd7 100644
--- a/desktop/src/lib/audio.ts
+++ b/desktop/src/lib/audio.ts
@@ -33,6 +33,10 @@ export interface Voice {
time: number;
/** Linear gain, fades already applied. May exceed 1. */
volume: number;
+ /** Playback rate. */
+ speed: number;
+ /** False lets pitch rise with speed, like tape. */
+ preservePitch: boolean;
/**
* A filtered render of this clip, when it has filters.
*
@@ -155,6 +159,11 @@ export class AudioPreview {
// No clamp. A boost is meant to be audible.
loaded.gain.gain.value = Math.max(0, voice.volume);
+ // `preservesPitch` is exactly the toggle: on, the browser time-stretches
+ // and the voice stays put; off, it resamples and pitch rides the rate.
+ element.playbackRate = Math.max(0.0625, Math.min(16, voice.speed));
+ element.preservesPitch = voice.preservePitch;
+
// A filtered render starts at the clip's in-point, so the same instant
// sits at a different offset inside it than in the original file.
const target = Math.max(0, voice.time - loaded.offset);
diff --git a/desktop/src/lib/engine.ts b/desktop/src/lib/engine.ts
index e50bdd85..631e7e20 100644
--- a/desktop/src/lib/engine.ts
+++ b/desktop/src/lib/engine.ts
@@ -109,6 +109,16 @@ export async function openProject(path: string): Promise<ProjectInfo> {
return invoke<ProjectInfo>("open_project", { path });
}
+/** Writes the whole project document to the project folder. */
+export async function saveProject(path: string, document: unknown): Promise<void> {
+ return invoke<void>("save_project", { path, document });
+}
+
+/** Reads the whole project document back. */
+export async function loadProject(path: string): Promise<unknown> {
+ return invoke<unknown>("load_project", { path });
+}
+
/** Recently opened projects, newest first, with vanished folders left out. */
export async function recentProjects(): Promise<ProjectInfo[]> {
return invoke<ProjectInfo[]>("recent_projects");
diff --git a/desktop/src/lib/persist.ts b/desktop/src/lib/persist.ts
new file mode 100644
index 00000000..ba326ba2
--- /dev/null
+++ b/desktop/src/lib/persist.ts
@@ -0,0 +1,170 @@
+/**
+ * Reading and writing the project document.
+ *
+ * The document is the file on disk. It is deliberately *not* the same shape as
+ * the in-memory `Project`: loading fills in anything a file predates, so a
+ * project saved before a feature existed still opens instead of arriving with
+ * `undefined` where a number should be.
+ *
+ * That tolerance is the whole job of this module. Everything else is a
+ * one-to-one copy.
+ */
+
+import type { ProjectSession } from "../components/StartScreen";
+import type { Clip, MediaItem, Project, Track } from "./project";
+
+/** Bumped only when a change cannot be absorbed by defaulting. */
+const DOCUMENT_VERSION = 1;
+
+export interface ProjectDocument {
+ relay: string;
+ version: number;
+ name: string;
+ video: { width: number; height: number; rateNum: number; rateDen: number };
+ media: MediaItem[];
+ tracks: Track[];
+ clips: Clip[];
+}
+
+export function toDocument(session: ProjectSession, project: Project): ProjectDocument {
+ return {
+ relay: "0.1.0",
+ version: DOCUMENT_VERSION,
+ name: session.name,
+ video: {
+ width: session.width,
+ height: session.height,
+ rateNum: session.rateNum,
+ rateDen: session.rateDen,
+ },
+ media: project.media,
+ tracks: project.tracks,
+ clips: project.clips,
+ };
+}
+
+const number = (value: unknown, fallback: number): number =>
+ typeof value === "number" && Number.isFinite(value) ? value : fallback;
+
+const text = (value: unknown, fallback: string): string =>
+ typeof value === "string" ? value : fallback;
+
+const flag = (value: unknown, fallback: boolean): boolean =>
+ typeof value === "boolean" ? value : fallback;
+
+/**
+ * Rebuilds a project from a document.
+ *
+ * Every field is defaulted rather than trusted. A hand-edited or older file
+ * should degrade to something openable, not produce a timeline full of `NaN`
+ * that fails somewhere far away from the cause.
+ *
+ * Returns null only when there is nothing recognisable to load at all.
+ */
+export function fromDocument(raw: unknown): Project | null {
+ if (typeof raw !== "object" || raw === null) return null;
+ const document = raw as Record<string, unknown>;
+
+ const media: MediaItem[] = Array.isArray(document.media)
+ ? document.media.flatMap((entry) => {
+ if (typeof entry !== "object" || entry === null) return [];
+ const item = entry as Record<string, unknown>;
+ if (typeof item.id !== "string" || typeof item.path !== "string") return [];
+
+ const kind = item.kind === "audio" || item.kind === "image" ? item.kind : "video";
+ return [
+ {
+ id: item.id,
+ path: item.path,
+ name: text(item.name, item.path),
+ duration: typeof item.duration === "number" ? item.duration : null,
+ kind,
+ width: typeof item.width === "number" ? item.width : null,
+ height: typeof item.height === "number" ? item.height : null,
+ frameRate: typeof item.frameRate === "number" ? item.frameRate : null,
+ frameRateFraction:
+ typeof item.frameRateFraction === "string" ? item.frameRateFraction : null,
+ videoCodec: typeof item.videoCodec === "string" ? item.videoCodec : null,
+ audioCodec: typeof item.audioCodec === "string" ? item.audioCodec : null,
+ hasAudio: flag(item.hasAudio, false),
+ },
+ ];
+ })
+ : [];
+
+ const tracks: Track[] = Array.isArray(document.tracks)
+ ? document.tracks.flatMap((entry) => {
+ if (typeof entry !== "object" || entry === null) return [];
+ const track = entry as Record<string, unknown>;
+ if (typeof track.id !== "string") return [];
+ return [
+ {
+ id: track.id,
+ name: text(track.name, track.id),
+ visible: flag(track.visible, true),
+ muted: flag(track.muted, false),
+ },
+ ];
+ })
+ : [];
+
+ const known = new Set(tracks.map((track) => track.id));
+ const mediaIds = new Set(media.map((item) => item.id));
+
+ const clips: Clip[] = Array.isArray(document.clips)
+ ? document.clips.flatMap((entry) => {
+ if (typeof entry !== "object" || entry === null) return [];
+ const clip = entry as Record<string, unknown>;
+ if (typeof clip.id !== "string") return [];
+
+ // A clip whose track or media vanished has nowhere to live and nothing
+ // to play. Dropping it beats keeping a reference that resolves to
+ // nothing everywhere it is used.
+ if (typeof clip.trackId !== "string" || !known.has(clip.trackId)) return [];
+ if (typeof clip.mediaId !== "string" || !mediaIds.has(clip.mediaId)) return [];
+
+ const kind = clip.kind === "audio" || clip.kind === "image" ? clip.kind : "video";
+ return [
+ {
+ id: clip.id,
+ trackId: clip.trackId,
+ mediaId: clip.mediaId,
+ name: text(clip.name, "clip"),
+ kind,
+ start: Math.max(0, number(clip.start, 0)),
+ duration: Math.max(0.01, number(clip.duration, 1)),
+ sourceStart: Math.max(0, number(clip.sourceStart, 0)),
+ volume: Math.max(0, number(clip.volume, 1)),
+ fadeIn: Math.max(0, number(clip.fadeIn, 0)),
+ fadeOut: Math.max(0, number(clip.fadeOut, 0)),
+ scale: Math.max(0.05, number(clip.scale, 1)),
+ offsetX: number(clip.offsetX, 0),
+ offsetY: number(clip.offsetY, 0),
+ speed: Math.max(0.1, number(clip.speed, 1)),
+ preservePitch: flag(clip.preservePitch, true),
+ filters: Array.isArray(clip.filters)
+ ? clip.filters.flatMap((filter) => {
+ if (typeof filter !== "object" || filter === null) return [];
+ const applied = filter as Record<string, unknown>;
+ if (typeof applied.id !== "string") return [];
+ return [
+ {
+ id: applied.id,
+ params:
+ typeof applied.params === "object" && applied.params !== null
+ ? (applied.params as Record<string, number>)
+ : {},
+ },
+ ];
+ })
+ : [],
+ },
+ ];
+ })
+ : [];
+
+ // A file with no tracks at all is not something to open silently as empty.
+ if (tracks.length === 0) return null;
+
+ return { media, tracks, clips };
+}
diff --git a/desktop/src/lib/project.ts b/desktop/src/lib/project.ts
index bacaa9f9..aa6a8f92 100644
--- a/desktop/src/lib/project.ts
+++ b/desktop/src/lib/project.ts
@@ -97,6 +97,36 @@ export interface Clip {
/** Fade-out length in seconds. Zero means no fade. */
fadeOut: number;
+ /**
+ * How big the picture is drawn, where 1 fills the frame.
+ *
+ * "Fills the frame" means the size the clip would be with no transform at
+ * all - fitted to the project's frame, preserving its aspect. Everything is
+ * relative to that, so a transform means the same thing on a 4K clip and a
+ * 720p one.
+ */
+ scale: number;
+ /** Offset from centred, as a fraction of frame width. */
+ offsetX: number;
+ /** Offset from centred, as a fraction of frame height. */
+ offsetY: number;
+
+ /**
+ * Playback rate. 1 is normal, 2 is twice as fast.
+ *
+ * Changing it rescales the clip's timeline duration, because the same span
+ * of source now takes a different amount of time to play. That is what every
+ * editor does and what people expect from a speed control.
+ */
+ speed: number;
+ /**
+ * Whether pitch stays put when the speed changes.
+ *
+ * True is the modern default - time-stretching that leaves the voice where
+ * it was. False is the tape behaviour, where faster also means higher.
+ */
+ preservePitch: boolean;
+
/**
* Audio filters, applied in order.
*
@@ -217,6 +247,11 @@ export function addClip(
volume: 1,
fadeIn: 0,
fadeOut: 0,
+ scale: 1,
+ offsetX: 0,
+ offsetY: 0,
+ speed: 1,
+ preservePitch: true,
filters: [],
};
@@ -521,6 +556,49 @@ export function mergeClips(
};
}
+/**
+ * Changes a clip's speed, rescaling its duration to match.
+ *
+ * The amount of *source* the clip covers is held constant - that is what makes
+ * this a speed change rather than a trim. Playing the same material twice as
+ * fast means occupying half as much timeline.
+ */
+export function setClipSpeed(project: Project, clipId: string, speed: number): Project {
+ const clip = findClip(project, clipId);
+ if (!clip) return project;
+
+ const next = Math.max(0.1, Math.min(8, speed));
+ const sourceCovered = clip.duration * clip.speed;
+
+ return updateClip(project, clipId, {
+ speed: next,
+ duration: Math.max(MIN_CLIP_DURATION, sourceCovered / next),
+ });
+}
+
+/** Limits, so a clip cannot be scaled or dragged out of reach. */
+export const MIN_SCALE = 0.05;
+export const MAX_SCALE = 8;
+const MAX_OFFSET = 3;
+
+/** Moves and resizes a clip's picture, clamped to something recoverable. */
+export function setClipTransform(
+ project: Project,
+ clipId: string,
+ transform: Partial<Pick<Clip, "scale" | "offsetX" | "offsetY">>,
+): Project {
+ const clamp = (value: number, limit: number) => Math.max(-limit, Math.min(limit, value));
+
+ const patch: Partial<Clip> = {};
+ if (transform.scale !== undefined) {
+ patch.scale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, transform.scale));
+ }
+ if (transform.offsetX !== undefined) patch.offsetX = clamp(transform.offsetX, MAX_OFFSET);
+ if (transform.offsetY !== undefined) patch.offsetY = clamp(transform.offsetY, MAX_OFFSET);
+
+ return updateClip(project, clipId, patch);
+}
+
export function setTrackFlag(
project: Project,
trackId: string,
diff --git a/desktop/src/lib/text.ts b/desktop/src/lib/text.ts
new file mode 100644
index 00000000..0b02ba2b
--- /dev/null
+++ b/desktop/src/lib/text.ts
@@ -0,0 +1,122 @@
+/**
+ * Text overlays.
+ *
+ * A text clip has no media file behind it - it *is* its own content - which is
+ * why the style lives on the clip rather than in the bin. Everything is stored
+ * relative to the frame rather than in pixels, so a title composed against a
+ * 1080p project still lands correctly when exported at 4K.
+ */
+
+export interface TextStyle {
+ content: string;
+ /** CSS family name. See `FONTS`. */
+ fontFamily: string;
+ /**
+ * Cap height as a fraction of frame height.
+ *
+ * Relative, not points: a 48pt title means something different on a 720p
+ * frame than a 4K one, and the project can be either.
+ */
+ fontSize: number;
+ fontWeight: number;
+ italic: boolean;
+ color: string;
+ align: "left" | "center" | "right";
+ /** 0..1. */
+ opacity: number;
+ /** Outline width as a fraction of the font size. Zero for none. */
+ strokeWidth: number;
+ strokeColor: string;
+ /** A soft drop shadow, which is what makes text readable over footage. */
+ shadow: boolean;
+ /** A solid plate behind the text. Empty string for none. */
+ background: string;
+ /** Extra space between lines, as a multiple of the font size. */
+ lineHeight: number;
+ /** Letter spacing as a fraction of the font size. */
+ tracking: number;
+}
+
+/**
+ * The fonts on offer.
+ *
+ * The two bundled faces are guaranteed - they ship with the app, so a project
+ * opened on another machine looks the same. The system families below them are
+ * a convenience and may fall back to something else elsewhere, which is why
+ * they are grouped separately in the picker.
+ */
+export const FONTS: { label: string; value: string; bundled: boolean }[] = [
+ { label: "Cabinet Grotesk", value: '"Cabinet Grotesk"', bundled: true },
+ { label: "Synonym", value: '"Synonym"', bundled: true },
+ { label: "System sans", value: "system-ui, sans-serif", bundled: false },
+ { label: "Georgia", value: "Georgia, serif", bundled: false },
+ { label: "Times", value: '"Times New Roman", serif', bundled: false },
+ { label: "Courier", value: '"Courier New", monospace', bundled: false },
+ { label: "Impact", value: "Impact, sans-serif", bundled: false },
+ { label: "Comic Sans", value: '"Comic Sans MS", cursive', bundled: false },
+];
+
+export const WEIGHTS: { label: string; value: number }[] = [
+ { label: "Light", value: 300 },
+ { label: "Regular", value: 400 },
+ { label: "Medium", value: 500 },
+ { label: "Bold", value: 700 },
+ { label: "Black", value: 900 },
+];
+
+export function defaultTextStyle(): TextStyle {
+ return {
+ content: "Your text",
+ fontFamily: '"Cabinet Grotesk"',
+ // Roughly a tenth of the frame: big enough to read on a phone, small
+ // enough not to fill the screen before anyone has touched it.
+ fontSize: 0.09,
+ fontWeight: 700,
+ italic: false,
+ color: "#ffffff",
+ align: "center",
+ opacity: 1,
+ strokeWidth: 0,
+ strokeColor: "#000000",
+ shadow: true,
+ background: "",
+ lineHeight: 1.2,
+ tracking: 0,
+ };
+}
+
+/**
+ * The CSS for one text clip, given the height of the surface it is drawn on.
+ *
+ * Shared by the preview overlay and the export rasteriser, so a title cannot
+ * look one way on screen and another in the file.
+ */
+export function textCss(style: TextStyle, surfaceHeight: number): React.CSSProperties {
+ const size = style.fontSize * surfaceHeight;
+
+ const shadow = style.shadow
+ ? `0 ${(size * 0.04).toFixed(2)}px ${(size * 0.12).toFixed(2)}px rgba(0,0,0,0.55)`
+ : undefined;
+
+ return {
+ fontFamily: style.fontFamily,
+ fontSize: `${size}px`,
+ fontWeight: style.fontWeight,
+ fontStyle: style.italic ? "italic" : "normal",
+ color: style.color,
+ textAlign: style.align,
+ opacity: style.opacity,
+ lineHeight: style.lineHeight,
+ letterSpacing: `${style.tracking * size}px`,
+ textShadow: shadow,
+ // `paint-order` puts the stroke behind the fill, so an outline thickens
+ // outwards instead of eating into the letterforms.
+ WebkitTextStrokeWidth: style.strokeWidth > 0 ? `${style.strokeWidth * size}px` : undefined,
+ WebkitTextStrokeColor: style.strokeColor,
+ paintOrder: "stroke fill",
+ backgroundColor: style.background || undefined,
+ padding: style.background ? `${size * 0.2}px ${size * 0.35}px` : undefined,
+ borderRadius: style.background ? `${size * 0.12}px` : undefined,
+ whiteSpace: "pre-wrap",
+ };
+}
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsx
index bc3c1b39..cef35101 100644
--- a/desktop/src/main.tsx
+++ b/desktop/src/main.tsx
@@ -4,6 +4,22 @@ import ReactDOM from "react-dom/client";
import { App } from "./App";
import "./styles.css";
+/*
+ * The webview's own context menu has no place in a desktop app - it offers
+ * Reload, View Source and Inspect, none of which mean anything here, and it
+ * appears instead of whatever menu the app wanted to show.
+ *
+ * Suppressed at the document, so a component only has to call
+ * `preventDefault` where it wants its *own* menu. Inputs keep theirs, because
+ * cut/copy/paste in a text field is genuinely useful and there is no custom
+ * replacement for it.
+ */
+document.addEventListener("contextmenu", (event) => {
+ const target = event.target as HTMLElement | null;
+ if (target?.closest("input, textarea, [contenteditable='true'], .selectable")) return;
+ event.preventDefault();
+});
+
const root = document.getElementById("root");
if (!root) {
throw new Error("index.html is missing #root");
diff --git a/desktop/src/styles.css b/desktop/src/styles.css
index be6e3fd2..7d8a9a9e 100644
--- a/desktop/src/styles.css
+++ b/desktop/src/styles.css
@@ -94,6 +94,16 @@
*/
--color-stage: #000000;
--color-on-stage: rgba(255, 255, 255, 0.38);
+ /*
+ * Selection highlight, the same in both themes.
+ *
+ * Lime is legible against near-black and near-white alike, which is what a
+ * selection has to be - it lands on whatever text happens to be underneath
+ * it. The dark ink on top is fixed for the same reason.
+ */
+ --color-selection: #c6f432;
+ --color-on-selection: #101014;
+
--color-playhead: #ff3b30;
--color-clip-video: #0a6cc4;
--color-clip-video-body: #cfe3f7;
@@ -180,6 +190,20 @@
--color-ruler: #131316;
}
+/**
+ * Opts a region back into text selection.
+ *
+ * The app disables selection globally, because dragging clips around a
+ * timeline should not paint half the interface blue. Read-only information is
+ * the exception - a file path you cannot copy is a file path you have to
+ * retype.
+ */
+@utility selectable {
+ user-select: text;
+ -webkit-user-select: text;
+ cursor: auto;
+}
+
/* Panel scrollbars: no visible track or gutter, just a small rounded thumb. */
@utility thin-scroll {
scrollbar-width: thin;
@@ -259,6 +283,11 @@
-webkit-user-select: text;
}
+ ::selection {
+ background-color: var(--color-selection);
+ color: var(--color-on-selection);
+ }
+
/* Numbers that change in place must not reflow as they do. */
.font-technical {
font-variant-numeric: tabular-nums;