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(captions): place a cue past an insertion on the source it names
EtienneLescoteddcbe22a2de
diff --git a/src/lib/ai-edition/timeline/timelineMap.test.ts b/src/lib/ai-edition/timeline/timelineMap.test.tsindex ea3f6c61b..b06ac8fb9 100644--- a/src/lib/ai-edition/timeline/timelineMap.test.ts+++ b/src/lib/ai-edition/timeline/timelineMap.test.ts@@ -5,7 +5,7 @@import { describe, expect, it } from "vitest";import { resolvePlaybackSegments } from "../document/timeline";-import type { AxcutClip, AxcutTrimRange } from "../schema";+import type { AxcutClip, AxcutInsertRange, AxcutTrimRange } from "../schema";import {anchorRawRegionsToClips,anchorRegionsWithDerivedMs,@@ -805,3 +805,65 @@ describe("legacy groupId must never affect identity (regression: test 1)", () =>expect(out[0]).not.toHaveProperty("groupId");});});++// ─── Placing an unanchored region past an insertion ─────────────────────────+// A caption cue is built fresh on every derive and carries no clip anchor, so it is placed+// by intersecting its TIMELINE span with each segment's extent. A clip carrying insertions+// is longer than its source window, so the segment that resumes after one starts that much+// further along — and a projection blind to that put every caption after an insertion on+// the wrong stretch of source. That is what "the subtitles are out of sync" was (#560).++describe("projectRegionsToSource past an insertion", () => {+ const raw = clip({+ id: "c1",+ assetId: "a1",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 11, // 10s of recording + 1s inserted at source 5+ });+ const inserts: AxcutInsertRange[] = [+ {+ id: "i1",+ assetId: "a1",+ atSec: 5,+ durationSec: 1,+ wordId: "w1",+ reason: "",+ origin: "user",+ },+ ];+ // What `resolvePlaybackSegments` produces: the clip split at the insertion, with the+ // inserted media between the halves.+ const segments = [+ clip({ id: "c1_seg1", assetId: "a1", sourceStartSec: 0, sourceEndSec: 5 }),+ clip({ id: "c1_seg2", assetId: "a1", sourceStartSec: 5, sourceEndSec: 10 }),+ ];++ it("lands a region on the source it actually names", () => {+ // Timeline 7..9 is one second past the insertion, so it is source 6..8.+ const [out] = projectRegionsToSource(+ [region("cue", 7, 9)],+ segments,+ [raw],+ () => "x",+ inserts,+ );+ expect(out.startMs).toBe(6000);+ expect(out.endMs).toBe(8000);+ expect(out.clipIndex).toBe(1);+ });++ it("leaves a region before the insertion where it was", () => {+ const [out] = projectRegionsToSource(+ [region("cue", 1, 3)],+ segments,+ [raw],+ () => "x",+ inserts,+ );+ expect(out.startMs).toBe(1000);+ expect(out.endMs).toBe(3000);+ expect(out.clipIndex).toBe(0);+ });+});diff --git a/src/lib/ai-edition/timeline/timelineMap.ts b/src/lib/ai-edition/timeline/timelineMap.tsindex 4440b4be0..2f3749ae7 100644--- a/src/lib/ai-edition/timeline/timelineMap.ts+++ b/src/lib/ai-edition/timeline/timelineMap.ts@@ -568,11 +568,16 @@ export function projectRegionsToSource<visibleSegments: PlaybackSegment[],rawClips: AxcutClip[],makeId: () => string,+ /** The insertions the clips carry. A segment after one starts that much further along+ * the timeline, and an UNANCHORED region — a caption cue, which is built fresh each+ * time and has no clip anchor — is placed by intersecting with exactly that extent.+ * Without them the caption landed on the wrong stretch of source (issue #560). */+ insertRanges: readonly AxcutInsertRange[] = [],): (T & { clipIndex?: number; underTrim?: boolean })[] {// RAW extents + owning raw clip per visible segment. Both are only consulted by the// path that needs them (raw fallback / anchor match), but resolving them once keeps// the per-region loop free of repeated lookups.- const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips));+ const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips, insertRanges));const segmentRawClipIds = visibleSegments.map((seg) => findRawClipForSegment(seg, rawClips)?.id);const out: (T & { clipIndex?: number; underTrim?: boolean })[] = [];for (const region of regions) {diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 7fa4f2f03..683066b69 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -777,6 +777,7 @@ export function buildSceneDescription(visibleClips,document.timeline.clips,() => createId("zoom"),+ document.timeline.insertRanges ?? [],);// Same raw→source projection as the zoom regions above, for the same reason: annotations are// authored in RAW document time and the compositor matches each frame's SOURCE time.@@ -813,6 +814,7 @@ export function buildSceneDescription(visibleClips,document.timeline.clips,() => createId("ann"),+ document.timeline.insertRanges ?? [],);const projectedCameraFullscreenRegions = projectRegionsToSource(((document.legacyEditor as Record<string, unknown> | null)?.cameraFullscreenRegions as@@ -821,6 +823,7 @@ export function buildSceneDescription(visibleClips,document.timeline.clips,() => createId("camfull"),+ document.timeline.insertRanges ?? [],);// Speed regions carry an extra `speed` field the standard `rangeSchema` does not, so we// can't read from `document.timeline.speedRanges` today (see SceneDescription.speedRegions@@ -835,6 +838,7 @@ export function buildSceneDescription(visibleClips,document.timeline.clips,() => createId("speed"),+ document.timeline.insertRanges ?? [],);// Webcam rect, single source of truth between preview & native :