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.

fix(webv2): default wrapped audio references to "Audio only"

Lincoln Steinbd91a753f66a
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
index 19f0ac5771..7c7ea2f3e8 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
@@ -12,6 +12,7 @@ import {
cloneVideoWidgetValues,
createVideoSourceClip,
deriveReferenceExtendClip,
+ getDefaultReferenceConditioning,
isVideoSettings,
isVideoSourceClip,
normalizeVideoSettings,
@@ -260,6 +261,23 @@ describe('createVideoSourceClip', () => {
});
});
+describe('getDefaultReferenceConditioning', () => {
+ it('starts a wrapped audio upload on its soundtrack alone', () => {
+ expect(getDefaultReferenceConditioning({ media_origin: 'audio_upload' })).toBe('audio');
+ });
+
+ it('keeps video + audio for ordinary videos', () => {
+ expect(getDefaultReferenceConditioning({ generation_mode: 'minimax_h3_ref2v' })).toBe('video_audio');
+ expect(getDefaultReferenceConditioning({ media_origin: 'something_else' })).toBe('video_audio');
+ });
+
+ it('keeps video + audio when there is no metadata to read', () => {
+ expect(getDefaultReferenceConditioning(null)).toBe('video_audio');
+ expect(getDefaultReferenceConditioning(undefined)).toBe('video_audio');
+ expect(getDefaultReferenceConditioning({})).toBe('video_audio');
+ });
+});
+
describe('clearDeletedVideoMedia', () => {
const withMedia = createSettings({
firstFrameImage: FIRST_FRAME,
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.ts
index 4cbc9cd855..d0753f261f 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@ -18,6 +18,7 @@ import type {
MiniMaxH3TargetResolution,
VideoAspectRatioId,
VideoGenerationMode,
+ VideoReferenceConditioning,
VideoReferenceItem,
VideoSettings,
VideoSourceClip,
@@ -470,6 +471,20 @@ export const createVideoSourceClip = (item: {
};
};
+/**
+ * The conditioning a video reference starts on when it is added from the gallery or an
+ * upload.
+ *
+ * Audio uploads are stored as videos: the server wraps an uploaded audio file into a
+ * rendered-waveform clip at ingest and stamps `media_origin: audio_upload` on it. Those
+ * frames are a picture of the sound rather than footage anyone means to condition on, so
+ * such a reference defaults to its soundtrack alone. Everything else keeps video + audio.
+ * This is only the starting value — the card's selector still offers all three.
+ */
+export const getDefaultReferenceConditioning = (
+ metadata: Record<string, unknown> | null | undefined
+): VideoReferenceConditioning => (metadata?.media_origin === 'audio_upload' ? 'audio' : 'video_audio');
+
/** The minimum frames a trim must keep — video_concat's crossfade consumes a 2-frame tail. */
export const MIN_VIDEO_TRIM_FRAMES = 2;
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index c990a04aa1..63f608f670 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -8,9 +8,9 @@ import type { ChangeEvent } from 'react';
import { Badge, Box, createListCollection, HStack, Image, Input, Spinner, Stack, Text } from '@chakra-ui/react';
import { useDndContext, useDndMonitor, useDroppable } from '@dnd-kit/core';
-import { galleryImages, galleryItems, galleryTransfers } from '@features/gallery';
+import { galleryImages, galleryItems, galleryTransfers, galleryVideos } from '@features/gallery';
import { galleryImageUrls, galleryVideoUrls, isGalleryItemDragData } from '@features/gallery/utility';
-import { createVideoSourceClip } from '@features/video/core/settings';
+import { createVideoSourceClip, getDefaultReferenceConditioning } from '@features/video/core/settings';
import {
assertAccountScopeCurrent,
captureAccountScope,
@@ -365,7 +365,14 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
setIsLoading(true);
try {
- const item = await galleryItems.resolve({ kind: 'video', name: videoName });
+ // Fetched alongside the resolve, not after it: the metadata only picks the
+ // card's starting conditioning, and it must not add a round trip to the add.
+ // A missing or unreadable record is not a failure -- it just means the
+ // ordinary video default.
+ const [item, metadata] = await Promise.all([
+ galleryItems.resolve({ kind: 'video', name: videoName }),
+ galleryVideos.metadata(videoName).catch(() => null),
+ ]);
if (item?.kind === 'video') {
const clip = createVideoSourceClip({
@@ -393,7 +400,7 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
// 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 },
- conditioning: 'video_audio',
+ conditioning: getDefaultReferenceConditioning(metadata),
kind: 'video',
},
];