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.

Agent: count the parts a source still being made is planned to have

Bowen Xuefb9dc2ee4403
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index 39e2156..ce01af2 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -218,7 +218,7 @@ CAPABILITIES_ZH = {
('GET', '/editor/sources/content'): '下载剪辑项目的源素材或缩略图;使用 GET /projects/{id} 返回的素材标识',
('GET', '/inbox'): '等待当前工作会话中用户的消息或答复,最多 25 秒',
('POST', '/drama/plan'): '预览多镜头影片的剧本和各镜头拍摄条数,不保存、不提交。'
- '多镜头影片可以逐镜选片;单条视频无论多长,都用一个 generate 任务',
+ '多镜头影片可以逐镜选片;单条视频(最长 60 秒)用一个 generate 任务',
('POST', '/drama'): '确认计划后开始拍摄,进度会保存;查看各条画面并逐镜选片',
('GET', '/drama'): '查看影片列表;status=active 返回未完成影片的摘要',
('GET', '/drama/{id}'): '读取待办事项 todo 和版本 revision;用 since 和 wait=25 等待变化。'
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index 1e3eb75..4681945 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -105,11 +105,12 @@ def cut_problems(spec, seconds, prefix='', *, editor=None):
return [dict(problem, got=got, message=problem['message'].replace('received None', 'received ' + got))]
-def parts_problems(spec, runner, prefix='', *, editor=None, work=None):
+def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=None):
"""One video continues through a limited number of parts; say so before anything is generated.
The chain backend refuses the same request when the chain is created, with the same sentence.
`work` is the saved video continue_from names (output-relative), or None while it cannot be told.
+ `planned` is the number of parts an unfinished job it continues will have, when that is known instead.
"""
if runner is None or spec['kind'] != 'generate' or spec.get('refine_from'):
return []
@@ -126,7 +127,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None):
earlier, needed = 0, max(runner._depths(dict(id=None, blocks=rows)).values())
else:
# A source the backend has no record of counts as one part, as it does there.
- earlier = (runner._work_parts(work, ()) if work else 1) if continued else 0
+ earlier = (runner._work_parts(work, ()) if work else planned or 1) if continued else 0
needed = earlier + count(spec['seconds'])
except (ValueError, KeyError, TypeError):
return [] # Not a chain the backend accepts; it says why when the chain is created.
@@ -578,7 +579,8 @@ class Jobs:
problems.append(schema.diagnostic(prefix + '/after', 'existing jobs or earlier batch refs', dependency))
problems.extend(continuation_problems(normalized, prefix, editor=editor))
problems.extend(parts_problems(normalized, self.port.chain_runner(), prefix, editor=editor,
- work=self.continued_work(normalized)))
+ work=self.continued_work(normalized),
+ planned=self.planned_parts(normalized, rows)))
problems.extend(cut_problems(normalized, normalized.get('seconds'), prefix, editor=editor))
try:
self.port.check(normalized)
@@ -1152,6 +1154,32 @@ class Jobs:
except Exception:
return None
+ def planned_parts(self, spec, rows=()):
+ """Parts the unfinished job a request continues will have, from that job's own plan; None when not known."""
+ from ..chain_plan import plan
+ runner, total, seen = self.port.chain_runner(), 0, set()
+ try:
+ while True:
+ identity = (spec.get('continue_from') or {}).get('from_job')
+ source = next((r for r in rows if r['id'] == identity), None) or self.jobs.get(identity)
+ if source is None or identity in seen or source['status'] not in ACTIVE:
+ return None
+ seen.add(identity)
+ spec = source['spec']
+ if spec['kind'] != 'generate' or spec.get('refine_from') or source.get('editor'):
+ return None
+ total += len(plan(spec['seconds'], continued=bool(spec.get('continue_from')))['blocks'])
+ if not spec.get('continue_from'):
+ return total
+ work = self.continued_work(spec)
+ if work is not None:
+ with runner.lock:
+ return total + runner._work_parts(work, ())
+ if 'from_job' not in spec['continue_from']:
+ return total + 1 # A source the backend has no record of counts as one part there.
+ except (ValueError, KeyError, TypeError, AttributeError):
+ return None
+
def media_file(self, row, item, name, *, target=None):
"""Resolve one media item to a file relative to ComfyUI input (frames, imports, edits)."""
folder = 'freevideo/agent/' + row['id']
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index f49e8c7..18ca54b 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -212,7 +212,8 @@ def plan(port, value, jobs=None):
from .jobs import continuation_problems, cut_problems, parts_problems
problems = continuation_problems(spec) + cut_problems(spec, spec['seconds'])
if jobs is not None:
- problems += parts_problems(spec, jobs.port.chain_runner(), work=jobs.continued_work(spec))
+ problems += parts_problems(spec, jobs.port.chain_runner(), work=jobs.continued_work(spec),
+ planned=jobs.planned_parts(spec))
if problems:
raise specs.SpecError(problems)
if jobs is not None:
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index d50ffc1..cb4ff62 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -351,7 +351,7 @@ def contracts(*, local=False):
DRAMA_OPERATIONS = {
- 'plan': ('POST', '/drama/plan', 'For a film of several shots with takes to choose from (one video, however long, is one generate job): first preview a screenplay and its take counts without saving or submitting'),
+ 'plan': ('POST', '/drama/plan', 'For a film of several shots with takes to choose from (one video of up to 60 seconds is one generate job): first preview a screenplay and its take counts without saving or submitting'),
'start': ('POST', '/drama', 'After planning, start a durable film; review sheets and choose each shot'),
'list': ('GET', '/drama', 'List films; status=active returns unfinished summaries'),
'get': ('GET', '/drama/{id}', 'Read todo and revision; use since and wait=25. If paused, stop acting and long-wait until the user continues'),