@@ -17,7 +17,7 @@ import { tmpdir } from "node:os";
1717import { basename , dirname , join , resolve } from "node:path" ;
1818import { fpsToNumber , parseFps } from "@hyperframes/core" ;
1919import { 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" ;
2121import {
2222 drawnFrames ,
2323 drawnVerdict ,
@@ -67,6 +67,7 @@ const ALL_CELLS = Array.from({ length: GRID * GRID }, (_, c) => c);
6767const WORST_GAP_S = 0.5 ;
6868const SHEET_W = 960 ;
6969const 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.
7172const 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+
463482function 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