Open source CapCut alternative.
TypeScript
fix(site): read a fade through a frame a screen recording shows twice
David Le29398ff57069
diff --git a/site/src/cut/lib/measure/cuts.test.ts b/site/src/cut/lib/measure/cuts.test.tsindex 26db27a3..bcf196c4 100644--- a/site/src/cut/lib/measure/cuts.test.ts+++ b/site/src/cut/lib/measure/cuts.test.ts@@ -247,3 +247,14 @@ test("a crossfade between two colours and a hard cut are no fades", () => {expect(hard.cuts).toEqual([4]);expect(hard.fades).toEqual([]);});++test("a fade that repeats a frame on its way, as a screen recording does, is read whole", () => {+ const frames = fadeRun({ ease: "sine.out", start: 8, frames: 16, amount: 1, tone: 0, way: "to", total: 30 });+ // Frame 13 shows frame 12 again; the rest keep their times.+ frames[13] = frames[12];+ const { cuts, fades } = scoreFrames(frames);+ expect(cuts).toEqual([]);+ expect(fades).toHaveLength(1);+ expect(fades[0].frame).toBeCloseTo(8, 0);+ expect(fades[0].frames).toBeCloseTo(16, 0);+});diff --git a/site/src/cut/lib/measure/cuts.ts b/site/src/cut/lib/measure/cuts.tsindex 51ba08f9..0bd453a8 100644--- a/site/src/cut/lib/measure/cuts.ts+++ b/site/src/cut/lib/measure/cuts.ts@@ -321,8 +321,11 @@ export function pictureFades(fines: ArrayLike<number>[]): PictureFade[] {for (let a = 1; a < fines.length; a++) {const sign = Math.sign(luma[a] - luma[a - 1]);if (!(Math.abs(luma[a] - luma[a - 1]) >= FADE_STEP)) continue;+ // A frame shown twice (a screen recording's repeat) holds the run for a+ // frame; the next step carries it on.+ const steps = (i: number) => i < fines.length && Math.sign(luma[i] - luma[i - 1]) === sign && Math.abs(luma[i] - luma[i - 1]) >= FADE_STEP;let b = a;- while (b + 1 < fines.length && Math.sign(luma[b + 1] - luma[b]) === sign && Math.abs(luma[b + 1] - luma[b]) >= FADE_STEP) b++;+ while (steps(b + 1) || (Math.abs(luma[b + 1] - luma[b]) < FADE_STEP && steps(b + 2))) b += steps(b + 1) ? 1 : 2;const run = b - a + 1;const moved = Math.abs(luma[b] - luma[a - 1]);const next = b;