Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Fix too-short chat videos: honor a requested duration (seconds) + longer defaults

purple671beb097695
diff --git a/src/api/__tests__/vram-handoff.test.ts b/src/api/__tests__/vram-handoff.test.ts
index 38e2fa64..6b0b87dd 100644
--- a/src/api/__tests__/vram-handoff.test.ts
+++ b/src/api/__tests__/vram-handoff.test.ts
@@ -81,7 +81,7 @@ vi.mock('../agent-context', () => ({
// settingsStore is the real module — pure, no services. The orchestrator reads
// settings.exclusiveVramMode through it; default DEFAULT_SETTINGS = 'auto'.
-import { decideUnload, vramHandoffGenerate, pollGone } from '../vram-handoff'
+import { decideUnload, vramHandoffGenerate, pollGone, resolveClip } from '../vram-handoff'
import { useSettingsStore } from '../../stores/settingsStore'
const GB = 1024 * 1024 * 1024
@@ -166,6 +166,40 @@ describe('decideUnload', () => {
})
})
+// ── resolveClip: video length from seconds/frames/fps (David: "video nur 1s") ──
+
+describe('resolveClip', () => {
+ const SVD = { defFps: 8, defFrames: 25, maxFrames: 25 }
+ const WAN = { defFps: 16, defFrames: 81, maxFrames: 161 }
+
+ it('SVD default (no args) → full 25-frame clip, not a stubby 14 (~3s @ 8fps)', () => {
+ expect(resolveClip({ prompt: 'x' }, SVD)).toEqual({ frames: 25, fps: 8 })
+ })
+
+ it('SVD seconds=2 → 16 frames @ 8fps (fits under the cap)', () => {
+ expect(resolveClip({ prompt: 'x', seconds: 2 }, SVD)).toEqual({ frames: 16, fps: 8 })
+ })
+
+ it('SVD seconds=4 → caps at 25 frames but LOWERS fps so it still lasts ~4s', () => {
+ const r = resolveClip({ prompt: 'x', seconds: 4 }, SVD)
+ expect(r.frames).toBe(25)
+ expect(r.fps).toBe(6) // 25/4 ≈ 6 → 25 frames @ 6fps ≈ 4.2s (duration honored)
+ })
+
+ it('explicit frames is respected (advanced) and clamped to the model cap', () => {
+ expect(resolveClip({ prompt: 'x', frames: 14 }, SVD)).toEqual({ frames: 14, fps: 8 })
+ expect(resolveClip({ prompt: 'x', frames: 999 }, SVD).frames).toBe(25)
+ })
+
+ it('Wan seconds=4 → 64 frames @ 16fps (text-to-video can run longer)', () => {
+ expect(resolveClip({ prompt: 'x', seconds: 4 }, WAN)).toEqual({ frames: 64, fps: 16 })
+ })
+
+ it('Wan default → the model default length', () => {
+ expect(resolveClip({ prompt: 'x' }, WAN)).toEqual({ frames: 81, fps: 16 })
+ })
+})
+
// ── helpers for the orchestrator tests ────────────────────────────
/** Program a completed history with one image output for a given promptId. */
diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.ts
index 66f50dc3..d567a177 100644
--- a/src/api/mcp/builtin-tools.ts
+++ b/src/api/mcp/builtin-tools.ts
@@ -494,6 +494,7 @@ const BUILTIN_TOOLS: MCPToolDefinition[] = [
description:
'Generate a short video clip from a text prompt via the local ComfyUI pipeline (Wan / Hunyuan / AnimateDiff backend, auto-detected). Blocks up to 10 minutes. '
+ 'USE for "make a video of", "animate", "generate a clip". '
+ + 'For a specific length pass `seconds` (e.g. seconds=4 for a 4-second clip) — prefer this over raw frames. Image-to-video (SVD) effectively tops out around 3-4 seconds; text-to-video can run longer. '
+ 'Pass `inputImage` (a filename from an earlier image_generate result) to animate a still image — image-to-video, which auto-selects an installed I2V model such as SVD; omit it for text-to-video. First installed video model is auto-selected (or pass `model`). '
+ 'Write ONE clear prompt and call this ONCE per turn — video generation is slow and ComfyUI queues parallel calls rather than speeding up. '
+ 'EXPECT A PAUSE: LU will briefly unload the chat model from VRAM to fit the (large) video model, then reload it after — typically a 30-90s swap, longer on a cold ComfyUI start. This prevents out-of-memory errors; your conversation is preserved across the swap.',
@@ -503,7 +504,8 @@ const BUILTIN_TOOLS: MCPToolDefinition[] = [
prompt: { type: 'string', description: 'Positive text description of the desired video / motion' },
negativePrompt: { type: 'string', description: 'Things to avoid (static, blurry, deformed, etc.)' },
model: { type: 'string', description: 'Optional video model filename to use. Omit to auto-select the first installed video model.' },
- frames: { type: 'number', description: 'Number of frames to generate (clamped per model defaults; e.g. ~81 for Wan). Omit for the model default.' },
+ seconds: { type: 'number', description: 'Desired clip length in seconds (e.g. 4). PREFER this over frames for "an N second video". Image-to-video (SVD) effectively maxes near 3-4s; text-to-video can be longer.' },
+ frames: { type: 'number', description: 'Advanced: exact frame count (clamped per model; e.g. ~81 for Wan, ~25 for SVD). Prefer `seconds`. Omit for the model default.' },
fps: { type: 'number', description: 'Frames per second of the output clip (e.g. 16). Omit for the model default.' },
inputImage: { type: 'string', description: 'Optional. Filename of a previously generated image to animate (image-to-video). Requires an installed I2V model such as SVD. Omit for text-to-video.' },
},
diff --git a/src/api/vram-handoff.ts b/src/api/vram-handoff.ts
index c6591c55..2ab23799 100644
--- a/src/api/vram-handoff.ts
+++ b/src/api/vram-handoff.ts
@@ -356,6 +356,10 @@ export interface VramHandoffArgs {
// Video-only
frames?: number
fps?: number
+ // Desired clip length in seconds. Preferred over raw frames for the agent —
+ // LU converts it to frames/fps per model (honoring the duration even when a
+ // model like SVD caps the frame count).
+ seconds?: number
[k: string]: unknown
}
@@ -591,8 +595,9 @@ async function generateVideo(
if (typeof args.inputImage === 'string' && args.inputImage && isI2VModel(model)) {
const { buildDynamicWorkflow } = await import('./dynamic-workflow')
const inputImage = await resolveInputImage(args.inputImage)
- const frames = clampInt(args.frames, 14, 1, 25)
- const fps = clampInt(args.fps, 8, 1, 30)
+ // SVD-XT caps ~25 frames. Default to the full clip (~3 s @ 8 fps) and honor
+ // a requested `seconds` (lowering playback fps if 25 frames can't reach it).
+ const { frames, fps } = resolveClip(args, { defFps: 8, defFrames: 25, maxFrames: 25 })
const workflow = await buildDynamicWorkflow(
{
prompt,
@@ -621,8 +626,9 @@ async function generateVideo(
// ── Text-to-video ──────────────────────────────────────────────
const defaults = MODEL_TYPE_DEFAULTS[type] ?? MODEL_TYPE_DEFAULTS.wan
const snapped = snapToVideoGrid(defaults.width, defaults.height)
- const frames = clampInt(args.frames, defaults.frames, 1, 256)
- const fps = clampInt(args.fps, defaults.fps, 1, 60)
+ // Text-to-video (Wan/Hunyuan/AnimateDiff) can run longer than SVD — honor a
+ // requested `seconds` up to a generous cap; default to the model's own length.
+ const { frames, fps } = resolveClip(args, { defFps: defaults.fps, defFrames: defaults.frames, maxFrames: Math.max(defaults.frames, 161) })
const workflow = await buildTxt2VidWorkflow(
{
@@ -704,6 +710,39 @@ function clampFloat(v: unknown, fallback: number, min: number, max: number): num
return Math.max(min, Math.min(max, n))
}
+/**
+ * Resolve a clip's (frames, fps) from the agent's optional `seconds` / `frames`
+ * / `fps`, capped to a model's frame limit.
+ *
+ * David 2026-06-03: chat videos came out ~1 s because the I2V default was a
+ * stubby 14 frames @ 8 fps. Now:
+ * - `seconds` is the preferred control → frames = round(seconds * fps).
+ * - When the requested duration needs more frames than the model can make
+ * (SVD-XT tops out ~25), we KEEP the max frames and LOWER the playback fps
+ * so the clip still LASTS ~seconds (honoring the user's "4 second video";
+ * motion is just a touch slower since SVD can't synthesize more frames).
+ * - With no `seconds` and no `frames`, default to the model's full frame count
+ * (e.g. 25 for SVD ≈ ~3 s, not 1.75 s).
+ */
+export function resolveClip(
+ args: VramHandoffArgs,
+ opts: { defFps: number; defFrames: number; maxFrames: number },
+): { frames: number; fps: number } {
+ const fpsBase = clampInt(args.fps, opts.defFps, 1, 60)
+ const wantSeconds = clampFloat(args.seconds, 0, 0, 60) // 0 = not requested
+ let frames: number
+ if (wantSeconds > 0) frames = Math.round(wantSeconds * fpsBase)
+ else if (typeof args.frames === 'number' && Number.isFinite(args.frames)) frames = Math.round(args.frames)
+ else frames = opts.defFrames
+ frames = Math.max(1, Math.min(opts.maxFrames, frames))
+ let fps = fpsBase
+ // Duration won't fit at fpsBase (frame cap hit) → slow playback to honor it.
+ if (wantSeconds > 0 && frames / fpsBase < wantSeconds - 0.25) {
+ fps = Math.max(4, Math.min(60, Math.round(frames / wantSeconds)))
+ }
+ return { frames, fps }
+}
+
/**
* Turn an `inputImage` argument (a prior generate result's filename, or a /view
* URL) into a filename inside ComfyUI's *input* folder, ready for LoadImage.