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.

Editing view: a saved video put on the tracks brings the description it was generated from

Bowen Xue68e2a4a0760d
diff --git a/freevideo_engine/agent/projects.py b/freevideo_engine/agent/projects.py
index 26a0252..2dd233f 100644
--- a/freevideo_engine/agent/projects.py
+++ b/freevideo_engine/agent/projects.py
@@ -36,6 +36,8 @@ RULE_EXPECTED = {
# The note operation shares the page's 'text' code with describe; what it needed is its own.
NOTE_EXPECTED = 'picture clips and a text of at most 120 characters on one line (an empty text removes the note)'
# An agent acts on the last answer it read, so the answer that brings new picture clips asks for their notes.
+# It comes first in that answer: the project after it carries every clip's description, and a real agent
+# that printed only the start of a long answer never saw a request placed after it.
NOTE_NEXT = ('Picture clips %s have no note yet. Write each one now with a note operation: in the user\'s language, '
'what is in the picture, subject first; not its position and not its progress.')
@@ -43,9 +45,7 @@ NOTE_NEXT = ('Picture clips %s have no note yet. Write each one now with a note
def note_next(result, project, ids):
missing = [clip['id'] for track in project['tracks'] if track['kind'] == 'video' for clip in track['clips']
if clip['id'] in ids and not clip.get('note')]
- if missing:
- result['next'] = NOTE_NEXT % ', '.join(missing)
- return result
+ return dict(next=NOTE_NEXT % ', '.join(missing), **result) if missing else result
def new_project(given):
@@ -244,7 +244,8 @@ class Projects:
# Operations ----------------------------------------------------------------------------------------
def _media(self, operations):
- """Insert operations name a source key; the server fills in its length and streams."""
+ """Insert operations name a source key; the server fills in its length and streams, and for a
+ saved video the description it was generated from."""
keys = [op['source'] for op in operations if op.get('op') == 'insert']
found = comfy_editor.sources(self.root, keys) if keys else {}
resolved = []
@@ -258,6 +259,8 @@ class Projects:
kind, identity = op['source'].split(':', 1)
media = dict(source=dict(kind=kind, id=identity), frames=info['frames'], hasVideo=info['has_video'],
hasAudio=info['has_audio'], width=info['width'], height=info['height'])
+ if info.get('text'):
+ media['text'] = info['text']
resolved.append(dict({k: v for k, v in op.items() if k != 'source'}, media=media))
return resolved
@@ -285,7 +288,7 @@ class Projects:
operations[index] if index is not None else None, operation=index)
saved = self._save(reply['project'], ref=ref, client=client)
result = dict(project=saved, changed_clip_ids=changed_clip_ids(stored, saved), results=reply['results'])
- note_next(result, saved, set(result['changed_clip_ids']) - set(_clips(stored)))
+ result = note_next(result, saved, set(result['changed_clip_ids']) - set(_clips(stored)))
self._remember(ref, digest, result, client)
return result
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index 2fa2313..f8d8fb4 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -753,7 +753,7 @@ def project_schema(name):
if name != 'operations':
return EMPTY
fields = {
- 'insert': (dict(source=EDITOR_SOURCE, at=EDITOR_FRAME), ('source',), 'Insert picture and sound from a source. Omit at to append at the timeline end. Then write the new picture clip\'s note.'),
+ 'insert': (dict(source=EDITOR_SOURCE, at=EDITOR_FRAME), ('source',), 'Insert picture and sound from a source. Omit at to append at the timeline end. A work brings the description it was generated from. Then write the new picture clip\'s note.'),
'split': (dict(clip_ids=ids, frame=EDITOR_FRAME), ('clip_ids', 'frame'), 'Cut selected clips and their linked partners. The frame must be inside a selected segment.'),
'trim': (dict(clip_ids=ids, frame=EDITOR_FRAME, edge=enum(('start', 'end'))), ('clip_ids', 'frame', 'edge'), 'Trim a selected edge at the frame. The frame must be inside a selected segment.'),
'remove': (dict(clip_ids=ids), ('clip_ids',), 'Remove selected clips and linked partners. Use clip IDs from this revision.'),
diff --git a/freevideo_engine/comfy_editor.py b/freevideo_engine/comfy_editor.py
index df799b4..d915d2c 100644
--- a/freevideo_engine/comfy_editor.py
+++ b/freevideo_engine/comfy_editor.py
@@ -653,6 +653,10 @@ def sources(root, keys):
if _read_json(report, 4 * 1024**2).get('success') is not True:
raise ValueError('Creation is incomplete')
media = probe(path)
+ if source['kind'] == 'work':
+ text = _work_text(root, relative)
+ if text:
+ media['text'] = text
if source['kind'] == 'import':
metadata = _read_import(root, source['id'])
media.update(preview_width=media['width'], preview_height=media['height'])
@@ -682,6 +686,23 @@ def sources(root, keys):
return result
+def _work_text(root, relative):
+ """The text a saved video was generated from; a block made from it starts with this description."""
+ try:
+ path = _safe(root, (PurePosixPath(relative).parent / 'prompt.txt').as_posix())
+ with path.open('rb') as stream:
+ data = stream.read(4 * 8000 + 1)
+ if len(data) > 4 * 8000:
+ # Longer than any description a block keeps; its beginning alone is not the description.
+ return ''
+ text = data.decode('utf-8').strip()
+ except (OSError, ValueError):
+ # Optional: an old, joined or hand-copied video has none.
+ return ''
+ # The same limit as a block's own description, so the project it lands in still saves.
+ return text if _text(text, 8000) else ''
+
+
def _read_import(root, identity):
key = (str(Path(root).resolve()), identity)
with _STATE:
diff --git a/web/editor.js b/web/editor.js
index c5d2f9f..d156095 100644
--- a/web/editor.js
+++ b/web/editor.js
@@ -435,7 +435,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given
}
const metadata = store.sources.get(sourceKey(value.source));
try { state.apply(t('Insert source', '放入素材'), record => model.insertSource(record, {
- ...value, width: metadata?.width ?? value.width, height: metadata?.height ?? value.height,
+ ...value, width: metadata?.width ?? value.width, height: metadata?.height ?? value.height, text: value.text ?? metadata?.text,
at: value.at ?? model.duration(record)}), {clearRange: state.selection !== initialSelection});
return {ok: true};
} catch (valueError) {
@@ -856,7 +856,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given
record = model.emptyProject({width: even(metadata?.width || g.width || panel.width || 1344), height: even(metadata?.height || g.height || panel.height || 768),
settings: panel.settings || null, name: t('Untitled edit', '未命名剪辑')});
record = model.insertSource(record, {source: {kind: 'work', id}, frames: metadata?.frames || g.frames || Math.round((g.seconds || 15) * 24),
- hasVideo: true, hasAudio: metadata?.has_audio ?? work.has_audio !== false, at: 0});
+ hasVideo: true, hasAudio: metadata?.has_audio ?? work.has_audio !== false, text: metadata?.text, at: 0});
if (!metadata) store.cache({[key]: {video: mediaURL(api, work.video), audio: mediaURL(api, work.video), frames: g.frames,
has_video: true, has_audio: true, path: work.video, missing: false, thumbnail: '/freevideo/library/thumbnail?' + new URLSearchParams({id})}});
}
diff --git a/web/editor_model.js b/web/editor_model.js
index 26e821d..cb83814 100644
--- a/web/editor_model.js
+++ b/web/editor_model.js
@@ -433,9 +433,19 @@ function sourceAudioTrack(record, start, frames, allowRoom = false) {
}
throw new EditError('audio_full');
}
-export function insertSource(record, {source, frames, hasVideo, hasAudio, width, height, at: position = 0}) {
- source = sourceData(source); check(whole(frames, 1) && whole(position), 'range');
+// A saved project file holds 8 MiB; every character outside plain ASCII is written there as six.
+const STORED_ROOM = 8 * 1024 * 1024 - 64 * 1024;
+function storedSize(record) {
+ const written = JSON.stringify(record); let size = written.length;
+ for (let i = 0; i < written.length; i++) { const code = written.charCodeAt(i); size += code > 126 ? 5 : code === 44 || code === 58 ? 1 : 0; }
+ return size;
+}
+// A saved video brings the description it was generated from; one that cannot be kept is left out.
+export function insertSource(record, {source, frames, hasVideo, hasAudio, width, height, at: position = 0, text = '', by = 'user'}) {
+ const given = source; source = sourceData(source); check(whole(frames, 1) && whole(position), 'range');
check(typeof hasVideo === 'boolean' && typeof hasAudio === 'boolean' && (hasVideo || hasAudio), 'source');
+ check(TEXT_BY.includes(by), 'text');
+ const words = hasVideo && typeof text === 'string' && validText(text.trim()) ? text.trim() : '';
const next = copy(record);
if (hasVideo) followFirstSize(next, width, height);
let track = trackBy(next, hasVideo ? 'v1' : 'a1');
@@ -445,11 +455,16 @@ export function insertSource(record, {source, frames, hasVideo, hasAudio, width,
const sound = available ? audioTrack(next, sourceAudioTrack(available, start, frames, true).id) : null;
applyRoom(next, start, frames, {tracks: [track.id, ...(sound ? [sound.id] : [])]});
const primary = newClip(next, track, {source, frames, start});
+ if (words) written(primary, words, by);
if (hasVideo && hasAudio) {
const mate = newClip(next, sound, {source, frames, start});
primary.link = mate.id; mate.link = primary.id;
+ if (words) written(mate, words, by);
}
- return finish(next);
+ const result = finish(next);
+ // The description is a convenience: a project it would make too large to save takes the video without it.
+ if (words && storedSize(result) > STORED_ROOM) return insertSource(record, {source: given, frames, hasVideo, hasAudio, width, height, at: position});
+ return result;
}
export function move(record, id, start) {
if (isText(find(record, id))) return changeText(record, id, {start});
diff --git a/web/editor_notes.css b/web/editor_notes.css
index e61a006..48bdd29 100644
--- a/web/editor_notes.css
+++ b/web/editor_notes.css
@@ -4,7 +4,7 @@
.fv-editor .fv-ed-notes-again{display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 8px;font-size:12px}
.fv-ed-notes-again .fv-ed-glyph{width:12px;height:12px}
.fv-editor .fv-ed-notes-again:disabled{opacity:.4}
-.fv-editor .fv-ed-notes-text{display:block;height:auto;box-sizing:border-box;width:100%;min-height:34px;max-height:94px;padding:6px 10px;resize:none;overflow-y:auto;font:13px/20px var(--fv-font);color:var(--fv-ink);background:var(--fv-bg);border:1px solid var(--fv-border);border-radius:8px}
+.fv-editor .fv-ed-notes-text{display:block;height:auto;box-sizing:border-box;width:100%;min-height:34px;max-height:98px;padding:6px 10px;resize:none;overflow-y:auto;font:13px/20px var(--fv-font);color:var(--fv-ink);background:var(--fv-bg);border:1px solid var(--fv-border);border-radius:8px}
.fv-editor .fv-ed-notes-text:focus-visible{outline:1px solid var(--fv-accent);outline-offset:-1px;border-color:var(--fv-accent)}
.fv-editor .fv-ed-notes-text:disabled{opacity:.4}
.fv-ed-notes-versions{display:flex;flex-direction:column;gap:6px;margin-top:6px}