Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): scale the reference-extend tail window to the source frame rate
Lincoln Steinfcc2fbf7868a
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex c2d988db5d..ed1267fee4 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -3165,7 +3165,7 @@"referenceDetailMax": "Max detail (2048px, slower)","referenceExtendCapFull": "No continuity reference added","referenceExtendCapFullDescription": "All 3 video reference slots are in use, so the extension has no reference sampling the initial video. Remove a video reference to add one.",- "referenceExtendHelp": "The generated video is appended to this clip at its End Frame. A linked video reference samples the last ~5 seconds (141 frames) before that cutpoint for continuity — its trim re-derives whenever the cutpoints change.",+ "referenceExtendHelp": "The generated video is appended to this clip at its End Frame. A linked video reference samples the last ~5 seconds of the clip (141 frames at 24 fps, scaled to its frame rate) before that cutpoint for continuity — its trim re-derives whenever the cutpoints change.","referenceFromInitialVideo": "Initial video","references": "References","referencesHelp": "Up to 3 videos and 9 images condition the generation, in order — reordering references changes the result. A video reference can contribute its image track, its soundtrack, or both.",diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts b/invokeai/frontend/webv2/src/features/video/core/settings.test.tsindex 2b37ce0776..bc0f042a6b 100644--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts@@ -384,14 +384,23 @@ describe('references', () => {});describe('reference-extend linkage', () => {- const longSource = { ...SOURCE_VIDEO, endFrame: 400, numFrames: 402, video_name: 'long.mp4' };+ const longSource = { ...SOURCE_VIDEO, endFrame: 400, fps: 24, numFrames: 402, video_name: 'long.mp4' };- it('derives the tail trim: 141 frames inclusive ending at the cutpoint, clamped at 0', () => {+ it('derives the tail trim: 141 frames at 24 fps ending at the cutpoint, clamped at 0', () => {expect(deriveReferenceExtendClip(longSource)).toMatchObject({ endFrame: 400, startFrame: 260 });// Shorter than the tail window: sample from the clip's own start.expect(deriveReferenceExtendClip(SOURCE_VIDEO)).toMatchObject({ endFrame: 79, startFrame: 0 });});+ it('scales the tail window to the source frame rate — a constant duration, not a constant frame count', () => {+ // 16 fps: round(141/24 * 16) = 94 frames of the same ~5.9 s.+ expect(deriveReferenceExtendClip({ ...longSource, fps: 16 })).toMatchObject({ endFrame: 400, startFrame: 307 });+ // 30 fps: round(141/24 * 30) = 176 frames.+ expect(deriveReferenceExtendClip({ ...longSource, fps: 30 })).toMatchObject({ endFrame: 400, startFrame: 225 });+ // A degenerate recorded rate falls back to the 24 fps window.+ expect(deriveReferenceExtendClip({ ...longSource, fps: 0 })).toMatchObject({ endFrame: 400, startFrame: 260 });+ });+it('prepends a linked video+audio reference and re-derives it on cutpoint changes', () => {const added = applyReferenceExtendSourceVideo([IMAGE_REFERENCE], longSource, 3);diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.tsindex 38b3eebdf8..0822cca15c 100644--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts@@ -387,21 +387,35 @@ export const createVideoSourceClip = (item: {export const MIN_VIDEO_TRIM_FRAMES = 2;/**- * Frames the reference-extend tail reference samples ahead of the cutpoint:- * ~5s of lead-in at H3's fixed 24 fps, and exactly on the 17n+5 frame grid- * (17*8+5) so the backend's snap-down keeps all of it.+ * Frames the reference-extend tail reference samples ahead of the cutpoint,+ * expressed at 24 fps: ~5s of lead-in, and exactly on the 17n+5 frame grid+ * (17*8+5) so the backend's 24 fps resample + snap-down keeps all of it. The+ * window is a DURATION — `deriveReferenceExtendClip` scales it to the source+ * clip's own frame rate, so a 16 fps source samples 94 frames of the same+ * ~5.9 s rather than 141 frames of ~8.8 s.*/export const VIDEO_REFERENCE_EXTEND_TAIL_FRAMES = 141;-/** The tail reference's default trim: the last `VIDEO_REFERENCE_EXTEND_TAIL_FRAMES` frames before the cutpoint. */-export const deriveReferenceExtendClip = (sourceVideo: VideoSourceClip): VideoSourceClip => ({- ...sourceVideo,- endFrame: sourceVideo.endFrame,- // Deliberately unclamped by the Initial Video's START cutpoint: the- // reference samples the original clip for continuity, independent of which- // portion the extension keeps.- startFrame: Math.max(0, sourceVideo.endFrame - (VIDEO_REFERENCE_EXTEND_TAIL_FRAMES - 1)),-});+const VIDEO_REFERENCE_EXTEND_TAIL_FPS = 24;++/** The tail reference's default trim: the `VIDEO_REFERENCE_EXTEND_TAIL_FRAMES`-at-24fps window before the cutpoint, in source frames. */+export const deriveReferenceExtendClip = (sourceVideo: VideoSourceClip): VideoSourceClip => {+ const fps =+ Number.isFinite(sourceVideo.fps) && sourceVideo.fps > 0 ? sourceVideo.fps : VIDEO_REFERENCE_EXTEND_TAIL_FPS;+ const tailFrames = Math.max(+ 1,+ Math.round((VIDEO_REFERENCE_EXTEND_TAIL_FRAMES / VIDEO_REFERENCE_EXTEND_TAIL_FPS) * fps)+ );++ return {+ ...sourceVideo,+ endFrame: sourceVideo.endFrame,+ // Deliberately unclamped by the Initial Video's START cutpoint: the+ // reference samples the original clip for continuity, independent of+ // which portion the extension keeps.+ startFrame: Math.max(0, sourceVideo.endFrame - (tailFrames - 1)),+ };+};/*** Keeps the reference list in step with the Initial Video on a reference-extend