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.

feat(webv2): present reference trims as a sliding sample window; add steppers

Lincoln Stein97428b5a782a
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 17154e7b0b..d802b2f99e 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -3405,6 +3405,7 @@
"removeFrame": "Remove",
"replaceClip": "Replace the initial video",
"replaceFrame": "Replace the frame image",
+ "sampleLength": "Sample Length (Frames)",
"trim": "Trim",
"trimEnd": "End Frame",
"trimEndShort": "End",
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.ts
index 4cbc9cd855..e3b0ddc9fc 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@ -79,6 +79,14 @@ export const isVideoSourceClip = (value: unknown): value is VideoSourceClip =>
export const VIDEO_REFERENCE_MAX_VIDEOS = 3;
export const VIDEO_REFERENCE_MAX_IMAGES = 9;
+/**
+ * Default sample length (in frames) for a newly added video reference. Reference rows cost
+ * VRAM in every denoise step — the packed sequence grows with reference length — so the
+ * useful sample is a short window that captures the wanted visual/audio features, not the
+ * whole clip. 200 frames ≈ 8s at the models' native 24 fps.
+ */
+export const DEFAULT_REFERENCE_SAMPLE_FRAMES = 200;
+
const VIDEO_REFERENCE_CONDITIONINGS = ['video_audio', 'video', 'audio'] as const;
const VIDEO_REFERENCE_IMAGE_DETAILS = ['max', 'match'] as const;
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index c990a04aa1..b20dc47efc 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -10,7 +10,7 @@ import { Badge, Box, createListCollection, HStack, Image, Input, Spinner, Stack,
import { useDndContext, useDndMonitor, useDroppable } from '@dnd-kit/core';
import { galleryImages, galleryItems, galleryTransfers } from '@features/gallery';
import { galleryImageUrls, galleryVideoUrls, isGalleryItemDragData } from '@features/gallery/utility';
-import { createVideoSourceClip } from '@features/video/core/settings';
+import { createVideoSourceClip, DEFAULT_REFERENCE_SAMPLE_FRAMES } from '@features/video/core/settings';
import {
assertAccountScopeCurrent,
captureAccountScope,
@@ -106,24 +106,33 @@ const ReferenceCard = memo(function ReferenceCard({
},
[index, onUpdate, reference]
);
+ // The trim is presented as a sliding sample window — start frame plus length — because
+ // what the user is choosing is "how much" (every reference frame costs denoise VRAM) and
+ // "from where". Storage stays startFrame/endFrame (the request contract): length is
+ // derived as end - start + 1, and moving the start slides the window at constant length
+ // until it hits the clip's end, where it shrinks.
const handleStartFrame = useCallback(
- (startFrame: number) => {
+ (rawStart: number) => {
if (reference.kind === 'video') {
+ const maxFrame = Math.max(0, reference.clip.numFrames - 1);
+ const sampleFrames = reference.clip.endFrame - reference.clip.startFrame + 1;
+ const startFrame = Math.min(Math.max(0, rawStart), maxFrame);
+
onUpdate(index, {
...reference,
- clip: { ...reference.clip, endFrame: Math.max(startFrame, reference.clip.endFrame), startFrame },
+ clip: { ...reference.clip, endFrame: Math.min(startFrame + sampleFrames - 1, maxFrame), startFrame },
});
}
},
[index, onUpdate, reference]
);
- const handleEndFrame = useCallback(
- (endFrame: number) => {
+ const handleSampleFrames = useCallback(
+ (rawSampleFrames: number) => {
if (reference.kind === 'video') {
- onUpdate(index, {
- ...reference,
- clip: { ...reference.clip, endFrame, startFrame: Math.min(reference.clip.startFrame, endFrame) },
- });
+ const maxFrame = Math.max(0, reference.clip.numFrames - 1);
+ const endFrame = Math.min(reference.clip.startFrame + Math.max(1, rawSampleFrames) - 1, maxFrame);
+
+ onUpdate(index, { ...reference, clip: { ...reference.clip, endFrame } });
}
},
[index, onUpdate, reference]
@@ -160,9 +169,12 @@ const ReferenceCard = memo(function ReferenceCard({
value={selectValue}
onValueChange={handleSelect}
/>
- {/* One row per trim bound: the bound's live frame at left, its slider at
- right. The seeking thumbs replace the static gallery poster for video
- references — the start-frame thumb is the card's visual identity. */}
+ {/* One row per window edge: the live frame at left, its control at right. The
+ seeking thumbs replace the static gallery poster for video references — the
+ start-frame thumb is the card's visual identity. The second row's SLIDER is
+ the sample length (the quantity that costs VRAM); its THUMB still shows the
+ resulting end frame, badged with that frame number since the number field
+ beside it shows the length, not the frame. */}
{reference.kind === 'video' ? (
<Stack gap="1">
<HStack gap="2">
@@ -178,6 +190,7 @@ const ReferenceCard = memo(function ReferenceCard({
disabled={disabled}
max={Math.max(0, reference.clip.numFrames - 1)}
min={0}
+ showStepper
step={1}
value={reference.clip.startFrame}
onChange={handleStartFrame}
@@ -188,18 +201,19 @@ const ReferenceCard = memo(function ReferenceCard({
<TrimBoundThumb
fps={reference.clip.fps}
frame={reference.clip.endFrame}
- label={t('widgets.video.trimEndShort')}
+ label={`${t('widgets.video.trimEndShort')} · ${reference.clip.endFrame}`}
src={galleryVideoUrls.full(name)}
/>
<Box flex="1" minW="0">
<SliderNumberField
- ariaLabel={t('widgets.video.trimEnd')}
+ ariaLabel={t('widgets.video.sampleLength')}
disabled={disabled}
- max={Math.max(0, reference.clip.numFrames - 1)}
- min={0}
+ max={Math.max(1, reference.clip.numFrames - reference.clip.startFrame)}
+ min={1}
+ showStepper
step={1}
- value={reference.clip.endFrame}
- onChange={handleEndFrame}
+ value={reference.clip.endFrame - reference.clip.startFrame + 1}
+ onChange={handleSampleFrames}
/>
</Box>
</HStack>
@@ -390,9 +404,15 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
return [
...current,
{
- // References are truncated to the generated duration, not joined: default to
- // the whole clip rather than the extend-mode 2-frame-tail trim.
- clip: { ...clip, endFrame: Math.max(0, clip.numFrames - 1), startFrame: 0 },
+ // Default to a short sample window from the clip's start, not the whole
+ // clip: reference frames cost denoise VRAM every step, and a few seconds
+ // captures the wanted features. (Not the extend-mode 2-frame-tail trim
+ // either — references are truncated to the generated duration, not joined.)
+ clip: {
+ ...clip,
+ endFrame: Math.max(0, Math.min(DEFAULT_REFERENCE_SAMPLE_FRAMES, clip.numFrames) - 1),
+ startFrame: 0,
+ },
conditioning: 'video_audio',
kind: 'video',
},
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
index 831e61b542..5e117198e9 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
@@ -286,6 +286,7 @@ export const VideoSourceClipField = memo(
disabled={disabled}
max={maxFrameIndex}
min={0}
+ showStepper
step={1}
value={sourceVideo.startFrame}
onChange={setStartFrame}
@@ -305,6 +306,7 @@ export const VideoSourceClipField = memo(
disabled={disabled}
max={maxFrameIndex}
min={0}
+ showStepper
step={1}
value={sourceVideo.endFrame}
onChange={setEndFrame}