Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix: derive the dev ffmpeg dir from the cargo pin, and drop a region that a trim removes
Etienne Lescotaa359ee94ee0
diff --git a/electron/native-bridge/services/compositorViewService.test.ts b/electron/native-bridge/services/compositorViewService.test.tsindex fbdc76c54..b0d7fee8b 100644--- a/electron/native-bridge/services/compositorViewService.test.ts+++ b/electron/native-bridge/services/compositorViewService.test.ts@@ -4,26 +4,85 @@ import path from "node:path";import { afterEach, beforeEach, describe, expect, it } from "vitest";import { CompositorViewService, ffmpegSharedBinCandidates } from "./compositorViewService";+/** A source checkout's `poc-d3d/.cargo/config.toml`, with `FFMPEG_DIR` written as `body`. */+function writeCargoConfig(root: string, body: string): void {+ const cargoDir = path.join(root, "poc-d3d", ".cargo");+ fs.mkdirSync(cargoDir, { recursive: true });+ fs.writeFileSync(+ path.join(cargoDir, "config.toml"),+ `# pin comment\n[env]\n${body}\nLIBCLANG_PATH = "C:\\\\Program Files\\\\LLVM\\\\bin"\n`,+ "utf8",+ );+}+describe("ffmpegSharedBinCandidates", () => {- it("lists the dev-vendored shared-ffmpeg dir before the arch-tagged native bin dir", () => {- const appRoot = "C:/fake/repo";- const candidates = ffmpegSharedBinCandidates(appRoot).map((p) => p.replace(/\\/g, "/"));+ let tmpRoot: string;++ beforeEach(() => {+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openscreen-ffmpeg-pin-test-"));+ });++ afterEach(() => {+ fs.rmSync(tmpRoot, { recursive: true, force: true });+ });++ it("reads the dev-vendored dir off the cargo pin instead of a second hardcoded copy of the name", () => {+ // The pin has moved before (floating `master-latest` → fixed `n8.1.2`) and+ // left this list probing a directory that no longer existed. Deriving it+ // means the next repin cannot rot the loader.+ writeCargoConfig(+ tmpRoot,+ `FFMPEG_DIR = { value = "thirdparty/ffmpeg-n9.9.9-win64-lgpl-shared", relative = true }`,+ );+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));+expect(candidates[0]).toBe(- `${appRoot}/poc-d3d/thirdparty/ffmpeg-master-latest-win64-lgpl-shared/bin`,+ `${tmpRoot.replace(/\\/g, "/")}/poc-d3d/thirdparty/ffmpeg-n9.9.9-win64-lgpl-shared/bin`,);expect(candidates[1]).toMatch(/electron\/native\/bin\/(win32|darwin|linux)-(x64|arm64)$/);});+ it("accepts the plain-string spelling of the pin as well as the table one", () => {+ writeCargoConfig(tmpRoot, `FFMPEG_DIR = "thirdparty/ffmpeg-plain"`);+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));++ expect(candidates[0]).toBe(+ `${tmpRoot.replace(/\\/g, "/")}/poc-d3d/thirdparty/ffmpeg-plain/bin`,+ );+ });++ it("keeps an absolute pin absolute rather than nesting it under the crate dir", () => {+ writeCargoConfig(tmpRoot, `FFMPEG_DIR = "C:/vendor/ffmpeg"`);+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));++ expect(candidates[0]).toBe("C:/vendor/ffmpeg/bin");+ });++ it("starts at the arch-tagged native bin dir when there is no cargo pin to read", () => {+ // Packaged builds ship no `poc-d3d/` at all — the dev candidate must drop+ // out silently rather than contribute a path that can never exist.+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));++ expect(candidates[0]).toMatch(/electron\/native\/bin\/(win32|darwin|linux)-(x64|arm64)$/);+ expect(candidates.some((c) => c.includes("poc-d3d"))).toBe(false);+ });++ it("ignores a cargo config that pins no FFMPEG_DIR", () => {+ writeCargoConfig(tmpRoot, `SOME_OTHER_VAR = "thirdparty/nope"`);+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));++ expect(candidates.some((c) => c.includes("poc-d3d"))).toBe(false);+ });+it("also probes process.resourcesPath, since electron/native/bin ships only via extraResources in packaged builds", () => {+ writeCargoConfig(tmpRoot, `FFMPEG_DIR = { value = "thirdparty/ffmpeg-x", relative = true }`);const original = process.resourcesPath;Object.defineProperty(process, "resourcesPath", {value: "C:/fake/resources",configurable: true,});try {- const candidates = ffmpegSharedBinCandidates("C:/fake/repo").map((p) =>- p.replace(/\\/g, "/"),- );+ const candidates = ffmpegSharedBinCandidates(tmpRoot).map((p) => p.replace(/\\/g, "/"));expect(candidates).toContain(`C:/fake/resources/electron/native/bin/${candidates[1]!.split("/").at(-1)}`,);@@ -53,15 +112,19 @@ describe("CompositorViewService ffmpeg PATH prepend", () => {}});- it("prepends the ffmpeg shared-DLL dir to PATH when it exists, even though the addon itself is absent", () => {- const ffmpegDir = path.join(- tmpRoot,- "poc-d3d",- "thirdparty",- "ffmpeg-master-latest-win64-lgpl-shared",- "bin",+ /** Lay down a source checkout: the cargo pin plus the tree it points at. */+ function vendorPinnedFfmpeg(root: string): string {+ writeCargoConfig(+ root,+ `FFMPEG_DIR = { value = "thirdparty/ffmpeg-n8.1.2-win64-lgpl-shared", relative = true }`,);- fs.mkdirSync(ffmpegDir, { recursive: true });+ const dir = path.join(root, "poc-d3d", "thirdparty", "ffmpeg-n8.1.2-win64-lgpl-shared", "bin");+ fs.mkdirSync(dir, { recursive: true });+ return dir;+ }++ it("prepends the ffmpeg shared-DLL dir to PATH when it exists, even though the addon itself is absent", () => {+ const ffmpegDir = vendorPinnedFfmpeg(tmpRoot);process.env.PATH = "C:\\Windows\\System32";const service = new CompositorViewService({ appRoot: tmpRoot, isPackaged: false });@@ -69,6 +132,18 @@ describe("CompositorViewService ffmpeg PATH prepend", () => {expect(process.env.PATH?.split(path.delimiter)).toContain(ffmpegDir);});+ it("skips a pinned dir the checkout never vendored, instead of putting a dead path on PATH", () => {+ // The exact rot this derivation removes: a pin naming a tree that isn't+ // on disk must contribute nothing, not a candidate that can never resolve.+ writeCargoConfig(tmpRoot, `FFMPEG_DIR = "thirdparty/ffmpeg-not-vendored"`);+ process.env.PATH = "C:\\Windows\\System32";+ const before = process.env.PATH;++ new CompositorViewService({ appRoot: tmpRoot, isPackaged: false }).hasAddon();++ expect(process.env.PATH).toBe(before);+ });+it("leaves PATH untouched when no ffmpeg shared-DLL dir exists", () => {process.env.PATH = "C:\\Windows\\System32";const before = process.env.PATH;@@ -80,14 +155,7 @@ describe("CompositorViewService ffmpeg PATH prepend", () => {});it("does not duplicate the entry when PATH already contains it", () => {- const ffmpegDir = path.join(- tmpRoot,- "poc-d3d",- "thirdparty",- "ffmpeg-master-latest-win64-lgpl-shared",- "bin",- );- fs.mkdirSync(ffmpegDir, { recursive: true });+ const ffmpegDir = vendorPinnedFfmpeg(tmpRoot);process.env.PATH = "C:\\Windows\\System32";// simulates a second view/service instance loading after PATH wasdiff --git a/electron/native-bridge/services/compositorViewService.ts b/electron/native-bridge/services/compositorViewService.tsindex 30fd5600d..bbea4a529 100644--- a/electron/native-bridge/services/compositorViewService.ts+++ b/electron/native-bridge/services/compositorViewService.ts@@ -150,6 +150,41 @@ function buildCandidatePaths(return ordered.map((candidate) => candidate.replace(/\.asar([/\\])/, ".asar.unpacked$1"));}+/**+ * The dev-vendored ffmpeg tree, read from the pin that already exists rather+ * than named a second time here: `poc-d3d/.cargo/config.toml`'s `FFMPEG_DIR`.+ *+ * That pin is the one thing the addon is actually built against (see the+ * config's own comment), so the DLL basenames it imports — `avcodec-62.dll` and+ * friends — only match the tree it points at. Restating the folder name in this+ * file is precisely how the previous entry rotted: the pin moved off a floating+ * `master-latest` snapshot onto the fixed `n8.1.2` release and this list went on+ * probing a directory that no longer existed. Nothing broke, because the search+ * silently fell through to the vendored `electron/native/bin/<tag>` — which is+ * what makes the rot worth removing rather than tolerating.+ *+ * Returns null when there is no config to read: packaged builds ship no+ * `poc-d3d/` at all, and the candidate list simply starts one entry later.+ */+function pinnedFfmpegDir(appRoot: string): string | null {+ const crateDir = path.join(appRoot, "poc-d3d");+ let toml: string;+ try {+ toml = fs.readFileSync(path.join(crateDir, ".cargo", "config.toml"), "utf8");+ } catch {+ return null;+ }+ // Both spellings cargo accepts carry the path as the first quoted string on+ // the line: `FFMPEG_DIR = "…"` and `FFMPEG_DIR = { value = "…", relative = true }`.+ const value = /^\s*FFMPEG_DIR\s*=.*?"([^"]+)"/m.exec(toml)?.[1];+ if (!value) {+ return null;+ }+ // `relative = true` resolves against the directory the config governs (the+ // crate root), which is also what the pin's own comment documents.+ return path.isAbsolute(value) ? value : path.join(crateDir, value);+}+/*** Directories that may hold the ffmpeg shared DLLs (avcodec/avformat/avutil/…)* the addon dynamically links against. Node's `require()` of a native addon@@ -158,12 +193,13 @@ function buildCandidatePaths(* gets prepended to `process.env.PATH` before the `require()` in* `tryLoadAddon`.*- * Order: the dev-only vendored location first, then the arch-tagged bin dir- * under `appRoot` (dev / `electron-builder --dir` unpacked staging), then the- * *same* dir under `process.resourcesPath` — required for real packaged- * installers, since `electron/native/bin/**` ships exclusively via- * `extraResources` (see `electron-builder.json5`'s `files` list, which only- * packs `dist`/`dist-electron`) and is never inside `app.getAppPath()` there.+ * Order: the dev-only vendored location first (absent outside a source+ * checkout — see `pinnedFfmpegDir`), then the arch-tagged bin dir under+ * `appRoot` (dev / `electron-builder --dir` unpacked staging), then the *same*+ * dir under `process.resourcesPath` — required for real packaged installers,+ * since `electron/native/bin/**` ships exclusively via `extraResources` (see+ * `electron-builder.json5`'s `files` list, which only packs+ * `dist`/`dist-electron`) and is never inside `app.getAppPath()` there.* Mirrors the appPath/resourcePath pattern `stt/gpuDetector.ts` already uses* for the other native binaries in this same directory.*/@@ -173,8 +209,9 @@ export function ffmpegSharedBinCandidates(appRoot: string): string[] {typeof process.resourcesPath === "string" && process.resourcesPath.length > 0? process.resourcesPath: null;+ const devDir = pinnedFfmpegDir(appRoot);return [- path.join(appRoot, "poc-d3d", "thirdparty", "ffmpeg-master-latest-win64-lgpl-shared", "bin"),+ ...(devDir ? [path.join(devDir, "bin")] : []),path.join(appRoot, "electron", "native", "bin", tag),...(resourcesPath ? [path.join(resourcesPath, "electron", "native", "bin", tag)] : []),];diff --git a/src/lib/ai-edition/timeline/timelineMap.test.ts b/src/lib/ai-edition/timeline/timelineMap.test.tsindex 04b4ad9d1..a8eb2695e 100644--- a/src/lib/ai-edition/timeline/timelineMap.test.ts+++ b/src/lib/ai-edition/timeline/timelineMap.test.ts@@ -121,6 +121,50 @@ describe("projectRegionsToSource", () => {]);});+ it("drops a region a trim removes entirely rather than leaking it onto a later clip", () => {+ // The reported bug: an effect fully UNDER a trim fired later instead of being ignored.+ // Two clips of DIFFERENT assets whose source windows overlap numerically (c1: asset a+ // [0,10] @ raw[0,10]; c2: asset b [0,10] @ raw[10,20]). A zoom anchored to c1 at source+ // [3,5] is then fully trimmed away on c1 (trim removes a[2,8]; c2's asset b is+ // untouched). It must VANISH — not reappear during c2, whose source window [0,10]+ // numerically contains [3,5]. A clipIndex-less passthrough used to re-emit it with raw+ // coords, and native's `belongs()` then matched it on c2 (any overlapping clip).+ const c1 = clip({+ id: "c1",+ assetId: "a",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ });+ const c2 = clip({+ id: "c2",+ assetId: "b",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 10,+ timelineEndSec: 20,+ });+ const segments = resolvePlaybackSegments([c1, c2], [trim("a", 2, 8)]);+ const anchored = { ...region("r", 3, 5), clipId: "c1", sourceStartSec: 3, sourceEndSec: 5 };+ expect(projectRegionsToSource([anchored], segments, [c1, c2], () => "x")).toEqual([]);+ });++ it("drops an unanchored region that a trim removes entirely", () => {+ // The same class for an un-migrated (v1.7-imported) region that has only its RAW span:+ // raw[4.5,5.5] sits inside the removed stretch a[4,6], so it maps to no kept segment+ // and must be dropped — not passed through with its raw coords onto the native scene.+ const c = clip({+ id: "c1",+ assetId: "a",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineEndSec: 10,+ });+ const segments = resolvePlaybackSegments([c], [trim("a", 4, 6)]);+ expect(projectRegionsToSource([region("r", 4.5, 5.5)], segments, [c], () => "x")).toEqual([]);+ });+// --- anchored path: the anchor is the SSOT, `startMs`/`endMs` are not consulted ---it("places an anchored region from its anchor, ignoring a stale startMs/endMs", () => {diff --git a/src/lib/ai-edition/timeline/timelineMap.ts b/src/lib/ai-edition/timeline/timelineMap.tsindex 001210011..15a9b433a 100644--- a/src/lib/ai-edition/timeline/timelineMap.ts+++ b/src/lib/ai-edition/timeline/timelineMap.ts@@ -484,7 +484,18 @@ export function projectRegionsToSource<);});}- if (emitted === 0) out.push(region);+ // A region that WAS resolved against real segments but overlapped none of them+ // sits entirely under a trim (or off the visible timeline) — its content was+ // removed, so it must NOT render. Re-emitting it here is exactly what let a+ // fully-trimmed effect resurface elsewhere: it would carry its RAW-virtual+ // startMs/endMs and NO clipIndex, and native's `belongs()` (scene.rs) accepts a+ // clipIndex-less region on ANY clip whose SOURCE window numerically overlaps those+ // raw numbers — so the effect fired *later* on an unrelated clip instead of being+ // ignored (the same wrong-clip class as the `speed_at` fix in regions.rs). Only+ // when there are no segments AT ALL is there no layout to resolve against; keep the+ // passthrough for that degenerate case (it reaches an empty native clip list and so+ // can never be matched anyway).+ if (emitted === 0 && visibleSegments.length === 0) out.push(region);}return out;}