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.

Creation panel: reuse an earlier video's prompt and settings

Bowen Xued992a0d675ef
diff --git a/freevideo_engine/comfy_library.py b/freevideo_engine/comfy_library.py
index 3f2ece8..f8469bf 100644
--- a/freevideo_engine/comfy_library.py
+++ b/freevideo_engine/comfy_library.py
@@ -19,6 +19,8 @@ from .long_paths import io_path, plain
from .system import windows
_ID = re.compile(r'\d{4}-\d{2}-\d{2}/[0-9a-f]{32}')
+# The prompt box takes 20000 characters; a character is at most 4 bytes.
+_PROMPT_BYTES = 4 * 20000
def _video(root, identity):
@@ -142,6 +144,23 @@ def list_videos(output_directory, *, before=None, limit=24):
return dict(items=rows, next=next_cursor, unreadable=sum(last is None or key > last for key in unreadable))
+def prompt_text(output_directory, identity):
+ """The text a saved video was made from, or None for a run that kept none."""
+ path = _video(output_directory, identity)
+ root = Path(output_directory).resolve() / 'FreeVideo'
+ saved = path.with_name('prompt.txt')
+ if saved.is_symlink() or not saved.resolve().is_relative_to(root):
+ raise ValueError('Saved prompt is outside the library or is a symbolic link')
+ _report(path)
+ try:
+ with os.fdopen(os.open(saved, os.O_RDONLY | getattr(os, 'O_NOFOLLOW', 0) | getattr(os, 'O_BINARY', 0)), 'rb') as stream:
+ data = stream.read(_PROMPT_BYTES + 1)
+ except FileNotFoundError:
+ return None
+ # Longer than the prompt box takes: its beginning alone is not the prompt.
+ return data.decode('utf-8').strip() if len(data) <= _PROMPT_BYTES else None
+
+
def thumbnail(output_directory, identity):
path = _video(output_directory, identity)
saved = path.with_suffix('.thumbnail.jpg')
@@ -1162,6 +1181,14 @@ def register():
except ValueError as error:
raise web.HTTPBadRequest(text=str(error)) from error
+ @server.routes.get('/freevideo/library/prompt')
+ async def prompt(request):
+ try:
+ text = await asyncio.to_thread(prompt_text, folder_paths.get_output_directory(), request.query.get('id'))
+ except (OSError, ValueError, UnicodeDecodeError):
+ raise web.HTTPNotFound(text='Prompt unavailable') from None
+ return web.json_response(dict(prompt=text), headers={'Cache-Control': 'no-store'})
+
@server.routes.get('/freevideo/library/thumbnail')
async def preview(request):
async with thumbnails:
diff --git a/web/health.js b/web/health.js
index 468ad2f..577ed0b 100644
--- a/web/health.js
+++ b/web/health.js
@@ -17,7 +17,7 @@ export const MODULES = ['chat_data.js', 'phone_model.js', 'phone.js', 'lan_acces
'editor.js', 'editor_actions.js', 'editor_lifecycle.js', 'editor_adjust.js', 'editor_adjust_picture.js', 'editor_picture_fields.js', 'editor_picture_session.js', 'editor_preview_picture.js', 'editor_entry.js', 'editor_expand.js', 'editor_export_dialog.js', 'editor_first_frame.js', 'editor_media_references.js', 'editor_references.js', 'editor_genbar.js', 'editor_geometry.js', 'editor_library.js', 'editor_menu.js', 'editor_model.js', 'editor_frame.js', 'editor_player.js', 'editor_room.js', 'editor_select.js', 'editor_state.js', 'editor_store.js', 'editor_tracks.js', 'editor_generation.js', 'editor_transport.js', 'editor_transport_model.js', 'editor_audio.js', 'editor_audio_model.js', 'editor_audio_notes.js', 'editor_audio_replace.js', 'editor_audio_rules.js', 'editor_speed.js', 'editor_speed_model.js', 'editor_failure.js', 'editor_header_fit.js',
'editor_loader.js', 'editor_text_coverage.js', 'editor_text.js', 'editor_toolbar_more.js', 'editor_text_model.js', 'editor_text_layout.js', 'editor_notes.js', 'editor_icons.js', 'dialog_keys.js', 'done_notify.js', 'failure_issue.js', 'feedback.js', 'frame_sizes.js', 'health.js', 'image_commands.js', 'image_editor.js', 'image_editor_engine.js', 'image_generation.js', 'launch_visit.js', 'launcher.js', 'length_plan.js', 'lora_triggers.js', 'lora_check.js', 'library.js', 'motion.js', 'native_errors.js', 'translate_guard.js', 'output_download.js', 'port_notice.js', 'preview_scene.js',
'progress_connection.js', 'prompt_draft.js', 'prompt_enhance.js', 'prompt_references.js', 'prompt_terms.js', 'request_assets.js', 'repair_hint.js', 'report_issue.js', 'issue_button.js', 'studio_recent.js',
- 'result_actions.js', 'sampling_effort.js', 'setup.js', 'share.js', 'share_layout.js', 'studio.js', 'studio_chain.js', 'studio_extend.js', 'studio_length.js', 'first_frame_row.js', 'replace_person.js', 'replace_state.js', 'optional_inputs.js', 'studio_queue.js', 'studio_size.js',
+ 'result_actions.js', 'result_reuse.js', 'sampling_effort.js', 'setup.js', 'share.js', 'share_layout.js', 'studio.js', 'studio_chain.js', 'studio_extend.js', 'studio_length.js', 'first_frame_row.js', 'replace_person.js', 'replace_state.js', 'optional_inputs.js', 'studio_queue.js', 'studio_size.js',
'toolbar_position.js', 'updates.js', 'view_navigation.js', 'wordmark.js', 'workspace_restore.js', 'cast_library.js', 'media_upload.js', 'whitebox_encode.js', 'whitebox_mp4.js', 'whitebox_recording.js', 'whitebox_render.js', 'whitebox_scenes.js', 'whitebox_worker.js'];
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
let visibleAt = 0;
diff --git a/web/result_actions.css b/web/result_actions.css
index b3b1b2d..584bef8 100644
--- a/web/result_actions.css
+++ b/web/result_actions.css
@@ -66,3 +66,10 @@
.fv-actions[data-unavailable=true] :is(a.fv-action[download],.fv-action-extend,.fv-share-trigger){opacity:.45;cursor:default;pointer-events:none}
.fv-action-copy .fv-copy-text{display:inline-grid;justify-items:start}
.fv-action-copy .fv-copy-text::after{content:attr(data-widest);grid-area:1/1;visibility:hidden;height:0;overflow:hidden}
+.fv-action-reuse .fv-reuse-text{display:inline-grid;justify-items:start;white-space:nowrap}
+.fv-action-reuse .fv-reuse-text::after{content:attr(data-widest);grid-area:1/1;visibility:hidden;height:0;overflow:hidden}
+.fv-action-reuse .fv-reuse-text>*{grid-area:1/1}
+.fv-reuse-done{cursor:default}
+.fv-action-reuse .fv-reuse-undo{all:unset;cursor:pointer;color:var(--fv-accent,#6db8fa);text-decoration:underline;text-underline-offset:2px}
+.fv-action-reuse .fv-reuse-undo:focus-visible{outline:2px solid var(--fv-accent,#6db8fa);outline-offset:2px;border-radius:3px}
+.fv-action-reuse[hidden]{display:none}
diff --git a/web/result_actions.js b/web/result_actions.js
index 75befcd..9197357 100644
--- a/web/result_actions.js
+++ b/web/result_actions.js
@@ -3,6 +3,7 @@ import { outputDownloadURL } from './output_download.js';
import { shareButton } from './share.js';
import { canExtend, extendText, extendSourceProblem, extendSourceState } from './studio_extend.js';
import { issueButton } from './issue_button.js';
+import { savedSettings, differs } from './result_reuse.js';
const css = document.createElement('link');
css.rel = 'stylesheet'; css.href = new URL('./result_actions.css', import.meta.url).href; document.head.append(css);
@@ -140,12 +141,64 @@ export async function copyText(text) {
try { return document.execCommand('copy'); } catch { return false; } finally { area.remove(); }
}
+// Fills the prompt, size and duration of an earlier video back into the panel. It is offered only when
+// the video kept its prompt and the panel does not already hold the same settings. Resolves to the button or null.
+// `reuse`: {now(saved), apply(saved), onEdit(listener) -> stop}
+async function reuseAction(record, t, reuse) {
+ const saved = await savedSettings(api, record);
+ if (!saved) return null;
+ const label = t('Reuse settings', '复用设置'), filled = t('Filled in', '已填入'), undoLabel = t('Undo', '撤销');
+ const widest = [label, `${filled} · ${undoLabel}`, filled].sort((a, b) => b.length - a.length)[0];
+ // The label sits over an invisible copy of the longest state, so the bar does not shift when it changes.
+ const make = (...parts) => {
+ const text = document.createElement('span'); text.className = 'fv-reuse-text'; text.dataset.widest = widest;
+ const inner = document.createElement('span'); inner.append(...parts); text.append(inner);
+ return text;
+ };
+ let timer = 0, stop = () => {}, current = null;
+ const offered = () => differs(saved, reuse.now(saved));
+ const idle = () => {
+ clearTimeout(timer); stop();
+ const button = action('button', '', 'back', 'fv-action-secondary fv-action-reuse');
+ button.lastElementChild.replaceWith(make(label));
+ button.hidden = !offered();
+ button.onclick = () => {
+ const before = reuse.now(saved), hadContent = Boolean(before.text.trim()) && differs(saved, before);
+ reuse.apply(saved); show(hadContent ? before : null);
+ };
+ stop = reuse.onEdit(() => {
+ if (!button.isConnected) { stop(); return; }
+ button.hidden = !offered();
+ });
+ swap(button);
+ };
+ // A later state takes the place of the button in the bar.
+ const swap = next => { if (current?.parentNode) current.replaceWith(next); current = next; };
+ const show = before => {
+ clearTimeout(timer); stop();
+ const chip = document.createElement('span'); chip.className = 'fv-action fv-action-secondary fv-action-reuse fv-reuse-done';
+ chip.setAttribute('role', 'status');
+ chip.append(icon('back'));
+ const parts = [before ? `${filled} · ` : filled];
+ if (before) {
+ const undo = document.createElement('button'); undo.type = 'button'; undo.className = 'fv-reuse-undo'; undo.textContent = undoLabel;
+ undo.onclick = () => { reuse.apply(before); idle(); };
+ parts.push(undo);
+ }
+ chip.append(make(...parts)); swap(chip);
+ timer = setTimeout(idle, before ? 10000 : 1800);
+ if (before) stop = reuse.onEdit(() => { if (!chip.isConnected) stop(); else idle(); });
+ };
+ idle();
+ return current;
+}
+
// Download the video first; share and the report follow. A first-pass preview
// leads with `secondPass` instead, and saved creations end with `remove`.
// `diagnostic` downloads the redacted report (and may offer to send it); a
// result without one shows no report entry, because the full generation
// record keeps local paths and is not meant to be shared.
-export function resultActions(record, t, {diagnostic = null, secondPass = null, remove = null, extend = null} = {}) {
+export function resultActions(record, t, {diagnostic = null, secondPass = null, remove = null, extend = null, reuse = null} = {}) {
const bar = document.createElement('div'); bar.className = 'fv-actions';
if (secondPass) bar.append(secondPassAction(t, secondPass));
if (record.video) {
@@ -163,6 +216,7 @@ export function resultActions(record, t, {diagnostic = null, secondPass = null,
timer = setTimeout(() => { text.textContent = t('Copy path', '复制路径'); }, 1800);
};
bar.append(copy);
+ if (reuse) reuseAction(record, t, reuse).then(button => { if (button && bar.isConnected) copy.after(button); });
}
if (extend && canExtend(record)) {
const button = action('button', extendText(t, 'action'), 'extend', 'fv-action-secondary fv-action-extend');
diff --git a/web/result_reuse.js b/web/result_reuse.js
new file mode 100644
index 0000000..7963b21
--- /dev/null
+++ b/web/result_reuse.js
@@ -0,0 +1,28 @@
+// The prompt, size and duration an earlier video was made from, to fill back into the creation panel.
+const IDENTITY = /^FreeVideo\/(\d{4}-\d{2}-\d{2}\/[0-9a-f]{32})\/video\.mp4$/;
+
+// Frames a duration in seconds becomes (the model takes 17k + 5).
+export function framesOf(seconds) {
+ const requested = Math.ceil(Number(seconds) * 24);
+ return requested + ((5 - requested) % 17 + 17) % 17;
+}
+
+// Null when the video kept no prompt, or is not a saved creation.
+export async function savedSettings(api, record) {
+ const id = IDENTITY.exec(record?.video || '')?.[1], g = record.geometry;
+ if (!id || !(g?.width > 0) || !(g?.height > 0)) return null;
+ try {
+ const reply = await api.fetchApi('/freevideo/library/prompt?' + new URLSearchParams({id}), {cache: 'no-store'});
+ if (!reply.ok) return null;
+ const {prompt} = await reply.json();
+ if (typeof prompt !== 'string' || !prompt) return null;
+ const frames = Number(g.frames) > 0 ? Number(g.frames) : framesOf(g.seconds);
+ return {text: prompt, width: Number(g.width), height: Number(g.height), frames: Number.isFinite(frames) ? frames : null};
+ } catch { return null; }
+}
+
+// Whether filling the saved settings would change anything the panel can still change.
+export function differs(saved, now) {
+ return saved.text !== now.text || saved.width !== now.width || saved.height !== now.height
+ || (saved.frames !== null && saved.frames !== now.frames);
+}
diff --git a/web/studio.js b/web/studio.js
index 1dc5609..a8e7442 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -31,6 +31,7 @@ import { reconcileLoraTriggers } from './lora_triggers.js';
import { createVerdicts, describeVerdict, feedbackDraft } from './lora_check.js';
import { continuationUpscale, createSamplingEffort, effortFor, effortsFrom, passSwitch, stepCacheOf, upscaleOf } from './sampling_effort.js';
import { resultActions, previewBadge, icon, actionsUnavailable } from './result_actions.js';
+import { framesOf } from './result_reuse.js';
import { createPromptEnhancer } from './prompt_enhance.js';
import { createRequestAssets, enabledLoras, referenceFiles } from './request_assets.js';
import { promptDraftTrouble, rememberPromptDraft, restorePromptDraft, savePromptDraft, trackPromptDraft, watchPromptDraftTrouble } from './prompt_draft.js';
@@ -1371,6 +1372,41 @@ export function openStudio(node, {extendFrom = null} = {}) {
cleanup.push(() => recent.dispose());
// A run this window watched. Its result can arrive before or after the
// final progress message, and more than once; the tip stays with that video.
+ // "Reuse settings" in the result bar: what the panel holds now, filling an earlier video's settings back,
+ // and the edits that withdraw the offer. A field the panel cannot change counts as already matching.
+ let reuseApplying = false;
+ function setSize(w, h) {
+ set(node, 'width', w); set(node, 'height', h);
+ ratio = w / h; pixels = w * h / 1024 ** 2;
+ selected = [['16:9', 16 / 9], ['9:16', 9 / 16], ['1:1', 1]].find(([, r]) => Math.abs(Math.log(ratio / r)) < .035)?.[0] || 'custom';
+ node.properties.freevideo_aspect = selected; node.properties.freevideo_pixels = pixels;
+ if (![...mp.options].some(option => Number(option.value) === pixels)) { const option = el('option', `${pixels.toFixed(2)} MP`); option.value = pixels; mp.append(option); }
+ mp.value = String(pixels); syncCanvasSize();
+ }
+ const reuse = {
+ now: saved => {
+ const sizeLocked = dimensionsLinked || Boolean(extension.source), lengthLocked = linked(node, 'seconds') || Boolean(extension.source);
+ return {text: prompt.disabled ? saved.text : prompt.value, width: sizeLocked ? saved.width : Number(value(node, 'width')),
+ height: sizeLocked ? saved.height : Number(value(node, 'height')),
+ frames: lengthLocked ? saved.frames : framesOf(seconds.value), seconds: Number(seconds.value)};
+ },
+ apply: saved => {
+ reuseApplying = true;
+ try {
+ if (!prompt.disabled) { set(node, 'text', saved.text); window.dispatchEvent(new CustomEvent('freevideo-reference-prompt', {detail: node.id})); }
+ if (!dimensionsLinked && !extension.source) setSize(saved.width, saved.height);
+ if (!linked(node, 'seconds') && !extension.source) {
+ seconds.value = String(saved.seconds ?? Math.floor(saved.frames / 24 * 1000) / 1000);
+ seconds.dispatchEvent(new Event('input')); seconds.dispatchEvent(new Event('change'));
+ }
+ } finally { reuseApplying = false; }
+ },
+ onEdit: listener => {
+ const heard = () => { if (!reuseApplying) listener(); };
+ controls.addEventListener('input', heard, true); controls.addEventListener('change', heard, true);
+ return () => { controls.removeEventListener('input', heard, true); controls.removeEventListener('change', heard, true); };
+ },
+ };
let reportTipTimer = null, watchedRun = false, reportTipFor = null, shownReport = null;
// chosen: a video picked from Recent videos. It only changes the picture; a run in progress keeps its progress.
function showResult(r, {chosen = false} = {}) {
@@ -1429,7 +1465,7 @@ export function openStudio(node, {extendFrom = null} = {}) {
links.replaceChildren(resultActions(r, t, {diagnostic: reported ? downloadReport : null,
extend: saved => openExtendEditor(saved, node, {studio: dialog,
isCurrent: () => dialog.open && dialog.dataset.closing !== 'true' && topDialog() === dialog && result === r}),
- secondPass: r.preview ? secondPass(r) : null}));
+ secondPass: r.preview ? secondPass(r) : null, reuse: r.preview ? null : reuse}));
if (runButtonReady) updateExtendButton();
// After a video finished just now, point at the report menu until the
// user closes the tip once, whichever version they first saw it in.