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(audio): stop tracks inside a trimmed stretch from playing
Ola Adebayo24f736e19de7
diff --git a/src/components/ai-edition/VirtualPreview.audio.test.ts b/src/components/ai-edition/VirtualPreview.audio.test.tsindex 7371f851e..e1d6fec6d 100644--- a/src/components/ai-edition/VirtualPreview.audio.test.ts+++ b/src/components/ai-edition/VirtualPreview.audio.test.ts@@ -203,6 +203,75 @@ describe("resolveTimelineAudioPlayback", () => {});});+describe("resolveTimelineAudioPlayback under a trim", () => {+ const clip: AxcutClip = {+ id: "clip_1",+ assetId: "asset_1",+ sourceStartSec: 0,+ sourceEndSec: 20,+ timelineStartSec: 0,+ timelineEndSec: 20,+ wordRefs: [],+ origin: "user",+ reason: "",+ };+ const trim: AxcutTrimRange = {+ id: "trim_1",+ assetId: "asset_1",+ startSec: 4,+ endSec: 8,+ origin: "user",+ reason: "",+ };+ const project = (rawSec: number) => projectRawTimelineSecToPlayback([clip], [trim], rawSec);++ const buried: AxcutAudioTrack = {+ id: "buried",+ assetId: "a1",+ kind: "music",+ startMs: 5000,+ endMs: 7000,+ durationSec: 30,+ offsetMs: 0,+ gainDb: 0,+ loop: false,+ fadeInMs: 0,+ fadeOutMs: 0,+ muted: false,+ label: "",+ origin: "user",+ };++ it("never plays a track buried inside the trim", () => {+ // Both ends project onto the cut, so the track's OUTPUT span is zero. Read+ // off the raw span instead it stayed 2s long and played at the boundary,+ // with nothing on screen to explain the sound.+ const outStart = project(buried.startMs / 1000);+ const outSpan = project(buried.endMs / 1000) - outStart;+ expect(outSpan).toBeCloseTo(0, 6);+ for (const raw of [3, 5, 6, 9, 12]) {+ expect(resolveTimelineAudioPlayback(project(raw), outStart, buried, outSpan).shouldPlay).toBe(+ false,+ );+ }+ });++ it("plays a track that merely crosses the trim, for the length that survives", () => {+ const crossing = { ...buried, id: "crossing", startMs: 2000, endMs: 12_000 };+ const outStart = project(crossing.startMs / 1000);+ const outSpan = project(crossing.endMs / 1000) - outStart;+ // Raw 2..12 with raw 4..8 cut leaves 6s of programme.+ expect(outSpan).toBeCloseTo(6, 6);+ expect(resolveTimelineAudioPlayback(project(3), outStart, crossing, outSpan).shouldPlay).toBe(+ true,+ );+ // Just past the end of what survives.+ expect(+ resolveTimelineAudioPlayback(outStart + 6.1, outStart, crossing, outSpan).shouldPlay,+ ).toBe(false);+ });+});+describe("timelineAudioFadeAt", () => {const track: AxcutAudioTrack = {id: "t1",diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsxindex 50b500a1b..3994c8f29 100644--- a/src/components/ai-edition/VirtualPreview.tsx+++ b/src/components/ai-edition/VirtualPreview.tsx@@ -648,7 +648,19 @@ export function VirtualPreview({trimRangesRef.current,track.startMs / 1000,);- const spanSec = Math.max(0, (track.endMs - track.startMs) / 1000);+ // The span on the OUTPUT programme, not the raw ruler: both ends go+ // through the same projection the head does. A track buried inside a+ // trimmed stretch collapses to zero length and stays silent, instead+ // of playing its full raw length parked at the cut — audible with+ // nothing on screen to explain it.+ const spanSec = Math.max(+ 0,+ projectRawTimelineSecToPlayback(+ clipsRef.current,+ trimRangesRef.current,+ track.endMs / 1000,+ ) - outputStartSec,+ );const trackTarget = resolveTimelineAudioPlayback(outputTimeSec,outputStartSec,diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex 3effa84c4..0f7eb9dfe 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -2097,6 +2097,61 @@ describe("buildSceneDescription.audioTracks", () => {expect(buildSceneDescription(doc).audioTracks[0]?.startSec).toBeCloseTo(3, 6);});+ it("drops a track that sits entirely inside a trimmed stretch", () => {+ // The trim takes raw 4..8 out of the programme; a track living at raw 5..7+ // has nowhere left to play. It used to project both ends onto the cut and+ // then play its full raw length there — audible, and out of place, with+ // nothing on screen to account for it.+ const screen = makeAsset({ id: "scr", originalPath: "/screen.mp4", durationSec: 20 });+ const doc = makeDoc({+ assets: [screen, audioAsset],+ clips: [+ makeClip({+ id: "c1",+ assetId: "scr",+ sourceStartSec: 0,+ sourceEndSec: 20,+ timelineStartSec: 0,+ timelineEndSec: 20,+ }),+ ],+ timeline: {+ trimRanges: [+ { id: "t1", assetId: "scr", startSec: 4, endSec: 8, reason: "", origin: "user" },+ ],+ },+ audioTracks: [{ ...track, startMs: 5000, endMs: 7000 }],+ });+ expect(buildSceneDescription(doc).audioTracks).toEqual([]);+ });++ it("shortens a track by the trim it crosses", () => {+ // Raw 2..12 with raw 4..8 cut is 6s of programme, not 10.+ const screen = makeAsset({ id: "scr", originalPath: "/screen.mp4", durationSec: 20 });+ const doc = makeDoc({+ assets: [screen, audioAsset],+ clips: [+ makeClip({+ id: "c1",+ assetId: "scr",+ sourceStartSec: 0,+ sourceEndSec: 20,+ timelineStartSec: 0,+ timelineEndSec: 20,+ }),+ ],+ timeline: {+ trimRanges: [+ { id: "t1", assetId: "scr", startSec: 4, endSec: 8, reason: "", origin: "user" },+ ],+ },+ audioTracks: [{ ...track, startMs: 2000, endMs: 12_000, offsetMs: 0 }],+ });+ const [entry] = buildSceneDescription(doc).audioTracks;+ expect(entry.startSec).toBeCloseTo(2, 6);+ expect(entry.trimEndSec - entry.trimStartSec).toBeCloseTo(6, 6);+ });+it("drops a track whose asset has no resolvable path", () => {const doc = makeDoc({ assets: [], audioTracks: [track] });expect(buildSceneDescription(doc).audioTracks).toEqual([]);diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 17dd3dd3b..641ce86ce 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -550,13 +550,23 @@ export function buildSceneDescription(if (!asset?.originalPath) return [];const sourceDurationSec = asset.durationSec ?? track.durationSec;const offsetSec = track.offsetMs / 1000;- const spanSec = (track.endMs - track.startMs) / 1000;- if (spanSec <= 0) return [];const startSec = projectRawTimelineSecToPlayback(projectedClips,document.timeline.trimRanges,track.startMs / 1000,);+ // Measure the span on the OUTPUT programme, not the raw ruler. A track+ // sitting inside a trimmed stretch projects BOTH its ends onto the same+ // boundary, so its output span is zero and it is dropped — where the raw+ // span kept it alive and played it, in full, at the cut. A track that+ // merely crosses a trim shortens by what the cut removed.+ const endSec = projectRawTimelineSecToPlayback(+ projectedClips,+ document.timeline.trimRanges,+ track.endMs / 1000,+ );+ const spanSec = endSec - startSec;+ if (spanSec <= 0) return [];const base = {path: asset.originalPath,gainDb: track.gainDb,