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.

Use device limits for Agent videos under 30 seconds

Bowen Xue75d58b9fed54
diff --git a/freevideo_engine/agent/errors.py b/freevideo_engine/agent/errors.py
index b5b3fdb..0ca9a44 100644
--- a/freevideo_engine/agent/errors.py
+++ b/freevideo_engine/agent/errors.py
@@ -55,7 +55,7 @@ ERRORS = {
'internal_error': (500, True, 'An internal error prevented this operation from completing.', 'Read the job list and report request_id if the error persists.'),
'local_only': (403, False, 'This endpoint does not allow requests from this peer address.', 'Run the client on the FreeVideo computer and connect using its loopback address.'),
'origin_forbidden': (403, False, 'Origin must match this FreeVideo instance; a different origin was received.', 'Open the page served by this FreeVideo instance, or use a local command-line client without Origin.'),
- 'continuation_unavailable': (409, False, 'This backend cannot continue video blocks.', 'Use an independent shot with seconds<=15, or enable a backend with continuation inputs and resume.'),
+ 'continuation_unavailable': (409, False, 'This backend cannot continue video blocks.', 'Use POST /plan for a supported single block (unknown limit: seconds<=15), or enable continuation and resume.'),
'not_resumable': (409, False, 'Only failed, interrupted or cancelled generation jobs can resume.', 'Read the job; wait for active jobs or submit a new job for a different request.'),
'idempotency_conflict': (409, False, 'This idempotency key was already used for different request content.', 'Resend the original content with this key, or use a new ref for the changed request.'),
'source_missing': (409, False, 'A completed source block is no longer available.', 'Restore the completed block before resuming, or submit a new job.'),
diff --git a/freevideo_engine/agent/forecast.py b/freevideo_engine/agent/forecast.py
index 44ba77a..cb914c1 100644
--- a/freevideo_engine/agent/forecast.py
+++ b/freevideo_engine/agent/forecast.py
@@ -1,5 +1,6 @@
"""Machine-local timing forecasts shared by planning and durable films."""
import math
+from .length import capability_table, single_frame_limit
def generation_estimate(port, spec, chain=None):
@@ -9,9 +10,9 @@ def generation_estimate(port, spec, chain=None):
reasons here so a film never invents a time for unsupported conditioning.
"""
from ..chain_plan import plan as chain_plan
- chain = chain if chain is not None else chain_plan(spec['seconds'], continued=bool(spec.get('continue_from')))
- table = port.capability_snapshot(dict(width=str(spec['width']), height=str(spec['height']),
- task=spec['task'], adapters='1' if spec['loras'] else '0'))
+ table = capability_table(port, spec)
+ chain = chain if chain is not None else chain_plan(spec['seconds'], max_frames=single_frame_limit(spec, table=table),
+ continued=bool(spec.get('continue_from')))
seconds = None
reason = table['status'] if table['status'] in ('computing', 'unavailable') else 'no_matching_estimate'
if table['status'] == 'ready' and not spec['preview'] and not spec['media']:
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index 85d2feb..610aef2 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -60,9 +60,9 @@ GUIDE = {
],
'timing': [
'Single-block frames are 24 fps on a 17n+5 grid (6 s -> 6.583 s, 10 s -> 10.125 s). '
- 'Generation uses the continuous backend. A request of up to 15 s is one generation; a longer one is made '
- 'in parts of up to 15 s (30 s is 15 + 15) that continue one another and join automatically. '
- 'Continuing (longer than 15 s, or continue_from) needs two-pass text generation: quality "light" '
+ 'Under 30 s defaults to one generation when the device supports this size and quality; unknown limits use 15 s. '
+ 'Otherwise it uses parts of up to 15 s (30 s is 15 + 15), continued and joined automatically. '
+ 'Multiple blocks or continue_from need two-pass text generation: quality "light" '
'or sampling.two_pass=true, no preview and no media. '
'Multi-block output is cut to the planned duration. POST /plan shows the chain plan. '
'A continue_from job saves a new video that holds only the added part; to hand the user one video, '
@@ -119,7 +119,7 @@ GUIDE = {
for name, (method, path, summary) in SESSION_OPERATIONS.items()],
'filming': [
'Filming is for a film of several shots, each picked from takes. One video of up to 60 seconds is one generate '
- 'job (longer requests continue and join automatically); to polish an idea first, run enhance, then generate. '
+ 'job (30 s or more, or beyond the device limit, continues and joins automatically); to polish an idea first, run enhance, then generate. '
'A film is cut into shots: see the rule "Cut by default" before making one long continued video.',
'Use drama plan → start → get → sheet → choose/reshoot → finish; inspect todo after every change.',
'At start tell the user the estimated total time; on over_budget decide whether to ask them; '
@@ -176,8 +176,7 @@ RULES = [
'Cut by default. Wherever the film can change shot, make the new shot from the reference pictures it should '
'have (cast cards, scene pictures) instead of continuing the previous video. Continue a video only for a '
'long take that cannot be cut, an action that must stay unbroken, or sound that must stay unbroken, and '
- 'continuing again and again is not recommended. Content of 16 to 29 seconds is better made as shots of '
- 'up to 15 seconds each. One video has at most 5 parts (the first and 4 '
+ 'continuing again and again is not recommended. One video has at most 5 parts (the first and 4 '
'continuations), each continued part at least 10 seconds, about 70 seconds in all; filling that is not '
'recommended. Past it, cut to a new shot.',
]
@@ -470,8 +469,8 @@ GUIDE['agent_jobs'] += [
'Keys survive restart. Batch-level ref names the whole request; row refs still name earlier dependencies.',
'Upload media content with POST /media. HTTP accepts no local absolute paths; MCP and CLI read local files '
'before uploading. Unknown fields are rejected and every batch is validated before it is recorded.',
- 'limits.seconds in the status reply is what this installation can make now. While continuation is false, '
- 'one block (15 s) is the longest video; plan and submit refuse longer requests with continuation_unavailable.',
+ 'POST /plan gives the length supported for the current size and quality. Without continuation, only a '
+ 'single block can run; unknown device limits use 15 s. Multiple blocks return continuation_unavailable.',
'One video has at most 5 parts (60 s in one request). continue_from counts the parts of the video it '
'continues; plan and submit refuse a longer one and name the longest seconds that still fits.',
'features in the status reply names what this installation offers; false means not usable now (for example '
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index a7631a9..143f3b1 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -24,6 +24,7 @@ from urllib.parse import parse_qs, urlsplit
from . import spec as specs
from . import schema, errors, assets
+from .length import single_frame_limit
from ..system import windows
ACTIVE = ('waiting', 'queued', 'running', 'cancelling')
@@ -60,9 +61,10 @@ def chain_error(code, message, next_action, *, details=None, retryable=False):
return JobError(code, message, details=details or [], next=next_action, retryable=retryable)
-def single_block(seconds):
+def single_block(spec, seconds=None):
from ..chain_plan import plan
- return plan(seconds)['single']
+ return plan(spec['seconds'] if seconds is None else seconds, max_frames=single_frame_limit(spec),
+ continued=bool(spec.get('continue_from')))['single']
def continuation_problems(spec, prefix='', *, editor=None):
@@ -73,9 +75,9 @@ def continuation_problems(spec, prefix='', *, editor=None):
if spec['kind'] != 'generate' or spec.get('refine_from'):
return []
if not (any(block['after'] for block in editor['blocks']) if editor is not None
- else spec.get('continue_from') or not single_block(spec['seconds'])):
+ else spec.get('continue_from') or not single_block(spec)):
return []
- why = ' when continuing a video or making one longer than 15 s'
+ why = ' when continuing a saved video or generating multiple blocks'
problems = []
if not spec['two_pass']:
# The quality name is a contract enum, never caller text.
@@ -94,7 +96,7 @@ def cut_problems(spec, seconds, prefix='', *, editor=None):
"""A shot cut at or after the end of the video never appears; refuse it before anything is generated."""
if spec['kind'] != 'generate' or spec.get('refine_from') or spec.get('continue_from') or seconds is None:
return []
- if any(block['after'] for block in editor['blocks']) if editor is not None else not single_block(seconds):
+ if any(block['after'] for block in editor['blocks']) if editor is not None else not single_block(spec, seconds):
return [] # Every block of a continued video reads the same text.
late = [cut for cut in specs.cut_times(spec.get('prompt')) if cut >= seconds]
if not late:
@@ -118,7 +120,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=N
from ..chain_runner import ChainTooLong
from ..chain_store import reference
limit, continued = runner.max_parts, bool(spec.get('continue_from'))
- count = lambda seconds: len(plan(seconds, continued=continued)['blocks'])
+ count = lambda seconds: len(plan(seconds, max_frames=single_frame_limit(spec), continued=continued)['blocks'])
try:
with runner.lock:
if editor is not None:
@@ -148,7 +150,7 @@ def parts_problems(spec, runner, prefix='', *, editor=None, work=None, planned=N
def continuation_unavailable():
return chain_error('continuation_unavailable', 'This backend cannot continue multiple video blocks.',
- 'Submit a new job with seconds<=15, or enable a backend with continuation inputs and resume.')
+ 'Use POST /plan for a supported single block (unknown limit: seconds<=15), or enable continuation and resume.')
def library_id(relative):
@@ -403,6 +405,9 @@ class Jobs:
self.finish(row, 'failed', error=dict(code='interrupted',
message='ComfyUI restarted while this job ran; submit it again'), save=False)
row['_restored'] = True
+ if row['kind'] == 'generate' and not row['spec'].get('refine_from'):
+ # Before device-aware Agent planning, every accepted job used the unknown limit.
+ row['spec'].setdefault('single_max_frames', None)
self.jobs[row['id']] = row
for row in self.jobs.values():
if (row['kind'] != 'generate' or row['spec'].get('refine_from')
@@ -569,7 +574,7 @@ class Jobs:
from .routes import substitute
item = substitute(item, names)
try:
- normalized = specs.normalize(item)
+ normalized = specs.normalize(item, port=self.port)
except specs.SpecError as error:
problems.extend(schema.prefix_diagnostic(e, prefix) for e in error.errors)
continue
@@ -619,7 +624,7 @@ class Jobs:
if any(block['after'] for block in row['editor']['blocks']) and not self.continuation_ready():
raise continuation_unavailable()
continue
- self.require_continuation(row['spec']['seconds'])
+ self.require_continuation(row['spec'])
if row['spec'].get('continue_from') and not self.continuation_ready():
raise continuation_unavailable()
if receipt:
@@ -697,8 +702,8 @@ class Jobs:
from ..comfy_chain import continuation_available
return continuation_available() and os.environ.get('FREEVIDEO_CHAIN_INDEPENDENT') != '1'
- def require_continuation(self, seconds):
- if not single_block(seconds) and not self.continuation_ready():
+ def require_continuation(self, spec):
+ if not single_block(spec) and not self.continuation_ready():
raise continuation_unavailable()
def require_runner(self):
@@ -1197,7 +1202,8 @@ class Jobs:
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'])
+ total += len(plan(spec['seconds'], max_frames=single_frame_limit(spec),
+ continued=bool(spec.get('continue_from')))['blocks'])
if not spec.get('continue_from'):
return total
work = self.continued_work(spec)
@@ -1278,6 +1284,7 @@ class Jobs:
return graph, extra, node
else:
payload = dict(node=node, prompt=graph, seconds=spec['seconds'],
+ max_frames=single_frame_limit(spec),
client_id='agent:' + row['id'], extra_data=extra)
if row.get('editor'):
payload.pop('seconds')
@@ -1315,7 +1322,7 @@ class Jobs:
if (any(b['state'] != 'done' and (b['after'] or b['before'])
for b in runner.records[row['chain_id']]['blocks']) if resume
else any(b['after'] for b in payload['blocks']) if row.get('editor')
- else bool(row['spec'].get('continue_from')) or not single_block(payload['seconds'])) and not self.continuation_ready():
+ else bool(row['spec'].get('continue_from')) or not single_block(row['spec'])) and not self.continuation_ready():
raise continuation_unavailable()
self.touch(row, chain_submission='creating', status='queued', queued_at=self.clock())
from ..chain_runner import ChainBusy, ChainTooLong
diff --git a/freevideo_engine/agent/length.py b/freevideo_engine/agent/length.py
new file mode 100644
index 0000000..eb4a492
--- /dev/null
+++ b/freevideo_engine/agent/length.py
@@ -0,0 +1,49 @@
+"""Studio capability limits for Agent generation plans, without hardware probing."""
+import time
+
+# A size asked for the first time is worked out in the background in about 0.1 s. The plan that asks first
+# waits for it, so it answers what the submit after it will do.
+WAIT_SECONDS = 3.
+
+
+def capability_table(port, spec, *, wait=0.):
+ query = dict(width=str(spec['width']), height=str(spec['height']),
+ task=spec['task'], adapters='1' if spec['loras'] else '0')
+ deadline = time.monotonic() + wait
+ try:
+ while True:
+ table = port.capability_snapshot(query)
+ if table.get('status') != 'computing' or time.monotonic() >= deadline:
+ return table
+ time.sleep(.05)
+ except Exception:
+ # The studio cache is advisory. Its failure retains the unknown-limit policy.
+ return dict(status='unavailable')
+
+
+def single_frame_limit(spec, *, port=None, table=None):
+ """Frame limit for this normalized size/sampling/task; unknown keeps the 15 s default.
+
+ A submitted spec pins even an unknown limit: a later cache refresh must not
+ change the accepted canvas or number of parts. Old receipts also keep their
+ unknown limit when no capability source is supplied.
+ """
+ if 'single_max_frames' in spec:
+ return spec['single_max_frames']
+ if table is None:
+ table = capability_table(port, spec, wait=WAIT_SECONDS) if port is not None else {}
+ if table.get('status') != 'ready':
+ return None
+ tiers = table.get('tiers', {})
+ tier = tiers.get(spec['quality'])
+ if tier is None:
+ tier = next((row for row in tiers.values()
+ if row.get('steps') == spec['base_steps'] and row.get('two_pass') == spec['two_pass']
+ and (not spec['two_pass'] or spec['refine_steps'] == 3)), {})
+ index = next((i for i, row in enumerate(table.get('sizes', []))
+ if (row['width'], row['height']) == (spec['width'], spec['height'])), None)
+ if index is None:
+ return None
+ maxima = tier.get('max_frames', [])
+ limit = maxima[index] if isinstance(maxima, list) and index < len(maxima) else None
+ return limit if type(limit) is int and limit > 0 else None
diff --git a/freevideo_engine/agent/mcp.py b/freevideo_engine/agent/mcp.py
index c59d259..2b683e7 100644
--- a/freevideo_engine/agent/mcp.py
+++ b/freevideo_engine/agent/mcp.py
@@ -44,7 +44,7 @@ def tool_list():
dict(name='freevideo_prompt_guide', title='H3 prompt guide', description='How to write prompts: sections, shots and cuts, camera motion, dialogue, references, short-drama tips, and a full example.', annotations=read),
dict(name='freevideo_schema', title='Job JSON Schemas', description='JSON Schemas of every job kind and of image edit recipes.', annotations=read),
dict(name='freevideo_plan', title='Plan a job', description="Validate a job without running it: actual frames/seconds, sampling passes, warnings and a time estimate from this computer's history. Same fields as freevideo_generate.", annotations=read),
- dict(name='freevideo_generate', title='Generate a video', description='Generate one video from an H3 prompt, up to 60 seconds: a longer request continues and joins into one file automatically. Prefer a new shot with its reference pictures wherever the film can cut; continue only a take, action or sound that must stay unbroken. Use this for any single video, also after freevideo_enhance_prompt; the drama tools are only for a film of several separately chosen shots. Optionally from first/last frames or references (files, local paths, or frames of earlier jobs). Returns the job; with wait, its result (video path and URL).', annotations=write),
+ dict(name='freevideo_generate', title='Generate a video', description='Generate one video from an H3 prompt, up to 60 seconds. Under 30 s defaults to one generation if the device supports this size and quality; unknown limits use 15 s. Otherwise parts continue and join automatically (30 s is 15 + 15). Prefer a new shot with its reference pictures wherever the film can cut; continue only a take, action or sound that must stay unbroken. Use this for any single video, also after freevideo_enhance_prompt; the drama tools are only for a film of several separately chosen shots. Optionally from first/last frames or references (files, local paths, or frames of earlier jobs). Returns the job; with wait, its result (video path and URL).', annotations=write),
dict(name='freevideo_submit_batch', title='Submit a storyboard', description='Submit several jobs at once. Each row is a job object with "kind" (generate default, assemble, vlm, enhance) and an optional "ref"; later rows use "@ref" wherever a job id is expected (from_job, after, clips, refine_from). FreeVideo runs them in dependency order.', annotations=write),
dict(name='freevideo_job', title='Job status', description='Status, progress, result or error of a job.', annotations=read),
dict(name='freevideo_wait', title='Wait for a job or the user', description="Wait at most 25 seconds for a job (with id) or, without id, at most 50 seconds for what the user says in FreeVideo (inbox). again=true means nothing new yet: call it again. A job wait returns early when the user says something. If the job is still active, call it again with the same ID; do not resubmit.", annotations=read),
diff --git a/freevideo_engine/agent/productions.py b/freevideo_engine/agent/productions.py
index 92af651..809b221 100644
--- a/freevideo_engine/agent/productions.py
+++ b/freevideo_engine/agent/productions.py
@@ -360,7 +360,7 @@ class Productions:
continues=shot['continues'])
if resolved['references']:
item['media'] = dict(references=deepcopy(resolved['references']))
- estimate, revision = generation_estimate(self.jobs.port, spec.normalize(item))
+ estimate, revision = generation_estimate(self.jobs.port, spec.normalize(item, port=self.jobs.port))
return dict(estimate, revision=revision)
except Exception: # Timing is optional; a forecast failure must not reject a film or job.
return dict(seconds=None, basis=None, reason='unavailable')
@@ -375,7 +375,7 @@ class Productions:
return dict(seconds=None, basis=None, reason='no_matching_estimate')
item = deepcopy(take['spec'])
item.pop('continue_from', None)
- normalized = spec.normalize(item)
+ normalized = spec.normalize(item, port=self.jobs.port)
shapes.append([normalized[k] for k in ('width', 'height', 'frames')])
current = next((j for j in state['joins'] if j['ref'] == state['current_join']), None)
transition = current['transition'] if current else state['screenplay'].get('transition', 'cut')
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index b7cd39b..cb3ba8d 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -214,7 +214,7 @@ def capabilities(port, jobs):
def plan(port, value, jobs=None):
from ..two_pass import plan as sampling_plan
from ..geometry import geometry
- spec = specs.normalize(value)
+ spec = specs.normalize(value, port=port)
result = dict(spec={k: v for k, v in spec.items() if k != 'depends_on'}, warnings=[])
if spec['kind'] != 'generate' or spec.get('refine_from'):
return result
@@ -226,7 +226,7 @@ def plan(port, value, jobs=None):
if problems:
raise specs.SpecError(problems)
if jobs is not None:
- jobs.require_continuation(spec['seconds'])
+ jobs.require_continuation(spec)
if spec.get('continue_from') and not jobs.continuation_ready():
from .jobs import continuation_unavailable
raise continuation_unavailable()
@@ -243,7 +243,9 @@ def plan(port, value, jobs=None):
if spec['width'] * spec['height'] > 2 * 1024 ** 2:
result['warnings'].append('Above 2 MP takes much longer and needs more memory')
from ..chain_plan import plan as chain_plan
- result['chain_plan'] = chain_plan(spec['seconds'], continued=bool(spec.get('continue_from')))
+ from .length import single_frame_limit
+ result['chain_plan'] = chain_plan(spec['seconds'], max_frames=single_frame_limit(spec),
+ continued=bool(spec.get('continue_from')))
from .forecast import generation_estimate
result['estimate'], result['capabilities_revision'] = generation_estimate(port, spec, result['chain_plan'])
return result
diff --git a/freevideo_engine/agent/spec.py b/freevideo_engine/agent/spec.py
index 8a9608c..8da2200 100644
--- a/freevideo_engine/agent/spec.py
+++ b/freevideo_engine/agent/spec.py
@@ -4,6 +4,7 @@ import math
import re
import secrets
from . import schema as contract
+from .length import single_frame_limit
QUALITY, ASPECTS = contract.QUALITY, contract.ASPECTS
KINDS = tuple(contract.KINDS)
@@ -149,12 +150,13 @@ def task(media):
return 'i2va' if 'first' in media else 'l2va' if 'last' in media else 't2va'
-def saved_length(canvas, seconds, continued=False):
- """Frames and seconds of the saved video. One generation keeps its aligned canvas; a longer video is
- made in blocks and joined to exactly the planned whole seconds. A continuation saves only what it adds."""
+def saved_length(canvas, spec):
+ """Saved length: one generation keeps its aligned canvas; multiple blocks are joined to the planned
+ whole seconds. A continuation saves only what it adds."""
from ..chain_plan import PlanError, plan
+ continued = bool(spec.get('continue_from'))
try:
- planned = plan(seconds, continued=continued)
+ planned = plan(spec['seconds'], max_frames=single_frame_limit(spec), continued=continued)
except PlanError:
return canvas['frames'], canvas['seconds']
if planned['single'] and not continued:
@@ -162,7 +164,7 @@ def saved_length(canvas, seconds, continued=False):
return planned['frames'], planned['frames'] / canvas['fps']
-def normalize(value):
+def normalize(value, *, port=None):
# Local Python callers retain local media refs. HTTP validates its stricter
# (content-only) schema first; the client adapts local refs before transport.
contract.validate_job(value, local=True)
@@ -180,9 +182,8 @@ def normalize(value):
from ..geometry import geometry
width, height = canvas_size(original)
canvas = geometry(width, height, seconds=value['seconds'])
- frames, output_seconds = saved_length(canvas, value['seconds'], bool(value.get('continue_from')))
result.update(prompt=value['prompt'], width=width, height=height, seconds=float(value['seconds']),
- frames=frames, output_seconds=output_seconds, seed_random=value['seed'] is None,
+ seed_random=value['seed'] is None,
seed=secrets.randbelow(MAX_SEED + 1) if value['seed'] is None else value['seed'],
preview=value['preview'], media=generation_media(value.get('media')), **sampling(value))
result['task'] = task(result['media'])
@@ -192,6 +193,9 @@ def normalize(value):
result['first_frame_reference'] = True
result['loras'] = [dict(name=row, strength=1.) if isinstance(row, str) else {'strength': 1., **row}
for row in value['loras']]
+ if port is not None:
+ result['single_max_frames'] = single_frame_limit(result, port=port)
+ result['frames'], result['output_seconds'] = saved_length(canvas, result)
elif kind == 'assemble':
result['clips'] = []
for row in value['clips']: