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): compact stacked trim rows for video references and the Initial Video

Lincoln Steindca8818b31eb
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 35fa8bebfa..adab027ce3 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -3118,9 +3118,12 @@
"removeFrame": "Remove",
"replaceClip": "Replace the initial video",
"replaceFrame": "Replace the frame image",
+ "trim": "Trim",
"trimEnd": "End Frame",
+ "trimEndShort": "End",
"trimHelp": "The kept range of the source clip. The extension continues from the end frame.",
"trimStart": "Start Frame",
+ "trimStartShort": "Start",
"unsupportedImageFile": "Please choose a PNG, JPEG, or WebP image.",
"unsupportedVideoFile": "Please choose a video file.",
"uploadClip": "Upload a video",
diff --git a/invokeai/frontend/webv2/src/features/video/ui/TrimBoundThumb.tsx b/invokeai/frontend/webv2/src/features/video/ui/TrimBoundThumb.tsx
new file mode 100644
index 0000000000..046069c3c2
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/video/ui/TrimBoundThumb.tsx
@@ -0,0 +1,69 @@
+import { Badge, Box } from '@chakra-ui/react';
+import { memo, useEffect, useRef } from 'react';
+
+/**
+ * Small always-visible preview of one trim bound. Same seek technique as the
+ * workflow editor's frame scrubber: one long-lived muted `<video>` element whose
+ * `currentTime` is set to the middle of the frame's display interval
+ * (`(frame + 0.5) / fps`), so rounding cannot show the neighbouring frame and
+ * browsers display the frame natively without a canvas roundtrip. Remounting per
+ * drag tick would spawn a range fetch per movement on multi-MB clips, hence the
+ * long-lived element (`key={src}` only).
+ *
+ * Sized for the trim rows it lives in — a fixed compact tile with the slider to
+ * its right — with the badge showing only the bound's name: the paired slider's
+ * number input already shows the frame number.
+ */
+
+const PREVIEW_VIDEO_STYLE = {
+ display: 'block',
+ height: '100%',
+ objectFit: 'contain',
+ width: '100%',
+} as const;
+
+export const TrimBoundThumb = memo(function TrimBoundThumb({
+ fps,
+ frame,
+ label,
+ src,
+}: {
+ fps: number;
+ frame: number;
+ label: string;
+ src: string;
+}) {
+ const videoRef = useRef<HTMLVideoElement | null>(null);
+
+ useEffect(() => {
+ const element = videoRef.current;
+ const time = Math.max(0, (frame + 0.5) / fps);
+
+ if (!element || !Number.isFinite(time)) {
+ return;
+ }
+
+ const seek = () => {
+ element.currentTime = time;
+ };
+
+ // Seeking before metadata arrives is ignored by some browsers; wait for it
+ // once, then seek directly on every later bound change.
+ if (element.readyState >= 1) {
+ seek();
+ } else {
+ element.addEventListener('loadedmetadata', seek, { once: true });
+
+ return () => element.removeEventListener('loadedmetadata', seek);
+ }
+ }, [fps, frame, src]);
+
+ return (
+ <Box bg="blackAlpha.300" flexShrink={0} h="14" overflow="hidden" position="relative" rounded="sm" w="20">
+ <video key={src} ref={videoRef} muted preload="metadata" src={src} style={PREVIEW_VIDEO_STYLE} />
+ <Badge bottom="0.5" insetInlineStart="0.5" pointerEvents="none" position="absolute" size="xs" variant="solid">
+ {label}
+ </Badge>
+ </Box>
+ );
+});
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index e9df66c6f4..f2e111a6c5 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -27,6 +27,7 @@ import { ArrowDownIcon, ArrowUpIcon, FilmIcon, ImagePlusIcon, XIcon } from 'luci
import { memo, useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { TrimBoundThumb } from './TrimBoundThumb';
import { useVideoUiActions } from './VideoUiContext';
/**
@@ -137,15 +138,11 @@ const ReferenceCard = memo(function ReferenceCard({
<Badge fontVariantNumeric="tabular-nums" size="xs" variant="solid">
{index + 1}
</Badge>
- <Box bg="blackAlpha.300" flexShrink={0} h="12" overflow="hidden" rounded="sm" w="16">
- <Image
- alt=""
- fit="cover"
- h="100%"
- src={reference.kind === 'video' ? galleryVideoUrls.thumbnail(name) : galleryImageUrls.thumbnail(name)}
- w="100%"
- />
- </Box>
+ {reference.kind === 'image' ? (
+ <Box bg="blackAlpha.300" flexShrink={0} h="12" overflow="hidden" rounded="sm" w="16">
+ <Image alt="" fit="cover" h="100%" src={galleryImageUrls.thumbnail(name)} w="100%" />
+ </Box>
+ ) : null}
<Stack flex="1" gap="1" minW="0">
<HStack gap="1">
{reference.kind === 'video' ? <FilmIcon size={12} /> : <ImagePlusIcon size={12} />}
@@ -163,27 +160,50 @@ 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. */}
{reference.kind === 'video' ? (
- <HStack gap="2">
- <SliderNumberField
- ariaLabel={t('widgets.video.trimStart')}
- disabled={disabled}
- max={Math.max(0, reference.clip.numFrames - 1)}
- min={0}
- step={1}
- value={reference.clip.startFrame}
- onChange={handleStartFrame}
- />
- <SliderNumberField
- ariaLabel={t('widgets.video.trimEnd')}
- disabled={disabled}
- max={Math.max(0, reference.clip.numFrames - 1)}
- min={0}
- step={1}
- value={reference.clip.endFrame}
- onChange={handleEndFrame}
- />
- </HStack>
+ <Stack gap="1">
+ <HStack gap="2">
+ <TrimBoundThumb
+ fps={reference.clip.fps}
+ frame={reference.clip.startFrame}
+ label={t('widgets.video.trimStartShort')}
+ src={galleryVideoUrls.full(name)}
+ />
+ <Box flex="1" minW="0">
+ <SliderNumberField
+ ariaLabel={t('widgets.video.trimStart')}
+ disabled={disabled}
+ max={Math.max(0, reference.clip.numFrames - 1)}
+ min={0}
+ step={1}
+ value={reference.clip.startFrame}
+ onChange={handleStartFrame}
+ />
+ </Box>
+ </HStack>
+ <HStack gap="2">
+ <TrimBoundThumb
+ fps={reference.clip.fps}
+ frame={reference.clip.endFrame}
+ label={t('widgets.video.trimEndShort')}
+ src={galleryVideoUrls.full(name)}
+ />
+ <Box flex="1" minW="0">
+ <SliderNumberField
+ ariaLabel={t('widgets.video.trimEnd')}
+ disabled={disabled}
+ max={Math.max(0, reference.clip.numFrames - 1)}
+ min={0}
+ step={1}
+ value={reference.clip.endFrame}
+ onChange={handleEndFrame}
+ />
+ </Box>
+ </HStack>
+ </Stack>
) : null}
</Stack>
<Stack gap="0">
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
index 7c58f9c915..95289d9003 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoSourceClipField.tsx
@@ -2,7 +2,7 @@ import type { DragEndEvent } from '@dnd-kit/core';
import type { VideoSourceClip } from '@features/video/core/types';
import type { ChangeEvent } from 'react';
-import { Badge, Box, HStack, Input, Spinner, Stack, Text } from '@chakra-ui/react';
+import { Box, HStack, Input, Spinner, Stack, Text } from '@chakra-ui/react';
import { useDndContext, useDndMonitor, useDroppable } from '@dnd-kit/core';
import { galleryItems, galleryTransfers } from '@features/gallery';
import { galleryVideoUrls, isGalleryItemDragData } from '@features/gallery/utility';
@@ -19,17 +19,17 @@ import { DropZone } from '@platform/ui/DropZone';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { SliderNumberField } from '@platform/ui/SliderNumberField';
import { FilmIcon, XIcon } from 'lucide-react';
-import { memo, useCallback, useEffect, useRef, useState } from 'react';
+import { memo, useCallback, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { TrimBoundThumb } from './TrimBoundThumb';
import { useVideoUiActions } from './VideoUiContext';
/**
- * The clip to extend: gallery drop target, file upload, a live frame preview,
- * and the trim bounds. The preview is a muted `<video>` element seeked to the
- * most recently adjusted trim bound (`frame / fps`) — browsers display the
- * frame natively without a canvas roundtrip, same trick as the workflow
- * editor's frame scrubber.
+ * The clip to extend: gallery drop target, file upload, and the trim bounds —
+ * one compact row per bound, the bound's live frame at left and its slider at
+ * right (see TrimBoundThumb for the seek technique). The rows are the only
+ * preview; the drop zone itself is a slim header with the clip's identity.
*/
const DROP_ID = 'video-source-clip';
@@ -42,73 +42,6 @@ const DROP_ZONE_FOCUS_PROPS = {
const DROP_ZONE_DISABLED_PROPS = { cursor: 'not-allowed', opacity: 0.6 };
const DROP_ZONE_BUSY_PROPS = { disabled: true };
const DROP_ZONE_HOVER_PROPS = { bg: 'bg.muted', color: 'fg' };
-const PREVIEW_VIDEO_STYLE = {
- display: 'block',
- height: '100%',
- objectFit: 'contain',
- width: '100%',
-} as const;
-
-/**
- * Small always-visible preview of one trim bound, so both ends of the kept
- * range stay in view while either slider moves (the large preview only follows
- * the last-touched bound). Same seek technique as the workflow editor's frame
- * scrubber: one long-lived muted element, half-frame nudge so rounding cannot
- * show the neighbouring frame.
- */
-const TrimBoundThumb = memo(function TrimBoundThumb({
- fps,
- frame,
- label,
- src,
-}: {
- fps: number;
- frame: number;
- label: string;
- src: string;
-}) {
- const videoRef = useRef<HTMLVideoElement | null>(null);
-
- useEffect(() => {
- const element = videoRef.current;
- const time = Math.max(0, (frame + 0.5) / fps);
-
- if (!element || !Number.isFinite(time)) {
- return;
- }
-
- const seek = () => {
- element.currentTime = time;
- };
-
- // Seeking before metadata arrives is ignored by some browsers; wait for it
- // once, then seek directly on every later bound change.
- if (element.readyState >= 1) {
- seek();
- } else {
- element.addEventListener('loadedmetadata', seek, { once: true });
-
- return () => element.removeEventListener('loadedmetadata', seek);
- }
- }, [fps, frame, src]);
-
- return (
- <Box bg="blackAlpha.300" flex="1" h="16" minW="0" overflow="hidden" position="relative" rounded="sm">
- <video key={src} ref={videoRef} muted preload="metadata" src={src} style={PREVIEW_VIDEO_STYLE} />
- <Badge
- bottom="1"
- fontVariantNumeric="tabular-nums"
- insetInlineStart="1"
- pointerEvents="none"
- position="absolute"
- size="xs"
- variant="solid"
- >
- {`${label} · ${frame}`}
- </Badge>
- </Box>
- );
-});
const getSingleVideoDragName = (data: unknown): string | null => {
if (!isGalleryItemDragData(data) || data.items.length !== 1) {
@@ -147,8 +80,6 @@ export const VideoSourceClipField = memo(
const fileInputRef = useRef<HTMLInputElement | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
- // Which trim bound the preview follows; the last one the user moved.
- const [previewBound, setPreviewBound] = useState<'start' | 'end'>('end');
const isInert = disabled || isLoading;
const { active } = useDndContext();
@@ -270,7 +201,6 @@ export const VideoSourceClipField = memo(
const startFrame = Math.min(Math.max(0, rawStart), Math.max(0, maxFrameIndex - 1));
- setPreviewBound('start');
onChange({ ...sourceVideo, endFrame: Math.max(startFrame + 1, sourceVideo.endFrame), startFrame });
},
[maxFrameIndex, onChange, sourceVideo]
@@ -283,29 +213,13 @@ export const VideoSourceClipField = memo(
const endFrame = Math.max(1, Math.min(rawEnd, maxFrameIndex));
- setPreviewBound('end');
onChange({ ...sourceVideo, endFrame, startFrame: Math.min(sourceVideo.startFrame, endFrame - 1) });
},
[maxFrameIndex, onChange, sourceVideo]
);
- const previewFrame = sourceVideo ? (previewBound === 'start' ? sourceVideo.startFrame : sourceVideo.endFrame) : 0;
- // Seek to the middle of the frame's display interval so rounding cannot
- // show the neighbouring frame. Seeking sets currentTime on one long-lived
- // element (the frame-scrubber trick) — remounting per drag tick would spawn
- // a range fetch per movement on multi-MB clips.
- const previewTime = sourceVideo ? Math.max(0, (previewFrame + 0.5) / sourceVideo.fps) : 0;
- const previewVideoRef = useRef<HTMLVideoElement | null>(null);
const previewSrc = sourceVideo ? galleryVideoUrls.full(sourceVideo.video_name) : null;
- useEffect(() => {
- const element = previewVideoRef.current;
-
- if (element && Number.isFinite(previewTime)) {
- element.currentTime = previewTime;
- }
- }, [previewSrc, previewTime]);
-
return (
<Stack gap="2">
<DropZone
@@ -327,24 +241,13 @@ export const VideoSourceClipField = memo(
onClick={handlePickFile}
>
{sourceVideo && previewSrc ? (
- <Stack gap="1" p="2">
- <Box bg="blackAlpha.300" h="28" overflow="hidden" rounded="sm" w="full">
- <video
- key={previewSrc}
- ref={previewVideoRef}
- muted
- preload="metadata"
- src={previewSrc}
- style={PREVIEW_VIDEO_STYLE}
- />
- </Box>
- <HStack justify="space-between" minW="0">
- <MiddleTruncate color="fg" flex="1" fontSize="xs" fontWeight="semibold" text={sourceVideo.video_name} />
- <Text color="fg.muted" flexShrink="0" fontSize="2xs" fontVariantNumeric="tabular-nums">
- {sourceVideo.width} × {sourceVideo.height} · {sourceVideo.fps} fps
- </Text>
- </HStack>
- </Stack>
+ <HStack gap="2" minW="0" p="2">
+ <FilmIcon aria-hidden="true" size={14} />
+ <MiddleTruncate color="fg" flex="1" fontSize="xs" fontWeight="semibold" text={sourceVideo.video_name} />
+ <Text color="fg.muted" flexShrink="0" fontSize="2xs" fontVariantNumeric="tabular-nums">
+ {sourceVideo.width} × {sourceVideo.height} · {sourceVideo.fps} fps
+ </Text>
+ </HStack>
) : (
<Stack align="center" color="fg.muted" gap="1.5" justify="center" minH="24" px="4">
{isLoading ? <Spinner size="sm" /> : <FilmIcon aria-hidden="true" size="18" />}
@@ -360,22 +263,6 @@ export const VideoSourceClipField = memo(
<DropTargetOverlay isActive={acceptsActiveDrag} isOver={isOver} label={t('widgets.video.dropInitialVideo')} />
</DropZone>
{sourceVideo && previewSrc ? (
- <HStack gap="2">
- <TrimBoundThumb
- fps={sourceVideo.fps}
- frame={sourceVideo.startFrame}
- label={t('widgets.video.trimStart')}
- src={previewSrc}
- />
- <TrimBoundThumb
- fps={sourceVideo.fps}
- frame={sourceVideo.endFrame}
- label={t('widgets.video.trimEnd')}
- src={previewSrc}
- />
- </HStack>
- ) : null}
- {sourceVideo ? (
<Stack gap="2">
{/* The empty-state slot shows the reason when no clip is set; with
one set, the frozen trim sliders were the only symptom. */}
@@ -384,27 +271,47 @@ export const VideoSourceClipField = memo(
{disabledReason}
</Text>
) : null}
- <Field helpText={t('widgets.video.trimHelp')} label={t('widgets.video.trimStart')}>
- <SliderNumberField
- ariaLabel={t('widgets.video.trimStart')}
- disabled={disabled}
- max={maxFrameIndex}
- min={0}
- step={1}
- value={sourceVideo.startFrame}
- onChange={setStartFrame}
- />
- </Field>
- <Field label={t('widgets.video.trimEnd')}>
- <SliderNumberField
- ariaLabel={t('widgets.video.trimEnd')}
- disabled={disabled}
- max={maxFrameIndex}
- min={0}
- step={1}
- value={sourceVideo.endFrame}
- onChange={setEndFrame}
- />
+ <Field helpText={t('widgets.video.trimHelp')} label={t('widgets.video.trim')}>
+ <Stack gap="1" w="full">
+ <HStack gap="2">
+ <TrimBoundThumb
+ fps={sourceVideo.fps}
+ frame={sourceVideo.startFrame}
+ label={t('widgets.video.trimStartShort')}
+ src={previewSrc}
+ />
+ <Box flex="1" minW="0">
+ <SliderNumberField
+ ariaLabel={t('widgets.video.trimStart')}
+ disabled={disabled}
+ max={maxFrameIndex}
+ min={0}
+ step={1}
+ value={sourceVideo.startFrame}
+ onChange={setStartFrame}
+ />
+ </Box>
+ </HStack>
+ <HStack gap="2">
+ <TrimBoundThumb
+ fps={sourceVideo.fps}
+ frame={sourceVideo.endFrame}
+ label={t('widgets.video.trimEndShort')}
+ src={previewSrc}
+ />
+ <Box flex="1" minW="0">
+ <SliderNumberField
+ ariaLabel={t('widgets.video.trimEnd')}
+ disabled={disabled}
+ max={maxFrameIndex}
+ min={0}
+ step={1}
+ value={sourceVideo.endFrame}
+ onChange={setEndFrame}
+ />
+ </Box>
+ </HStack>
+ </Stack>
</Field>
<HStack justify="end">
<Button disabled={isLoading} size="xs" variant="ghost" onClick={handleClear}>