Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Continuing a video from the creative panel keeps its pictures and characters, up to three

Bowen Xuea136a32708d8
diff --git a/web/cast_mention.js b/web/cast_mention.js
index 51fd3ad..c49cb54 100644
--- a/web/cast_mention.js
+++ b/web/cast_mention.js
@@ -34,11 +34,13 @@ export function subjectDefinitions(subjects) {
const IMAGE = /\.(png|jpe?g|webp|bmp|tiff?)$/i;
const enabled = row => row && row.enabled !== false;
// The number H3 gives each reference picture: images in list order (connected inputs come after the list).
-function pictureNumbers(rows) {
+// A part that continues a video keeps the first CONTINUE_PICTURES of them (continuation.PICTURES_MAX).
+export const CONTINUE_PICTURES = 3;
+function pictureNumbers(rows, limit = Infinity) {
const numbers = new Map();
let count = 0;
rows.forEach((row, index) => {
- if (enabled(row) && row.role === 'reference' && IMAGE.test(row.file || '')) numbers.set(index, ++count);
+ if (enabled(row) && row.role === 'reference' && IMAGE.test(row.file || '') && count < limit) numbers.set(index, ++count);
});
return numbers;
}
@@ -78,22 +80,24 @@ export function mentionRanges(text, people) {
}
// The prompt a request carries. Characters mentioned in the text are numbered in order of first mention; one whose
-// pictures are gone is written as a plain name. `active: false` (first/last frames, a continued video) leaves every
-// name plain too, since pictures of people cannot go with those.
-export function expandCast(text, rows, {active = true} = {}) {
+// pictures are gone is written as a plain name. `active: false` (first/last frames) leaves every name plain too, since
+// pictures of people cannot go with those. `continued` (the part continues a video) lets the characters stay: the part
+// keeps the first three reference pictures and its frames come after them, so a character whose pictures are not among
+// those three is written as a plain name.
+export function expandCast(text, rows, {active = true, continued = false} = {}) {
text = String(text ?? '');
const list = Array.isArray(rows) ? rows : [];
const people = castInRows(list);
const ranges = mentionRanges(text, people);
if (!ranges.length) return {text, subjects: []};
- if (list.some(row => enabled(row) && (row.role === 'first' || row.role === 'last'))) active = false;
- const numbers = pictureNumbers(list);
+ if (!continued && list.some(row => enabled(row) && (row.role === 'first' || row.role === 'last'))) active = false;
+ const numbers = pictureNumbers(list, continued ? CONTINUE_PICTURES : Infinity);
const order = [];
let result = '', at = 0;
for (const range of ranges) {
result += text.slice(at, range.start); at = range.end;
const person = people.find(p => (p.handle ?? p.name) === range.name);
- if (!active || !person) { result += person ? person.name : range.name; continue; }
+ if (!active || !person || !person.rows.some(index => numbers.has(index))) { result += person ? person.name : range.name; continue; }
let number = order.indexOf(person) + 1;
if (!number) {
if (order.length >= MAX_PEOPLE) { result += person.name; continue; }
@@ -106,7 +110,7 @@ export function expandCast(text, rows, {active = true} = {}) {
const subjects = order.map(person => {
// Consecutive picture numbers make one range; a person whose pictures are apart gets several.
const ranges = [];
- for (const number of person.rows.map(index => numbers.get(index)).sort((a, b) => a - b)) {
+ for (const number of person.rows.map(index => numbers.get(index)).filter(Boolean).sort((a, b) => a - b)) {
const last = ranges[ranges.length - 1];
if (last && number === last[1] + 1) last[1] = number; else ranges.push([number, number]);
}
@@ -126,12 +130,13 @@ export function cardPictures(card) {
// Whether a character can be mentioned now; `reason` is the one thing in the way.
// `count` is how many pictures the card would add when only its list row is known.
-export function mentionState(rows, card, count = cardPictures(card).length) {
+export function mentionState(rows, card, count = cardPictures(card).length, {continued = false} = {}) {
const list = Array.isArray(rows) ? rows : [];
const people = castInRows(list);
if (people.some(person => person.id === card.id)) return {ok: true, present: true};
- if (list.some(row => enabled(row) && (row.role === 'first' || row.role === 'last'))) return {ok: false, reason: 'frames'};
+ if (!continued && list.some(row => enabled(row) && (row.role === 'first' || row.role === 'last'))) return {ok: false, reason: 'frames'};
if (people.length >= MAX_PEOPLE) return {ok: false, reason: 'people'};
+ if (continued && pictureNumbers(list).size >= CONTINUE_PICTURES) return {ok: false, reason: 'continued'};
if (list.filter(enabled).length + count > MAX_REFERENCES) return {ok: false, reason: 'full'};
return {ok: true, present: false};
}
diff --git a/web/freevideo.js b/web/freevideo.js
index 22b12b4..f49e512 100644
--- a/web/freevideo.js
+++ b/web/freevideo.js
@@ -247,7 +247,8 @@ function mediaPanel(node, mount = null) {
// A Generate node that continues a video takes these keyframes as pictures, so they may sit beside references.
const continuing = (node.outputs?.[0]?.links || []).some(id => {
const target = node.graph?.getNodeById(node.graph?.links[id]?.target_id);
- return target?.type === 'FreeVideoGenerate' && optionalInputValue('continue_from', target.widgets?.find(w => w.name === 'continue_from')?.value) !== '';
+ return target?.type === 'FreeVideoGenerate' && (target.freevideoContinues?.()
+ || optionalInputValue('continue_from', target.widgets?.find(w => w.name === 'continue_from')?.value) !== '');
});
const first = active.filter(row => row.role === "first").length + Number(linked('first'));
const last = active.filter(row => row.role === "last").length + Number(linked('last'));
@@ -265,7 +266,7 @@ function mediaPanel(node, mount = null) {
chip.title = source?.title || source?.type || label; connections.append(chip);
}
mode.textContent = refs ? text("Reference video · experimental", "参考生成 · 实验性") : first && last ? text("First + last frame", "首尾帧生成") : first ? text("Image to video", "图生视频") : last ? text("Last frame to video", "尾帧生成") : text("Text to video · media is optional", "文生视频 · 素材可留空");
- message(refs > 32 ? text('There are more than 32 references; remove some before generating.', '参考素材超过 32 个,可移除部分后再生成。') : (first || last) && continuing ? text("When continuing a video, the first and last frames are used as references.", "接续视频时,首尾帧会用作参考图。") : refs && (first || last) ? text("Choose keyframes or references. Disable unused cards.", "首尾帧与参考模式不能混用,请关闭本次不用的素材。") : first > 1 || last > 1 ? text("Keep only one first frame and one last frame enabled.", "首帧和尾帧各只能启用一张图片。") : text("Drop or paste files, or connect images and audio on the left.", "可拖入、粘贴文件,或连接左侧的图片和音频。"), Boolean(refs > 32 || refs && (first || last) && !continuing || first > 1 || last > 1));
+ message(refs > 32 ? text('There are more than 32 references; remove some before generating.', '参考素材超过 32 个,可移除部分后再生成。') : continuing && active.filter(row => row.role === 'reference' && mediaKind(row.file) === 'image').length > 3 ? text('When continuing, only the first 3 images are used.', '接续时只用前 3\u00a0张图片。') : (first || last) && continuing ? text("When continuing a video, the first and last frames are used as references.", "接续视频时,首尾帧会用作参考图。") : refs && (first || last) ? text("Choose keyframes or references. Disable unused cards.", "首尾帧与参考模式不能混用,请关闭本次不用的素材。") : first > 1 || last > 1 ? text("Keep only one first frame and one last frame enabled.", "首帧和尾帧各只能启用一张图片。") : text("Drop or paste files, or connect images and audio on the left.", "可拖入、粘贴文件,或连接左侧的图片和音频。"), Boolean(refs > 32 || refs && (first || last) && !continuing || first > 1 || last > 1));
if (!rows.length && !connections.childElementCount) cards.append(el("div", text("Leave empty for text to video.", "留空则为文生视频。"), "fv-empty"));
if (!rows.length && connections.childElementCount) cards.append(el('div', text('Media comes from the connected inputs; no upload is needed.', '素材来自已连接的输入,无需上传。'), 'fv-connected-card'));
rows.forEach((row, index) => {
@@ -706,7 +707,7 @@ app.registerExtension({
}
// Characters mentioned with @ travel as <Subject N> plus their definitions; the draft keeps the typed names.
const prompt = this.widgets?.find(w => w.name === 'text');
- if (prompt) { const owner = this; prompt.serializeValue = () => expandCast(prompt.value, mediaRows(owner), {active: !owner.freevideoCastOff?.()}).text; }
+ if (prompt) { const owner = this; prompt.serializeValue = () => expandCast(prompt.value, mediaRows(owner), {continued: Boolean(owner.freevideoContinues?.())}).text; }
const quality = this.widgets?.find(w => w.name === 'two_pass');
if (quality) {
quality.label = text('Two-pass acceleration', '二次采样加速');
diff --git a/web/studio.css b/web/studio.css
index 23d3269..217b126 100644
--- a/web/studio.css
+++ b/web/studio.css
@@ -170,7 +170,6 @@
@media(max-width:480px){.fv-studio .fv-header:has(.fv-view-switch){height:auto;min-height:98px;grid-template-columns:1fr auto;padding-block:10px}.fv-studio .fv-header>.fv-view-switch{grid-column:1/-1;grid-row:2}.fv-studio .fv-header>.fv-header-actions{grid-column:2;grid-row:1}.fv-studio .fv-stats{grid-template-columns:repeat(2,minmax(0,1fr))}}
.fv-studio .fv-extend-source{display:flex;align-items:center;gap:12px;margin-bottom:14px;padding:10px;border:1px solid var(--fv-border);border-radius:var(--fv-r-md);background:var(--fv-card)}
.fv-studio .fv-extend-source[hidden]{display:none}
-.fv-studio .fv-extend-active>:not(.fv-extend-source){display:none}
.fv-studio .fv-extend-source img{width:80px;height:50px;object-fit:cover;border-radius:var(--fv-r-sm)}
.fv-studio .fv-extend-source>span{flex:1;font-size:var(--fv-micro)}
.fv-studio .fv-canvas-lock{display:inline-flex;margin-left:6px;vertical-align:-3px;color:var(--fv-muted)}
diff --git a/web/studio.js b/web/studio.js
index 008e6f5..dc06279 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -514,29 +514,28 @@ export function openStudio(node, {extendFrom = null} = {}) {
};
const castBlocked = reason => ({frames: t('Not available with first and last frames', '首尾帧不能和角色同时使用'),
people: t('Up to 3 characters', '最多 3 个角色'), full: t('Up to 32 references', '参考素材最多 32 个'),
- extend: t('Not available when continuing a video', '接着生成时不能使用角色')}[reason] || '');
+ continued: t('Up to 3 images when continuing', '接续时最多 3\u00a0张')}[reason] || '');
const castPending = new Map();
function castChoices() {
if (!castLibrary || linked(node, 'text') || !castAssets()) return [];
const rows = mediaRows(node);
return castLibrary.list().filter(card => card.name).map(card => {
- const state = extension.source ? {ok: false, reason: 'extend'}
- : mentionState(rows, card, Math.min(MAX_PICTURES_EACH, Number(card.images) || 0));
+ const state = mentionState(rows, card, Math.min(MAX_PICTURES_EACH, Number(card.images) || 0), {continued: Boolean(extension.source)});
return {id: card.id, name: card.name, handle: mentionHandle(rows, card, castPending), thumb: card.thumbnail?.file ? view(card.thumbnail.file) : card.thumbnail?.url || '',
blocked: state.ok ? '' : castBlocked(state.reason)};
});
}
// The name goes into the text at once; the card's pictures follow when the full card has been read.
function mentionCharacter(person) {
- if (!castLibrary || extension.source) return false;
+ if (!castLibrary) return false;
if (castInRows(mediaRows(node)).some(entry => entry.id === person.id)) return true;
- if (!mentionState(mediaRows(node), {id: person.id}, 1).ok) return false;
+ if (!mentionState(mediaRows(node), {id: person.id}, 1, {continued: Boolean(extension.source)}).ok) return false;
const typed = person.handle || person.name;
castPending.set(person.id, typed);
castLibrary.get(person.id).then(card => {
if (disposed) return;
const rows = mediaRows(node), target = castAssets();
- if (!target || !mentionState(rows, card).ok) return;
+ if (!target || !mentionState(rows, card, undefined, {continued: Boolean(extension.source)}).ok) return;
target.field.value = JSON.stringify(withCharacter(rows, card, typed));
target.owner.graph?.change?.();
window.dispatchEvent(new CustomEvent('freevideo-media', {detail: target.owner.id}));
@@ -564,13 +563,13 @@ export function openStudio(node, {extendFrom = null} = {}) {
prompt.addEventListener('input', announceCast);
const castChanged = event => { if (String(event.detail) === String(mediaNode?.id)) { castOverlay.refresh(); references.refresh(); announceCast(); } };
window.addEventListener('freevideo-media', castChanged);
- node.freevideoCastOff = () => Boolean(extension.source);
- cleanup.push(() => { castLibrary?.destroy?.(); castLibrary = null; window.removeEventListener('freevideo-media', castChanged); prompt.removeEventListener('input', announceCast); castOverlay.dispose(); delete node.freevideoCastOff; });
+ node.freevideoContinues = () => Boolean(extension.source);
+ cleanup.push(() => { castLibrary?.destroy?.(); castLibrary = null; window.removeEventListener('freevideo-media', castChanged); prompt.removeEventListener('input', announceCast); castOverlay.dispose(); delete node.freevideoContinues; });
openCastLibrary({api, text: t, viewURL: view, uploadOne: castUpload, onChange: () => { castOverlay.refresh(); references.refresh(); }})
.then(library => { if (disposed) library?.destroy?.(); else castLibrary = library; });
let requestAssets = null;
const enhancer = createPromptEnhancer({node, input: prompt, editor: promptEditor, api, t, starter,
- prepare: text => expandCast(text, mediaRows(node), {active: !extension.source}).text,
+ prepare: text => expandCast(text, mediaRows(node), {continued: Boolean(extension.source)}).text,
// The rewrite has its own report; the video's report entry is not touched.
onReport: row => { node.freevideoPromptReportId = row.rewrite_report_id || row.report_id; },
onChange: () => { rememberPromptDraft(api, node); requestAssets?.refresh(); },
@@ -1567,6 +1566,8 @@ export function openStudio(node, {extendFrom = null} = {}) {
twoPass.checked = Boolean(source) || value(node, 'two_pass') !== false;
previewFirst.checked = !source && value(node, 'preview') === true;
prompt.value = shown(value(node, 'text')); placeholder(); enhancer.sync();
+ // The media panel and the @ list read whether a video is being continued.
+ if (mediaNode) window.dispatchEvent(new CustomEvent('freevideo-media', {detail: mediaNode.id}));
syncSamplingSteps(); syncCanvasSize(); seconds.dispatchEvent(new Event('input'));
prompt.focus({preventScroll: true});
}
diff --git a/web/studio_extend.js b/web/studio_extend.js
index a8b1dfc..31c4c03 100644
--- a/web/studio_extend.js
+++ b/web/studio_extend.js
@@ -108,9 +108,9 @@ export function extendSnapshot(snapshot, node, source, {multiple = false} = {})
// The predecessor's tail replaces the draft's first frame.
const media = copy.output[String(inputs.media?.[0])];
if (media?.class_type === 'FreeVideoMedia') {
- // The continuation's own last frames stand in for every first, last and reference item.
+ // The continuation's own last frames stand in for connected media; the panel's pictures (characters, references)
+ // go with it, and the engine keeps up to three of them (continuation.PICTURES_MAX).
for (const key of Object.keys(media.inputs)) if (key !== 'assets') delete media.inputs[key];
- if (media.inputs.assets) media.inputs.assets = '[]';
}
return copy;
}