1- import { existsSync } from "node:fs" ;
1+ import { existsSync , mkdirSync , writeFileSync } from "node:fs" ;
22import { join } from "node:path" ;
33import { describe , expect , it } from "vitest" ;
44import {
55 cellsOutside ,
66 diffVideos ,
77 longRuns ,
88 pickedFrames ,
9+ projectRate ,
10+ rateWarning ,
911 regionRoi ,
1012 selectFilter ,
1113 wholeFrameCuts ,
@@ -183,6 +185,33 @@ describe("person gates", () => {
183185 } ) ;
184186} ) ;
185187
188+ describe ( "frame rate" , ( ) => {
189+ const original = { fps : 24 , fpsText : "24" } as Parameters < typeof rateWarning > [ 0 ] ;
190+
191+ it ( "warns when yours runs at another rate than the original" , ( ) => {
192+ expect ( rateWarning ( original , 30 ) ) . toContain ( "yours runs at 30 fps and the original at 24" ) ;
193+ expect ( rateWarning ( original , 30 ) ) . toContain ( 'data-fps="24"' ) ;
194+ expect ( rateWarning ( original , 24 ) ) . toBeUndefined ( ) ;
195+ expect (
196+ rateWarning ( { fps : 29.97 , fpsText : "30000/1001" } as typeof original , 30000 / 1001 ) ,
197+ ) . toBe ( undefined ) ;
198+ } ) ;
199+
200+ it ( "reads a project's rate from its root, and 30 when the root has none" , ( ) => {
201+ const project = ( name : string , attrs : string ) => {
202+ const path = join ( dir , name ) ;
203+ mkdirSync ( path , { recursive : true } ) ;
204+ writeFileSync (
205+ join ( path , "index.html" ) ,
206+ `<!doctype html><div data-composition-id="main" ${ attrs } ></div>` ,
207+ ) ;
208+ return path ;
209+ } ;
210+ expect ( projectRate ( project ( "rate-24" , 'data-fps="24"' ) ) ) . toBe ( 24 ) ;
211+ expect ( projectRate ( project ( "rate-none" , "" ) ) ) . toBe ( 30 ) ;
212+ } ) ;
213+ } ) ;
214+
186215describe ( "frame picks" , ( ) => {
187216 it ( "keeps a range's frames end-exclusive and renumbers them on the original's clock" , ( ) => {
188217 expect ( pickedFrames ( { kind : "range" , k0 : 3 , k1 : 6 } , 90 ) ) . toEqual ( [ 3 , 4 , 5 ] ) ;
@@ -199,6 +228,12 @@ describe.skipIf(noTools)("diffVideos", () => {
199228 loadOpenCvFirst ( ) ;
200229 const ref = noTools ? "" : clip ( "ref.mp4" , REF_ARGS ) ;
201230
231+ it ( "warns about a render at another frame rate" , async ( ) => {
232+ const yours = clip ( "rate-24.mp4" , [ "-i" , ref , "-r" , "24" ] ) ;
233+ const r = await diffVideos ( { reference : ref , yours, outDir : join ( dir , "rate" ) } ) ;
234+ expect ( r . warnings . join ( " " ) ) . toContain ( "yours runs at 24 fps" ) ;
235+ } ) ;
236+
202237 it ( "passes a video against itself" , async ( ) => {
203238 const r = await diffVideos ( { reference : ref , yours : ref , outDir : join ( dir , "same" ) } ) ;
204239 expect ( r . pass ) . toBe ( true ) ;
0 commit comments