Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

docs: describe the atempo stretch path and the six-library ffmpeg set

Etienne Lescot6a1a4cfef69e
diff --git a/technical-documentation/architecture/export-pipeline.md b/technical-documentation/architecture/export-pipeline.md
index 0068fdf4c..d9378d0bf 100644
--- a/technical-documentation/architecture/export-pipeline.md
+++ b/technical-documentation/architecture/export-pipeline.md
@@ -61,9 +61,9 @@ and **one** encoder + muxer pair:
per-segment rounded frame counts into a single output frame counter;
audio follows the same integer accumulation (`AudioConcatPlan`).
-- **Audio and video junctions are seamless.** Audio is decoded per
- segment up front (`audio.rs::decode_clip_audio`), WSOLA stretches each
- speed sub-segment to its output sample count, and
+- **Audio and video junctions are seamless.** Audio is decoded per clip
+ (`audio.rs::decode_clip_audio`), a libavfilter `atempo` chain stretches
+ each speed sub-segment to its output sample count, and
`assemble_concatenated_pcm` concatenates the per-segment PCM at the
integer sample offsets the video loop just produced — never
`round(cumulativeSec * sampleRate)`, because that compounds per-segment
@@ -71,8 +71,20 @@ and **one** encoder + muxer pair:
timeline. A short equal-power fade (`cos` on the tail, `sin` on the
head, `cos² + sin² = 1`) covers each internal boundary to suppress the
click where two recordings meet butt-joined, without shifting timing.
- The WSOLA stretch is kicked off before the video loop so it overlaps
- the encode and does not add to the wall.
+ The in-tree WSOLA stretcher is still there, but only as the fallback
+ `stretch_pcm_to_length` takes when the filter chain cannot be built or
+ yields too little audio (see [Audio](native-compositor.md#audio)).
+
+- **The stretch is not overlapped with the encode.** Decode and stretch
+ run inside `walk_composited_timeline`'s `on_clip_end` callback
+ (`pipeline.rs`), which fires once per clip *after* that clip's frames
+ have been composed and encoded, on the same thread — so the stretch
+ time is added to the export wall, not hidden behind it. `progress()` is
+ driven only by encoded video frames, so nothing moves while it runs and
+ a long clip parks the export at whatever percentage the last frame
+ reported. That is why the `atempo` path matters: it is O(n) where WSOLA
+ is O(grain × radius) per rendered sample, which on a long clip meant
+ minutes of an apparently frozen export.
- **Output** honours the timeline's selected aspect ratio
(`resolveAspectRatioValue` over `getEditorSettings(document).aspectRatio` —
diff --git a/technical-documentation/architecture/native-compositor.md b/technical-documentation/architecture/native-compositor.md
index f2b01c5c9..509ca68a3 100644
--- a/technical-documentation/architecture/native-compositor.md
+++ b/technical-documentation/architecture/native-compositor.md
@@ -31,7 +31,7 @@ and without that flag the runtime corruption is silent.
| [`crates/compositor/src/scene.rs`](../../crates/compositor/src/scene.rs) | the `Scene` struct parsed from the app's `SceneDescription` JSON |
| [`crates/compositor/src/regions.rs`](../../crates/compositor/src/regions.rs) | zoom / speed / Full Camera regions — envelope shapes and per-frame state sampling |
| [`crates/compositor/src/pipeline.rs`](../../crates/compositor/src/pipeline_windows.rs) | demux + `D3D11VA` decode + composite + AMF encode + mux (`run_c0` for decode/encode only, `run_composited` for the full path) |
-| [`crates/compositor/src/audio.rs`](../../crates/compositor/src/audio.rs) | per-clip audio decode, swresample → f32 planar 48 kHz stereo, WSOLA speed stretch, multi-track mix, AAC encoder |
+| [`crates/compositor/src/audio.rs`](../../crates/compositor/src/audio.rs) | per-clip audio decode, swresample → f32 planar 48 kHz stereo, libavfilter `atempo` speed stretch (WSOLA fallback), multi-track mix, AAC encoder |
| [`crates/compositor/src/cursor.rs`](../../crates/compositor/src/cursor.rs) | `.cursor.json` parser + interpolated cursor track (position, click bounces, adaptive follow samples) |
| [`crates/compositor/src/text.rs`](../../crates/compositor/src/text_windows.rs) | DirectWrite + Direct2D text rasterisation for annotation labels, cached per (content, style, box) |
| [`crates/compositor/src/text_anim.rs`](../../crates/compositor/src/text_anim.rs) | text-annotation appearance animations (port of the TS animation curves, in fractions of the output short side) |
@@ -199,9 +199,28 @@ each track is recut to the same `[source_start_sec, source_end_sec)` —
pads in front for late-starting tracks, trims the pre-roll for early-decoded
ones — so a summing mixer is enough and a real mix matrix is not needed.
-Speed regions apply after decode: WSOLA stretches each speed sub-segment to
-its output frame count, sharing search positions across channels from a
-mono down-mix (so the stereo image does not wander between channels).
+Speed regions apply after decode: `stretch_pcm_to_length` stretches each
+speed sub-segment to its output frame count through a libavfilter
+`abuffer → atempo… → abuffersink` graph built in-process
+(`avfilter_atempo_stretch`). The graph is pinned to the fltp / 48 kHz /
+stereo format `decode_clip_audio` already produces, and `atempo` preserves
+format, channels and rate, so no conversion is involved; the result is
+recut to the exact target length by truncation or zero-padding. `atempo`
+only accepts a factor in `[0.5, 100.0]`, so `atempo_factors` chains
+several instances whose product is the requested speed (0.2 →
+`[0.5, 0.5, 0.8]`).
+
+The in-tree WSOLA stretcher remains as the fallback, taken whenever
+`avfilter_atempo_stretch` returns `None` — the graph could not be built or
+configured, a buffersrc/buffersink call failed, or the chain drained fewer
+than 90% of the target samples, which is what happens on a span too short
+for `atempo`'s analysis window (a few tens of milliseconds between two
+speed regions). WSOLA shares its search positions across channels from a
+mono down-mix, so the stereo image does not wander between them. The move
+to `atempo` is a cost change, not a quality one: WSOLA is
+O(grain × radius) per rendered sample, minutes of a full core on a long
+clip, against `atempo`'s O(n) with ffmpeg's SIMD routines.
+
Across segments, `build_audio_concat_plan` sizes each segment's PCM by
**integer accumulation of the per-segment rounded sample count**, never
`round(cumulativeSec * sampleRate)` — that single change is what keeps A/V
diff --git a/technical-documentation/engineering/build-and-packaging.md b/technical-documentation/engineering/build-and-packaging.md
index 27ec043cc..bbb1d4084 100644
--- a/technical-documentation/engineering/build-and-packaging.md
+++ b/technical-documentation/engineering/build-and-packaging.md
@@ -42,7 +42,7 @@ Electron-builder copies only the matching `electron/native/bin/<platform>-<arch>
This is a hard requirement on Windows, not a tidiness preference.
-The addon dlopens `avcodec`/`avformat`/`avutil` at `require()` time. Until 1.9.0 the Windows build shipped it inside `app.asar.unpacked/electron/native/compositor-view/build/`, one directory away from `electron/native/bin/win32-x64/*.dll`, and the gap was bridged at runtime by `ensureFfmpegSharedDllsOnPath` prepending the DLL directory to `PATH` before the require.
+The addon pulls in six ffmpeg libraries at `require()` time — `avcodec`, `avformat`, `avutil`, `swresample`, `swscale` and `avfilter`, the exact set `crates/compositor/build.rs` emits `cargo:rustc-link-lib` lines for. (`avfilter` is the newest of them: the speed-region time stretch runs through its `atempo` filter.) Until 1.9.0 the Windows build shipped it inside `app.asar.unpacked/electron/native/compositor-view/build/`, one directory away from `electron/native/bin/win32-x64/*.dll`, and the gap was bridged at runtime by `ensureFfmpegSharedDllsOnPath` prepending the DLL directory to `PATH` before the require.
That works for the NSIS installer. **It does not work under MSIX**, which resolves an addon's dependent DLLs through the package graph and ignores `PATH`. Measured inside a registered package, with the directory verifiably present and correctly prepended to `PATH`:
@@ -60,7 +60,7 @@ require BEFORE PATH : LOADED OK
Node loads `.node` files with `LOAD_WITH_ALTERED_SEARCH_PATH`, so the addon's own directory is searched for its dependencies. Colocating removes the `PATH` mechanism rather than repairing it, and works on every Windows packaging format.
-This shipped: the 1.9.0 Store build loaded no compositor at all, so the editor opened with a permanently blank preview while audio kept playing — audio comes from the renderer, every frame comes from the addon. It read as an application bug rather than a packaging one, because every file was present in the package and the NSIS build of the same commit was fine. `scripts/before-pack.cjs` now refuses to package unless the addon and at least `avcodec`/`avformat`/`avutil` are in the same directory, on Windows as it already did on macOS.
+This shipped: the 1.9.0 Store build loaded no compositor at all, so the editor opened with a permanently blank preview while audio kept playing — audio comes from the renderer, every frame comes from the addon. It read as an application bug rather than a packaging one, because every file was present in the package and the NSIS build of the same commit was fine. `scripts/before-pack.cjs` now refuses to package unless the addon and all six of those libraries are in the same directory, on Windows as it already did on macOS. It checks one requirement **per library** rather than a count over a combined pattern, on all three platforms: several versioned copies of one library (an `avcodec-60`/`61`/`62.dll` left by an earlier fetch) would satisfy a combined count while another was missing entirely, and the addon would still fail to load.
`electron/native/bin/`, local native build directories, the compositor build output, models, and caches are gitignored. Rebuilding from a source checkout therefore requires the complete platform toolchain and third-party SDKs; running the generic `npm run build` alone does not manufacture missing native artifacts. The Windows compositor's D3D11/FFmpeg prerequisites are described by the source POC in `crates/README.md`, while capture helper lookup and output conventions are documented in `electron/native/README.md`.