@@ -70,12 +70,14 @@ import {
7070} from "../capture/captureCompositionFrame.js" ;
7171import {
7272 firstFrameColourArgs ,
73+ exportClipWindow ,
7374 hdrToSdrToneMapFilter ,
7475 keyframeTransferArgs ,
7576 parseKeyframeTransfers ,
7677 type ToneMapFrameColour ,
77- isClipVisibleAt ,
78+ isClipOnScreenAt ,
7879 isInClipWindow ,
80+ parseFpsWithDefault ,
7981 MEDIA_RENDER_ID_ATTR ,
8082 parseFirstFrameColour ,
8183 readsKeyframeTransfers ,
@@ -84,6 +86,7 @@ import {
8486 timeAtSourceTime ,
8587 type RateSpec ,
8688} from "@hyperframes/core" ;
89+ import { parseHTML } from "linkedom" ;
8790import { resolveProject } from "../utils/project.js" ;
8891import {
8992 definitiveEntryMismatchComposition ,
@@ -250,15 +253,18 @@ export function resolveSnapshotVideoFrameTime(input: {
250253 relativeTime : number ;
251254 sourceDuration : number ;
252255 compositionDuration : number ;
256+ fps ?: number ;
253257} ) : number | null {
254258 const { globalTime, clipStart, clipDuration, sourceDuration, compositionDuration } = input ;
259+ const fps = input . fps ?? 30 ;
255260 const clipEnd = clipStart + clipDuration ;
256- if ( ! isClipVisibleAt ( globalTime , clipStart , clipEnd , compositionDuration ) ) return null ;
261+ if ( ! isClipOnScreenAt ( globalTime , clipStart , clipEnd , fps , compositionDuration ) ) return null ;
262+ const onFrames = exportClipWindow ( clipStart , clipEnd , fps ) ;
257263 const relativeTime =
258264 globalTime < clipStart ? Math . max ( 0 , input . relativeTime ) : input . relativeTime ;
259265 if ( relativeTime < 0 ) return null ;
260266 const pastSource = sourceDuration > 0 && relativeTime >= sourceDuration ;
261- if ( isInClipWindow ( globalTime , clipStart , clipEnd ) && ! pastSource ) return relativeTime ;
267+ if ( isInClipWindow ( globalTime , onFrames . start , onFrames . end ) && ! pastSource ) return relativeTime ;
262268
263269 const sourceEnd = sourceDuration > 0 ? sourceDuration : relativeTime ;
264270 return Math . max ( 0 , Math . min ( relativeTime , sourceEnd - 1 / 30 ) ) ;
@@ -312,6 +318,7 @@ export function activeVideoAt(
312318 candidate : SnapshotVideoCandidate ,
313319 time : number ,
314320 compositionDuration : number ,
321+ fps : number ,
315322) {
316323 const start = resolveSnapshotVideoClipStart ( candidate ) ;
317324 const playbackRate = resolveSnapshotVideoRateSpec ( candidate ) ;
@@ -337,6 +344,7 @@ export function activeVideoAt(
337344 relativeTime : relTime ,
338345 sourceDuration : candidate . srcDuration ,
339346 compositionDuration,
347+ fps,
340348 } ) ;
341349 return frameTime === null
342350 ? null
@@ -901,6 +909,12 @@ export function computeSnapshotTimes(
901909 return { times : times . map ( round ) , appendedTail : false } ;
902910}
903911
912+ function compositionFps ( html : string ) : number {
913+ const root = parseHTML ( html ) . document . querySelector ( "[data-composition-id]" ) ;
914+ const declared = parseFpsWithDefault ( root ?. getAttribute ( "data-fps" ) ?? undefined ) ;
915+ return declared . ok ? declared . value . num / declared . value . den : 30 ;
916+ }
917+
904918export function serveCapturePage ( projectDir : string , html : string , proxy : boolean | undefined ) {
905919 return serveStaticProjectHtml ( projectDir , html , undefined , [ ] , proxy === true ) ;
906920}
@@ -971,6 +985,7 @@ export async function captureSnapshots(
971985 console . warn ( ` ${ c . warn ( "⚠" ) } ${ swallowed } ` ) ;
972986 }
973987 const server = await serveCapturePage ( projectDir , html , opts . autoProxy ) ;
988+ const fps = compositionFps ( html ) ;
974989 const heldVideoIds = localVideoRenderIds ( html ) ;
975990 const heldProbes = new Map < string , Promise < HeldVideoProbe > > ( ) ;
976991 const heldHints = await heldVideoHints ( projectDir , localVideos ( html ) , heldProbes ) ;
@@ -1270,7 +1285,7 @@ export async function captureSnapshots(
12701285 ) ;
12711286 let unreadable = 0 ;
12721287 const active = candidates . flatMap ( ( candidate ) => {
1273- const video = activeVideoAt ( candidate , time , duration ) ;
1288+ const video = activeVideoAt ( candidate , time , duration , fps ) ;
12741289 if ( ! video ) return [ ] ;
12751290 if ( ! candidate . id || ! candidate . src ) {
12761291 unreadable += 1 ;
@@ -1314,7 +1329,7 @@ export async function captureSnapshots(
13141329 ( opts . zoom ? ( opts . zoomScale ?? DEFAULT_ZOOM_SCALE ) : v . devicePixelRatio ) ,
13151330 ) ;
13161331 const wantAt = ( t : number ) : FrameWant | null => {
1317- const shown = activeVideoAt ( v , t , duration ) ;
1332+ const shown = activeVideoAt ( v , t , duration , fps ) ;
13181333 if ( ! shown ) return null ;
13191334 const holdLastFrame =
13201335 shown . srcDuration > 0 && shown . relTime >= shown . srcDuration - 1 ;
0 commit comments