Skip to content

Commit b1316e6

Browse files
fix(cli): diff stops counting a fast move as an extra cut (#6978)
A regenerated shot never lines up with a whip frame by frame, so diff listed every fast move. A jump now counts only above the original's own motion around it. fails without the fix: reads a change no stronger than the original's motion as the same fast move
1 parent 6bbda21 commit b1316e6

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎packages/cli/src/measure/diff.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join } from "node:path";
33
import { describe, expect, it } from "vitest";
44
import {
55
cellsOutside,
6+
cutsBeyondMotion,
67
diffVideos,
78
longRuns,
89
pickedFrames,
@@ -185,6 +186,28 @@ describe("person gates", () => {
185186
});
186187
});
187188

189+
describe("extra cuts", () => {
190+
const cut = (frame: number, change: number) => ({ frame, change, frames: 1 });
191+
const diffs = Array.from({ length: 100 }, (_, i) => (i >= 40 && i <= 50 ? 20 : 2));
192+
193+
it("reads a change no stronger than the original's motion as the same fast move", () => {
194+
const { extra, fast } = cutsBeyondMotion([cut(45, 25)], diffs, [], 24);
195+
expect(extra).toEqual([]);
196+
expect(fast.map((c) => c.frame)).toEqual([45]);
197+
});
198+
199+
it("keeps a real cut inside a fast move, and one where the original is still", () => {
200+
const { extra } = cutsBeyondMotion([cut(45, 60), cut(80, 14)], diffs, [], 24);
201+
expect(extra.map((c) => c.frame)).toEqual([45, 80]);
202+
});
203+
204+
it("keeps a cut a few frames off the original's, whose own change is not motion", () => {
205+
const atCut = diffs.map((d, i) => (i === 70 ? 90 : d));
206+
const { extra } = cutsBeyondMotion([cut(74, 80)], atCut, [cut(70, 90)], 24);
207+
expect(extra.map((c) => c.frame)).toEqual([74]);
208+
});
209+
});
210+
188211
describe("frame rate", () => {
189212
const original = { fps: 24, fpsText: "24" } as Parameters<typeof rateWarning>[0];
190213

‎packages/cli/src/measure/diff.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { tmpdir } from "node:os";
1717
import { basename, dirname, join, resolve } from "node:path";
1818
import { fpsToNumber, parseFps } from "@hyperframes/core";
1919
import { readCompositionFps } from "../utils/compositionFps.js";
20-
import { classifiedCuts, confirmsCut, frameChanges, signatures } from "./cuts.js";
20+
import { type Cut, classifiedCuts, confirmsCut, frameChanges, signatures } from "./cuts.js";
2121
import {
2222
drawnFrames,
2323
drawnVerdict,
@@ -67,6 +67,7 @@ const ALL_CELLS = Array.from({ length: GRID * GRID }, (_, c) => c);
6767
const WORST_GAP_S = 0.5;
6868
const SHEET_W = 960;
6969
const CUT_SLACK = 1;
70+
const OVER_MOTION = 1.5;
7071
// A segment's cell is left to its regenerated region when the region covers more than this share of it.
7172
const REGION_CELL_SHARE = 0.1;
7273
// Missing content: cells read at this width, from at most this many frames.
@@ -460,6 +461,24 @@ function outline(px: Uint8Array, w: number, [x, y, bw, bh]: number[], t = 3) {
460461
}
461462
}
462463

464+
/** Yours' unmatched cuts that stand out from the original's own motion around them, its cuts left out of that motion. */
465+
export function cutsBeyondMotion(
466+
unmatched: Cut[],
467+
diffs: number[],
468+
original: Cut[],
469+
fps: number,
470+
): { extra: Cut[]; fast: Cut[] } {
471+
const radius = Math.round(fps / 4);
472+
const atCut = (i: number) => original.some((c) => i >= c.frame - 1 && i <= c.frame + c.frames);
473+
const motion = (frame: number) => {
474+
const from = Math.max(1, frame - radius);
475+
const around = diffs.slice(from, frame + radius + 1);
476+
return Math.max(0, ...around.filter((_, i) => !atCut(from + i)));
477+
};
478+
const beyond = (c: Cut) => c.change > OVER_MOTION * motion(c.frame);
479+
return { extra: unmatched.filter(beyond), fast: unmatched.filter((c) => !beyond(c)) };
480+
}
481+
463482
function cutReport(ref: Clip, yours: Clip, k0: number, fps: number): CutReport {
464483
const [fa, fb] = [ref, yours].map((c) => signatures(c.input, c.filters).frames);
465484
const [da, db] = [frameChanges(fa!), frameChanges(fb!)];
@@ -473,14 +492,18 @@ function cutReport(ref: Clip, yours: Clip, k0: number, fps: number): CutReport {
473492
if (hit) used.add(hit.frame);
474493
else if (!(cut.soft && confirmsCut(db!, cut))) missing.push(cut.frame);
475494
}
476-
const extra = b.filter((g) => !used.has(g.frame) && !(g.soft && confirmsCut(da!, g)));
495+
const unmatched = b.filter((g) => !used.has(g.frame) && !(g.soft && confirmsCut(da!, g)));
496+
const { extra, fast } = cutsBeyondMotion(unmatched, da!, a, fps);
477497
const t = (f: number) => round((k0 + f) / fps, 3);
478498
return {
479499
reference: a.map((c) => t(c.frame)),
480500
yours: b.map((c) => t(c.frame)),
481501
missing: missing.map(t),
482502
extra: extra.map((c) => t(c.frame)),
483-
not_cuts: all.flatMap((c) => (c.kind ? [{ t: t(c.frame), kind: c.kind }] : [])),
503+
not_cuts: [
504+
...all.flatMap((c) => (c.kind ? [{ t: t(c.frame), kind: c.kind }] : [])),
505+
...fast.map((c) => ({ t: t(c.frame), kind: "fast" as const })),
506+
],
484507
pass: missing.length === 0 && extra.length === 0,
485508
};
486509
}

0 commit comments

Comments
 (0)