Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Faceless: a long bed clip is cut to the film before its split, and the estimate says how the clip's sound is used

Claude5ebe3be38e5b
diff --git a/src/lib/catalog/faceless.ts b/src/lib/catalog/faceless.ts
index 97215736..e73eaebd 100644
--- a/src/lib/catalog/faceless.ts
+++ b/src/lib/catalog/faceless.ts
@@ -742,6 +742,8 @@ export const MUSIC_MAX: Record<string, number> = { "sonilo-music": 600, "oss-ace
/** Longest bed a loop model makes (the open loop graph's limit; the cloud's whole plays go past any film). */
export const LOOP_MAX: Record<string, number> = { "oss-audio-loop": 600 };
+/** Cuts a bed clip longer than the film before its split (your GPU; a CPU step). */
+export const BED_CUT_MODEL = "oss-trim";
/** Seconds of crossfade at each seam of a looped bed (open engine): long enough to hide the restart. */
export const BED_CROSSFADE = 3;
@@ -1168,19 +1170,30 @@ export function buildEpisodeGraph(input: GraphInput, lookup: ModelLookup): Graph
let bedStem: string | undefined;
if (models.music && models.bedClip) {
const clip = models.bedClip;
- const clipSeconds = Math.max(1, clip.duration);
+ // A clip much longer than the film is cut to the film (and a second) first: only what plays is split.
+ const need = Math.ceil(length) + 1;
+ const cut = clip.duration > need + 1;
+ const clipSeconds = cut ? need : Math.max(1, clip.duration);
bedStem = "background";
+ if (cut)
+ steps.push({
+ key: "music-cut",
+ part: "music",
+ label: "Music bed · cut to the film",
+ request: { ...base, modelId: BED_CUT_MODEL, op: "trim", inputs: { video: clip.url }, params: { startTime: 0, endTime: need }, step: { label: "Music bed cut", index: n, of: n } },
+ });
steps.push({
key: "music",
part: "music",
label: "Music bed · from your clip",
seconds: clipSeconds,
+ ...(cut && { after: ["music-cut"], chain: [{ slot: "video" as const }] }),
request: {
...base,
modelId: models.music,
op: "separate-audio",
title: `Stems · ${clip.name?.trim() || "music bed"}`,
- inputs: { video: clip.url },
+ ...(!cut && { inputs: { video: clip.url } }),
params: { sourceDuration: Math.round(clipSeconds * 1000) / 1000, extra: { channels: "mono" } },
step: { label: "Music bed", index: n, of: n },
},
diff --git a/src/server/faceless.ts b/src/server/faceless.ts
index 7b235de4..bc5a3cbc 100644
--- a/src/server/faceless.ts
+++ b/src/server/faceless.ts
@@ -11,12 +11,14 @@ import {
changedKeys,
channelName,
defaultSettings,
+ BED_CROSSFADE,
ENGINE_MODELS,
estimateGraph,
EXPLAINER_MAX,
EXPLAINER_MIN,
genreInfo,
getStyle,
+ LOOP_MAX,
MAX_SCRIPT,
MAX_SOURCES,
musicPlan,
@@ -1354,9 +1356,16 @@ function notesFor(settings: EpisodeSettings, seconds: number): { notes?: string[
const limit = styleRefLimit(settings.engine, getModel);
if (settings.styleRefs.length > limit) notes.push(`The open-source picture model follows the first ${limit} style references.`);
if (settings.engine === "open" && settings.styleRefs.length && settings.sourceImages?.length) notes.push("Your style references set the look; the attached images aren't used for the open-source pictures.");
- if (m.music) {
+ const minutes = (s: number) => `${Math.floor(s / 60)} min${s % 60 ? ` ${s % 60} s` : ""}`;
+ if (m.music && m.bedClip) {
+ // Your clip's music and effects: cut to the film when it's longer, looped (as buildEpisodeGraph plans) when shorter.
+ const clip = Math.round(m.bedClip.duration);
+ const loop = m.loop && m.bedClip.duration < seconds ? Math.min(LOOP_MAX[m.loop] ?? Infinity, Math.ceil(seconds) + 1) : null;
+ if (loop) notes.push(`Your clip's music and effects (${clip} s) loop with a ${BED_CROSSFADE}-second crossfade to cover the film.`);
+ else if (m.bedClip.duration > Math.ceil(seconds) + 2) notes.push(`Only the first ${minutes(Math.ceil(seconds) + 1)} of your clip's sound is used.`);
+ if (loop && loop < seconds) notes.push(`The music bed goes up to ${minutes(loop)}, so the last ${Math.ceil(seconds - loop)} s play without music.`);
+ } else if (m.music) {
const plan = musicPlan(getModel(m.music), m.loop ? getModel(m.loop) : undefined, seconds);
- const minutes = (s: number) => `${Math.floor(s / 60)} min${s % 60 ? ` ${s % 60} s` : ""}`;
if (plan.loop?.crossfade) notes.push(`The music is made ${minutes(plan.bed)} long, then looped with a ${plan.loop.crossfade}-second crossfade to cover the film.`);
else if (plan.loop) notes.push(`The music is made ${minutes(plan.bed)} long and plays again to cover the film.`);
if (plan.short) notes.push(`The music bed goes up to ${minutes(plan.loop?.duration ?? plan.bed)}, so the last ${plan.short} s play without music.`);
diff --git a/tests/faceless-api.test.ts b/tests/faceless-api.test.ts
index 391a572a..55efc243 100644
--- a/tests/faceless-api.test.ts
+++ b/tests/faceless-api.test.ts
@@ -186,6 +186,20 @@ describe("Episodes", () => {
expect(notes).toEqual(expect.arrayContaining([expect.stringMatching(/first 2 style references/), expect.stringMatching(/made 4 min long, then looped with a 3-second crossfade/)]));
});
+ it("a clip's soundtrack as the bed: looped when it's shorter than the film, cut when it's longer, and 8 s at least", async () => {
+ const est = (s: EpisodeSettings) => estimateRoute.POST(json("POST", { kind: "faceless", settings: s }));
+ const clip = (duration: number) => ({ ...open, length: 60, musicClip: { url: "/api/files/bed.mp4", name: "bed", duration } });
+ const short = await (await est(clip(20))).json();
+ expect(short.notes).toEqual(expect.arrayContaining([expect.stringMatching(/Your clip's music and effects \(20 s\) loop with a 3-second crossfade/)]));
+ expect(short.notes.join(" ")).not.toMatch(/made .* long/);
+ const long = await (await est(clip(900))).json();
+ expect(long.notes).toEqual(expect.arrayContaining([expect.stringMatching(/Only the first 1 min( \d+ s)? of your clip's sound is used/)]));
+ expect(long.estimate.parts.music ?? 0).toBe(0);
+ const tooShort = await est(clip(5));
+ expect(tooShort.status).toBe(400);
+ expect((await tooShort.json()).error).toMatch(/8 s or more/);
+ });
+
it(
"renders end to end in demo mode on both engines (narration timed first, then the scenes), re-runs one scene, undoes it and retries a failure",
async () => {
diff --git a/tests/original-sound.test.ts b/tests/original-sound.test.ts
index 45bf08e8..bf47a627 100644
--- a/tests/original-sound.test.ts
+++ b/tests/original-sound.test.ts
@@ -331,12 +331,23 @@ describe("Faceless clip bed", () => {
expect(mix.chain?.[2]).toEqual({ slot: "audio2" });
expect(mix.request.params?.extra).toEqual({ backgroundVolumeDb: -14 });
expect(g.some((s) => s.request.op === "music")).toBe(false);
+ expect(g.some((s) => s.key === "music-cut")).toBe(false);
expect(estimateGraph(g, getModel, ["music", "music-loop"]).parts.music ?? 0).toBe(0);
});
- it("a clip longer than the film needs no loop: the mix takes the stem itself", () => {
+ it("a clip longer than the film needs no loop and is cut to the film before its split: the mix takes the stem itself", () => {
const g = graphFor({ engine: "open", music: true, musicClip: { ...musicClip, duration: 900 } }, blocks);
expect(g.some((s) => s.key === "music-loop")).toBe(false);
+ const film = Math.ceil(blocks.reduce((n, b) => n + b.seconds, 0));
+ const cut = g.find((s) => s.key === "music-cut")!;
+ expect(cut.request).toMatchObject({ modelId: "oss-trim", op: "trim", inputs: { video: musicClip.url }, params: { startTime: 0 } });
+ const end = cut.request.params!.endTime!;
+ expect(end).toBeGreaterThanOrEqual(film);
+ expect(end).toBeLessThan(film + 3);
+ const music = g.find((s) => s.key === "music")!;
+ expect(music).toMatchObject({ after: ["music-cut"], chain: [{ slot: "video" }], seconds: end, request: { modelId: SPLIT_MODEL, params: { sourceDuration: end } } });
+ expect(music.request.inputs).toBeUndefined();
+ expect(estimateGraph(g, getModel, ["music-cut", "music"]).parts.music ?? 0).toBe(0);
const mix = g.find((s) => s.key === "mix")!;
expect(mix.after?.[2]).toBe("music");
expect(mix.chain?.[2]).toEqual({ slot: "audio2", stem: "background" });