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
fix(webv2): stop the Initial Video cap gate blocking an adoptable clip
Lincoln Stein701709ff1047
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts b/invokeai/frontend/webv2/src/features/video/core/settings.test.tsindex cab2901dff..e7f6b013a4 100644--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts@@ -6,6 +6,7 @@ import { MINIMAX_H3_NUM_FRAMES_CHOICES } from './dimensions';import {applyReferenceExtendSourceVideo,applyReferenceExtendNumFrames,+ canPlaceReferenceExtendAnchor,pinReferenceExtendAnchor,clearDeletedVideoMedia,cloneVideoWidgetValues,@@ -658,6 +659,38 @@ describe('reference-extend linkage', () => {expect(adopted[1]).toMatchObject({ fromSourceVideo: true, kind: 'video' });});+ it('canPlaceReferenceExtendAnchor agrees with the setter in every state', () => {+ const video = (name: string, flagged = false) => ({+ ...VIDEO_REFERENCE,+ clip: { ...VIDEO_REFERENCE.clip, video_name: name },+ ...(flagged ? { fromSourceVideo: true } : {}),+ });+ const states: VideoReferenceItem[][] = [+ [],+ [IMAGE_REFERENCE],+ [video('a.mp4')],+ [video('a.mp4'), video('b.mp4')],+ [video('a.mp4'), video('b.mp4'), video('c.mp4')],+ // Recall's shape: three unflagged videos, one naming the source clip.+ [video('long.mp4'), video('b.mp4'), video('c.mp4')],+ [video('a.mp4'), video('b.mp4'), video('long.mp4', true)],+ ];++ for (const references of states) {+ const placed = applyReferenceExtendSourceVideo(references, source24, 3, FRAMES);+ // The setter signals refusal by returning the input array unchanged.+ const setterAccepted = placed !== references;++ expect({+ references: references.map((e) => (e.kind === 'video' ? e.clip.video_name : 'img')),+ placed: canPlaceReferenceExtendAnchor(references, source24.video_name, 3),+ }).toEqual({+ references: references.map((e) => (e.kind === 'video' ? e.clip.video_name : 'img')),+ placed: setterAccepted,+ });+ }+ });+it('applyReferenceExtendNumFrames leaves unlinked references alone', () => {const unlinked = [VIDEO_REFERENCE, IMAGE_REFERENCE];diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.tsindex de562521d2..86dea91b02 100644--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts@@ -524,6 +524,35 @@ export const pinReferenceExtendAnchor = (references: VideoReferenceItem[]): Videreturn [...references.slice(0, index), ...references.slice(index + 1), pinned];};+/**+ * Whether setting `videoName` as the Initial Video could place its anchor.+ *+ * Mirrors `applyReferenceExtendSourceVideo`'s refusal condition so the UI gate+ * cannot drift from what the setter actually does. An adoptable entry consumes+ * no slot: the flagged anchor is rewritten in place, and so is an unflagged+ * reference already naming the same clip -- which is exactly the shape recall+ * restores, since `fromSourceVideo` is panel state and never reaches metadata.+ *+ * `videoName` is the clip currently set; for a clip not yet dropped its name is+ * unknowable, so the answer is the conservative one -- whether a NEW anchor+ * would fit.+ */+export const canPlaceReferenceExtendAnchor = (+ references: VideoReferenceItem[],+ videoName: string | undefined,+ maxVideos: number+): boolean => {+ const videos = references.filter(+ (entry): entry is Extract<VideoReferenceItem, { kind: 'video' }> => entry.kind === 'video'+ );++ return (+ videos.some(+ (entry) => entry.fromSourceVideo === true || (videoName !== undefined && entry.clip.video_name === videoName)+ ) || videos.length < maxVideos+ );+};+/*** Keeps the reference list in step with the Initial Video on a reference-extend* panel (pure; the setter and the model-selection transition both use it):diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsxindex 4dec56af68..56c8a8298d 100644--- a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx@@ -11,6 +11,7 @@ import { getVideoDurationSeconds, invertVideoAspectRatioId } from '@features/vidimport {applyReferenceExtendSourceVideo,applyReferenceExtendNumFrames,+ canPlaceReferenceExtendAnchor,pinReferenceExtendAnchor,normalizeVideoWidgetValues,resolveVideoMode,@@ -404,12 +405,15 @@ export const VideoWidgetView = () => {const supportsReferences = policy.modes.includes('reference');const supportsInitialVideo = supportsExtend || referenceExtend;// Setting an Initial Video on a reference-extend panel has to place a linked- // tail reference, which needs a free video slot. With an anchor already- // present the drop only re-derives it in place, so it stays available.+ // tail reference, which needs a free video slot -- unless an existing entry+ // can be adopted, which consumes none. Deferring to the same predicate the+ // setter's refusal uses keeps the two from drifting: gating on the flag alone+ // disabled the field after a recall, which restores references UNFLAGGED+ // beside the source video, and `disabled` reaches the clip's trim sliders too+ // -- so the cutpoint could not be moved on a clip that was legitimately set.const initialVideoCapBlocked =referenceExtend &&- !values.references.some((entry) => entry.kind === 'video' && entry.fromSourceVideo === true) &&- values.references.filter((entry) => entry.kind === 'video').length >= maxVideoReferences;+ !canPlaceReferenceExtendAnchor(values.references, values.sourceVideo?.video_name, maxVideoReferences);const hasConditioningMedia = Boolean(values.firstFrameImage || values.lastFrameImage || values.sourceVideo);const derivedSourceText = dimensions ? t(`widgets.video.dimensionSource.${dimensions.source}`) : undefined;const derivedSizeText = dimensions