Skip to content

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.

Merge origin/main into fix/audio-reference-extend-anchor

Lincoln Stein8f53b262f67b
diff --cc invokeai/frontend/webv2/src/features/video/core/settings.test.ts
index 324fbd7d67,829fed814d..cba342ffa2
--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
@@@ -4,9 -4,9 +4,10 @@@ import type { VideoReferenceItem, Video
import { MINIMAX_H3_NUM_FRAMES_CHOICES } from './dimensions';
import {
+ DEFAULT_REFERENCE_SAMPLE_FRAMES,
resizeReferenceSampleWindow,
slideReferenceSampleWindow,
+ anchorReferenceConditioning,
applyReferenceExtendSourceVideo,
applyReferenceExtendNumFrames,
canPlaceReferenceExtendAnchor,
diff --cc invokeai/frontend/webv2/src/features/video/core/settings.ts
index 60525a7c70,e3170bce9f..a6608e4b56
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@@ -553,42 -553,36 +553,72 @@@ export const getDefaultReferenceConditi
metadata: Record<string, unknown> | null | undefined
): VideoReferenceConditioning => (metadata?.media_origin === 'audio_upload' ? 'audio' : 'video_audio');
+/**
+ * Whether a video reference can serve as the reference-extend ANCHOR.
+ *
+ * The anchor carries the tail of the Initial Video across the seam, and that is what the
+ * generated frames continue from. An 'audio' reference contributes soundtrack rows and no
+ * visual rows at all — the backend decodes a reference's frames only when its packed kind
+ * is `video` (`reference_kind`) — so it has nothing to offer the seam. Nor does it fail
+ * loudly: the all-audio validation reason needs EVERY reference to be audio-only, so one
+ * image reference alongside is enough to let a silently discontinuous seam queue.
+ *
+ * So an audio-only reference is never CHOSEN as the anchor. Adoption and the recall
+ * re-derive both skip it, and the anchor is appended fresh instead — which keeps the
+ * soundtrack the user actually asked for rather than overwriting it with a role it cannot
+ * fill. Only an entry already claiming the flag is converted, by
+ * {@link anchorReferenceConditioning}.
+ */
+const canAnchorReferenceExtend = (entry: VideoReferenceItem): boolean =>
+ entry.kind === 'video' && entry.conditioning !== 'audio';
+
+/**
+ * The conditioning an entry keeps once it IS the reference-extend anchor.
+ *
+ * Only reached for an entry already carrying the flag: a record written before
+ * {@link canAnchorReferenceExtend} existed, or a hand-edited one. Promoting keeps the
+ * soundtrack the choice asked for and restores the visuals the role requires; 'video' and
+ * 'video_audio' are the user's own answer and pass through.
+ *
+ * Deliberately applied only where the anchor's WINDOW is re-derived alongside it
+ * (`applyReferenceExtendSourceVideo`). Promoting in normalization instead would turn an
+ * entry that was merely inert into one emitting visual rows from whatever window it
+ * happens to hold — for a mis-flagged entry, the opening of the clip rather than the tail,
+ * which is a worse seam than no anchor at all.
+ */
+export const anchorReferenceConditioning = (conditioning: VideoReferenceConditioning): VideoReferenceConditioning =>
+ conditioning === 'audio' ? 'video_audio' : conditioning;
+
+ /**
+ * The sample window a newly added video reference starts on.
+ *
+ * Footage starts on {@link DEFAULT_REFERENCE_SAMPLE_FRAMES} from the clip's head, because
+ * every reference frame is VAE-encoded into rows the denoiser re-attends at every step.
+ *
+ * An AUDIO-ONLY reference starts on the whole clip. It pays none of that cost: the backend
+ * decodes a reference's frames only when its packed kind is `video` (`reference_kind`), so
+ * an 'audio' reference contributes soundtrack rows and no visual rows at all — and those
+ * rows are bounded by the GENERATED duration, not by how long the window is. What the
+ * window decides is which audio the model hears: the track is sliced to the window and only
+ * THEN truncated to the generated duration, so a window shorter than the generation cuts
+ * the soundtrack off early. At 8s that is every frame count above 200 — over half of the
+ * ones the panel offers.
+ *
+ * Only the starting value — the card's sample-length control still trims either kind, and
+ * changing a card's conditioning afterwards leaves the window the user can see alone.
+ */
+ export const getDefaultReferenceClip = (
+ clip: VideoSourceClip,
+ conditioning: VideoReferenceConditioning
+ ): VideoSourceClip => ({
+ ...clip,
+ endFrame:
+ conditioning === 'audio'
+ ? Math.max(0, clip.numFrames - 1)
+ : Math.max(0, Math.min(DEFAULT_REFERENCE_SAMPLE_FRAMES, clip.numFrames) - 1),
+ startFrame: 0,
+ });
+
/**
* The detail a newly added image reference starts on.
*