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(transcript): the conversion source second -> ruler second lives in one place
EtienneLescot762201679da1
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 79f9f2e00..7bbbac76a 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -72,6 +72,7 @@ import {isSilenceWord,placementRawExtent,placementRawSec,+ recordingPlacements,type TranscriptLane,type TrimRun,voiceoverPlacements,@@ -896,7 +897,10 @@ export function TranscriptPane({},[setCaptionSettings],);- const placements = activeLane === "voiceover" ? voiceover : clips;+ // The clips WITH their parts, so a word after an insertion resolves to the moment it is+ // actually spoken rather than to its distance from the clip's start.+ const recording = useMemo(() => recordingPlacements(clips, transcripts), [clips, transcripts]);+ const placements = activeLane === "voiceover" ? voiceover : recording;const sections = useMemo(() => buildAggregatedSections(placements, transcripts, assets, removed),diff --git a/src/lib/ai-edition/captions/captions.test.ts b/src/lib/ai-edition/captions/captions.test.tsindex ce3d4a961..b313cd8f7 100644--- a/src/lib/ai-edition/captions/captions.test.ts+++ b/src/lib/ai-edition/captions/captions.test.ts@@ -650,3 +650,43 @@ describe("translated caption layout", () => {);});});++// The whole point of the insertion layer, seen from the far end: a word typed into the+// middle of a take lengthens the film, and every caption after it has to move with the+// audio it belongs to. This is the check that failed on screen before it failed here.+describe("captions over an inserted word", () => {+ const withInsertion = () => {+ const t = transcript();+ return doc({+ transcripts: [+ {+ ...t,+ words: [+ ...t.words.slice(0, 3),+ {+ id: "synth_1",+ segmentId: "seg_1",+ startSec: 2,+ endSec: 2,+ text: "wait",+ source: "synth",+ },+ ...t.words.slice(3),+ ],+ },+ ],+ });+ };++ it("moves every cue after the insertion by exactly the extension's length", () => {+ const cues = deriveCaptionCues(withInsertion(), ON, {});+ // "wait" is 4 chars at 15/s.+ expect(cues[cues.length - 1].endMs).toBeCloseTo(6000 + (4 / 15) * 1000, 0);+ });++ it("leaves the cues before it exactly where they were", () => {+ const before = deriveCaptionCues(doc(), ON, {});+ const after = deriveCaptionCues(withInsertion(), ON, {});+ expect(after[0].startMs).toBe(before[0].startMs);+ });+});diff --git a/src/lib/ai-edition/captions/cues.ts b/src/lib/ai-edition/captions/cues.tsindex 4d7395063..49d8fa315 100644--- a/src/lib/ai-edition/captions/cues.ts+++ b/src/lib/ai-edition/captions/cues.ts@@ -23,7 +23,11 @@ import {} from "@/lib/captioning/annotationsFromCaptions";import type { CaptionSegment } from "@/lib/captioning/transcribe";import type { AxcutDocument, AxcutTranscript } from "../schema";-import { lanePlacements, type TranscriptPlacement } from "../timeline/aggregated-transcript";+import {+ lanePlacements,+ placementRawSec,+ type TranscriptPlacement,+} from "../timeline/aggregated-transcript";import { removedRawSpans } from "../timeline/programme-time";import {type CaptionAnchorV,@@ -171,10 +175,11 @@ export function sourceSpanToTimelineSpans(const s = Math.max(startSec, clip.sourceStartSec);const e = Math.min(endSec, clipSourceEnd);if (e <= s) continue;- out.push({- startSec: clip.timelineStartSec + (s - clip.sourceStartSec),- endSec: clip.timelineStartSec + (e - clip.sourceStartSec),- });+ // Through `placementRawSec`, never the subtraction it used to write here: a clip+ // carrying an added word plays its media in pieces, and the seconds after the+ // insertion sit further along the ruler than their distance from the clip's start.+ // Writing the short version here is what put every caption after an insertion early.+ out.push({ startSec: placementRawSec(clip, s), endSec: placementRawSec(clip, e) });}// Onto the ruler the viewer actually sees. Expanding BOTH ends does the whole job:return out;@@ -201,6 +206,7 @@ export function deriveCaptionCues(// document written before it — or hand-built, never through the schema — has none.document.audioTracks ?? [],removedRawSpans(document.timeline.clips, document.timeline.trimRanges),+ document.transcripts,);if (placements.length === 0) return [];diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.ts b/src/lib/ai-edition/timeline/aggregated-transcript.tsindex 309e3c6aa..eeebae973 100644--- a/src/lib/ai-edition/timeline/aggregated-transcript.ts+++ b/src/lib/ai-edition/timeline/aggregated-transcript.ts@@ -16,6 +16,7 @@import { collapseTracksToPills } from "../document/audioTracks";import type { AxcutAsset, AxcutAudioTrack, AxcutClip, AxcutTranscript, AxcutWord } from "../schema";+import { type ClipPart, clipParts, extensionAt, partsRawSec, partsSourceSec } from "./clip-parts";import { type RawSpan, type RemovedRawSpan, removalAt } from "./programme-time";import { takeProgramme } from "./take-programme";@@ -43,6 +44,11 @@ export interface TranscriptPlacement {/** Where the window lands on the RAW ruler. Source time is per asset, so this is* the only thing that turns a word back into a moment the playhead can seek to. */timelineStartSec: number;+ /** The placement's parts, when it has any: a clip carrying added words plays its own+ * media in pieces with generated media between them, so a source second no longer sits+ * a fixed distance from the head. Absent, the placement is one uninterrupted stretch+ * and every reader below behaves exactly as it did before extensions existed. */+ parts?: readonly ClipPart[];}/** Which lane's speech the transcript tab is reading. */@@ -56,7 +62,9 @@ export type TranscriptLane = "recording" | "voiceover";* and not in source time (issue #560).*/export function placementRawSec(placement: TranscriptPlacement, sourceSec: number): number {- return placement.timelineStartSec + (sourceSec - placement.sourceStartSec);+ return placement.parts+ ? partsRawSec(placement.parts, sourceSec)+ : placement.timelineStartSec + (sourceSec - placement.sourceStartSec);}/** The placement's own stretch of raw ruler, or null when it runs open-ended. */@@ -345,14 +353,36 @@ export function voiceoverPlacements();}+/**+ * The recording lane's placements: the clips, each carrying its own parts.+ *+ * One placement per clip, not one per part. The pane draws a header per placement, and a+ * clip does not become three clips because the user typed a word into it — the split+ * belongs to the mapping, which is where `parts` puts it.+ */+export function recordingPlacements(+ clips: AxcutClip[],+ transcripts: readonly AxcutTranscript[],+): TranscriptPlacement[] {+ const wordsByAsset = new Map(transcripts.map((t) => [t.assetId, t.words]));+ return clips.map((clip) => ({+ ...clip,+ parts: clipParts(clip, wordsByAsset.get(clip.assetId) ?? []),+ }));+}+/** The placements a lane contributes, in timeline order. */export function lanePlacements(lane: TranscriptLane,clips: AxcutClip[],audioTracks: AxcutAudioTrack[],removed: readonly RemovedRawSpan[] = [],+ /** Needed only by the recording lane, to know where its clips are interrupted. */+ transcripts: readonly AxcutTranscript[] = [],): TranscriptPlacement[] {- return lane === "voiceover" ? voiceoverPlacements(audioTracks, removed) : clips;+ return lane === "voiceover"+ ? voiceoverPlacements(audioTracks, removed)+ : recordingPlacements(clips, transcripts);}/**@@ -398,8 +428,17 @@ export function findCueWordId(sections: ClipSection[], rawSec: number | null): s}if (!match) return null;+ // An added word is spoken over its extension, which occupies ruler time and no source+ // time at all. Asked first, and by id: through source time it is indistinguishable from+ // the recorded word that resumes at the same second — which is why the pane used to skip+ // straight past every inserted word to the one after it.+ const spoken = match.clip.parts ? extensionAt(match.clip.parts, rawSec) : null;+ if (spoken) return clipWordId(match.clip.id, spoken);+// Back to the placement's own source clock, which is what the words are stamped in.- const t = match.clip.sourceStartSec + (rawSec - match.clip.timelineStartSec);+ const t = match.clip.parts+ ? partsSourceSec(match.clip.parts, rawSec)+ : match.clip.sourceStartSec + (rawSec - match.clip.timelineStartSec);let previous: string | null = null;for (const cw of match.words) {if (isSilenceWord(cw.word)) continue;diff --git a/src/lib/ai-edition/timeline/clip-parts.test.ts b/src/lib/ai-edition/timeline/clip-parts.test.tsindex 71bde2a9c..d26495167 100644--- a/src/lib/ai-edition/timeline/clip-parts.test.ts+++ b/src/lib/ai-edition/timeline/clip-parts.test.ts@@ -7,8 +7,11 @@ import {clipParts,clipsWithExtensions,extensionAssetId,+ extensionAt,extensionDurationSec,partsLengthSec,+ partsRawSec,+ partsSourceSec,} from "./clip-parts";const CLIP: AxcutClip = {@@ -142,3 +145,60 @@ describe("clipsWithExtensions", () => {expect(extensionAssetId("synth_1")).toBe("ext:synth_1");});});++// ─── The one conversion ─────────────────────────────────────────────────────+// Every reader used to write `timelineStartSec + (sec - sourceStartSec)` for itself. That+// subtraction is right until a clip carries an extension and wrong for every second after+// it, which is one bug per reader — so it lives here now, once.++describe("partsRawSec", () => {+ const parts = clipParts(CLIP, [added("s1", 4, "really")]);+ const ext = extensionDurationSec("really");++ it("leaves the seconds before the insertion where they were", () => {+ expect(partsRawSec(parts, 2)).toBeCloseTo(2, 6);+ });++ it("pushes the seconds after it along by exactly what was inserted", () => {+ expect(partsRawSec(parts, 6)).toBeCloseTo(6 + ext, 6);+ expect(partsRawSec(parts, 10)).toBeCloseTo(10 + ext, 6);+ });++ it("puts the split second AFTER the extension, where its media actually plays", () => {+ expect(partsRawSec(parts, 4)).toBeCloseTo(4 + ext, 6);+ });++ it("is the plain subtraction when nothing was added", () => {+ const plain = clipParts({ ...CLIP, timelineStartSec: 12, timelineEndSec: 22 }, []);+ expect(partsRawSec(plain, 6)).toBeCloseTo(18, 6);+ });+});++describe("partsSourceSec", () => {+ const parts = clipParts(CLIP, [added("s1", 4, "really")]);+ const ext = extensionDurationSec("really");++ it("undoes partsRawSec for a second the recording actually plays", () => {+ for (const sec of [0, 2, 4, 6, 10]) {+ expect(partsSourceSec(parts, partsRawSec(parts, sec))).toBeCloseTo(sec, 6);+ }+ });++ it("parks at the split while the extension plays — no recording runs there", () => {+ expect(partsSourceSec(parts, 4 + ext / 2)).toBeCloseTo(4, 6);+ });+});++describe("extensionAt", () => {+ const parts = clipParts(CLIP, [added("s1", 4, "really")]);+ const ext = extensionDurationSec("really");++ it("names the word being spoken over its own media", () => {+ expect(extensionAt(parts, 4 + ext / 2)).toBe("s1");+ });++ it("is nothing on either side of it, so the recorded words keep the highlight", () => {+ expect(extensionAt(parts, 3.9)).toBeNull();+ expect(extensionAt(parts, 4 + ext + 0.01)).toBeNull();+ });+});diff --git a/src/lib/ai-edition/timeline/clip-parts.ts b/src/lib/ai-edition/timeline/clip-parts.tsindex fcd3bc29b..b9aef8375 100644--- a/src/lib/ai-edition/timeline/clip-parts.ts+++ b/src/lib/ai-edition/timeline/clip-parts.ts@@ -181,3 +181,62 @@ export function partsLengthSec(parts: readonly ClipPart[]): number {if (parts.length === 0) return 0;return parts[parts.length - 1].timelineEndSec - parts[0].timelineStartSec;}++/** The parts that carry source time. An extension has none, which is the whole point. */+function recordings(parts: readonly ClipPart[]): Array<Extract<ClipPart, { kind: "recording" }>> {+ return parts.filter((p): p is Extract<ClipPart, { kind: "recording" }> => p.kind === "recording");+}++/**+ * A source second of the clip's media, as a second on the ruler. THE conversion.+ *+ * Every reader that writes `timelineStartSec + (sec - sourceStartSec)` is wrong the moment+ * the clip carries an extension: the seconds after one are pushed along by it, and the+ * reader lands everything early by the total inserted before it. That is one bug with one+ * home, not one per reader.+ *+ * A second sitting exactly where an insertion split maps to the moment AFTER the extension,+ * because that is where the recorded media of that second actually plays. The added word+ * itself never asks this question — it has no source second at all, and `extensionAt`+ * names its moment directly.+ */+export function partsRawSec(parts: readonly ClipPart[], sourceSec: number): number {+ const played = recordings(parts);+ if (played.length === 0) return parts[0]?.timelineStartSec ?? sourceSec;+ let part = played[0];+ for (const candidate of played) {+ if (candidate.sourceStartSec <= sourceSec) part = candidate;+ }+ return part.timelineStartSec + (sourceSec - part.sourceStartSec);+}++/**+ * The inverse: a second on the ruler, as a second of the clip's media.+ *+ * Inside an extension the source clock is PARKED at the second the insertion split. That is+ * the honest answer — none of the recording plays there, and the split is the last second+ * that did.+ */+export function partsSourceSec(parts: readonly ClipPart[], rawSec: number): number {+ const played = recordings(parts);+ if (played.length === 0) return rawSec;+ let part = played[0];+ for (const candidate of played) {+ if (candidate.timelineStartSec <= rawSec) part = candidate;+ }+ return Math.min(part.sourceEndSec, part.sourceStartSec + (rawSec - part.timelineStartSec));+}++/**+ * The added word being spoken at this moment on the ruler, if any.+ *+ * Asked of the parts directly rather than resolved through source time, where an extension+ * and the media that follows it share one second and nothing could tell them apart.+ */+export function extensionAt(parts: readonly ClipPart[], rawSec: number): string | null {+ for (const part of parts) {+ if (part.kind !== "extension") continue;+ if (rawSec >= part.timelineStartSec && rawSec < part.timelineEndSec) return part.wordId;+ }+ return null;+}