Open source CapCut alternative.
TypeScript
fix(site): join hard-cut runs with one concat [rebuild]
David Lef38989122f42
diff --git a/site/src/cut/server/exportPipeline.test.ts b/site/src/cut/server/exportPipeline.test.tsindex b64918a7..fe9817bf 100644--- a/site/src/cut/server/exportPipeline.test.ts+++ b/site/src/cut/server/exportPipeline.test.ts@@ -427,6 +427,24 @@ describe("one input per cut", () => {});});+describe("joins", () => {+ test("a run of hard cuts is one concat, split by a transition", async () => {+ const g = await graphFor({+ clips: [clip("a.mp4"), clip("b.mp4"), clip("c.mp4", { transition: 0.5 }), clip("d.mp4"), clip("e.mp4")],+ });+ const joins = g.filter((f) => /concat=|xfade=/.test(f) && !f.includes("[fan"));+ expect(joins.map((f) => f.replace(/xfade=.*\[/, "xfade=…["))).toEqual([+ "[vg0][vg1][vg2]concat=n=3:v=1:a=0,fps=30[vj2]",+ "[a0][a1][a2]concat=n=3:v=0:a=1[aj2]",+ "[vj2][vh3]xfade=…[vx3]",+ "[ah3][a3]concat=n=2:v=0:a=1[ax3]",+ "[vx3][vg4]concat=n=2:v=1:a=0,fps=30[vj4]",+ "[ax3][a4]concat=n=2:v=0:a=1[aj4]",+ ]);+ expect(xfadeMismatches(g)).toEqual([]);+ });+});+describe("a speed curve in the filtergraph", () => {test("a curved clip lays its picture through the map and reads baked sound", async () => {const curved = clip("a.mp4", { speedCurve: [[0, 1], [4, 4]] });diff --git a/site/src/cut/server/exportPipeline.ts b/site/src/cut/server/exportPipeline.tsindex b14f1469..1972f1f5 100644--- a/site/src/cut/server/exportPipeline.ts+++ b/site/src/cut/server/exportPipeline.ts@@ -2692,8 +2692,24 @@ export async function runExport();segLabel[j] = `vg${j}`;});- let vAcc = segLabel[0];- let aAcc = "a0";+ // A run of joins that concat — hard cuts and cross dissolves, whose sound+ // crosses on its own streams — is one concat over the whole run. A chain+ // of two-way concats would hold every frame handed to a segment it has not+ // reached at each link it waits behind, so its memory grew with the cut+ // count; one concat reads its segments in turn. concat emits a microsecond+ // timebase with no frame-rate stamp, and a later transitioned join hands+ // the run to xfade, which demands both inputs carry the same 1/fps stamp —+ // re-stamp it.+ let runV = [segLabel[0]];+ let runA = ["a0"];+ const joinRun = (j: number): [string, string] => {+ if (runV.length === 1) {+ return [runV[0], runA[0]];+ }+ filters.push(`${runV.map((l) => `[${l}]`).join("")}concat=n=${runV.length}:v=1:a=0,fps=${fps}[vj${j}]`);+ filters.push(`${runA.map((l) => `[${l}]`).join("")}concat=n=${runA.length}:v=0:a=1[aj${j}]`);+ return [`vj${j}`, `aj${j}`];+ };// Running timeline length of the accumulator, on the frame grid.const gridEnd = (j: number) => (segFrames[j].first + segFrames[j].count) / fps;let acc = gridEnd(0);@@ -2703,36 +2719,29 @@ export async function runExport(// The blend can't exceed most of either clip, matching the editor clamp.const d = Math.min(prev.transition ?? 0, acc * 0.9, durJ * 0.9);const cross = Math.min(prev.soundCross ?? 0, acc * 0.9, durJ * 0.9);- const vOut = `vj${j}`;- const aOut = `aj${j}`;- if (cross > 0.01) {- // The picture cuts: concat, re-stamped for a later xfade the same way- // a plain join is. The sound crosses the cut — its ramps are already on- // the two segments, and the halves that reach past the cut ride their- // own streams into the mix, so the join here is a plain one.- filters.push(`[${vAcc}][${segLabel[j]}]concat=n=2:v=1:a=0,fps=${fps}[${vOut}]`);- filters.push(`[${aAcc}][a${j}]concat=n=2:v=0:a=1[${aOut}]`);- } else if (d > 0.01) {+ if (cross > 0.01 || d <= 0.01) {+ // The picture cuts: the segment joins the run. A cross dissolve's sound+ // ramps are already on the two segments, and the halves that reach+ // past the cut ride their own streams into the mix.+ runV.push(segLabel[j]);+ runA.push(`a${j}`);+ } else {+ const [vAcc, aAcc] = joinRun(j - 1);const offset = Math.max(0, acc - d);// The style id resolves through the allowlist map; anything unknown// (or an old spec without a style) renders as a plain fade. The shaped// and softened styles come back as xfade expressions.const kind = xfadeTransition(prev.transitionStyle, prev.transitionFeather, d, W, H);filters.push(`[${segLabel[j]}]tpad=start_duration=${num(d)}:start_mode=clone[vh${j}]`);- filters.push(`[${vAcc}][vh${j}]xfade=${kind}:duration=${num(d)}:offset=${num(offset)}[${vOut}]`);+ filters.push(`[${vAcc}][vh${j}]xfade=${kind}:duration=${num(d)}:offset=${num(offset)}[vx${j}]`);filters.push(`[${aAcc}]afade=t=out:st=${num(offset)}:d=${num(d)}[ah${j}]`);- filters.push(`[ah${j}][a${j}]concat=n=2:v=0:a=1[${aOut}]`);- } else {- // concat emits a microsecond timebase with no frame-rate stamp, and a- // later transitioned join hands this accumulator to xfade, which- // demands both of its inputs carry the same 1/fps stamp — re-stamp it.- filters.push(`[${vAcc}][${segLabel[j]}]concat=n=2:v=1:a=0,fps=${fps}[${vOut}]`);- filters.push(`[${aAcc}][a${j}]concat=n=2:v=0:a=1[${aOut}]`);+ filters.push(`[ah${j}][a${j}]concat=n=2:v=0:a=1[ax${j}]`);+ runV = [`vx${j}`];+ runA = [`ax${j}`];}acc = gridEnd(j);- vAcc = vOut;- aAcc = aOut;}+ const [vAcc, aAcc] = joinRun(spec.clips.length - 1);// Composite the video stack bottom→top: the overlay tracks draw over the// track-0 base in track order. A full-frame layer covers; a regioned one