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.

A continued part's media panel keeps only its pictures before the Media node checks

Bowen Xue01d7bd67b01b
diff --git a/freevideo_engine/chain_runner.py b/freevideo_engine/chain_runner.py
index 4ab52cf..e5e4179 100644
--- a/freevideo_engine/chain_runner.py
+++ b/freevideo_engine/chain_runner.py
@@ -531,11 +531,13 @@ class ChainRunner:
block_inputs[key] = (source['output'] or '') if source is not None else ''
for name in getattr(self.host, 'continuation_inputs', ()):
prompt[node]['inputs'].pop(name, None)
- # A part that continues footage takes no keyframes or references of its own:
- # only a part that starts fresh keeps the request's media.
+ # A part that continues footage takes no keyframes of its own: it starts from the footage.
+ # The host's media inputs name what only a part that starts fresh keeps.
if any(source is not None for source in sources.values()):
for name in getattr(self.host, 'media_inputs', ()):
prompt[node]['inputs'].pop(name, None)
+ if hasattr(self.host, 'continued'):
+ self.host.continued(prompt, node)
prompt[node]['inputs'].update(self.inputs(block_inputs))
self.host.submit(prompt_id, node_prompt(prompt, node), extra)
except Exception as error:
diff --git a/freevideo_engine/comfy_assets.py b/freevideo_engine/comfy_assets.py
index 844b379..29d2cb8 100644
--- a/freevideo_engine/comfy_assets.py
+++ b/freevideo_engine/comfy_assets.py
@@ -106,6 +106,28 @@ def resolve_assets(serialized, input_directory):
return result
+def continued_assets(serialized):
+ """The panel rows a continued part uses: enabled image references in panel order, at most three.
+
+ Its frames and sounds stay in the panel for parts that start fresh, but never reach a continued part's checks."""
+ from .continuation import PICTURES_MAX
+ try:
+ rows = json.loads(serialized)
+ except (TypeError, ValueError):
+ return '[]'
+ kept = []
+ for row in rows if isinstance(rows, list) else ():
+ if (isinstance(row, dict) and row.get('enabled', True) is True and row.get('role') == 'reference'
+ and isinstance(row.get('file'), str)):
+ try:
+ image = media_kind(row['file']) == 'image'
+ except ValueError:
+ image = False
+ if image and len(kept) < PICTURES_MAX:
+ kept.append(dict(file=row['file'], role='reference'))
+ return json.dumps(kept)
+
+
def connect_assets(assets, *, first=None, last=None, reference=None, reference_audio=None, **images):
"""Keep connected IMAGE/AUDIO values native until request input export."""
result = dict(assets)
diff --git a/freevideo_engine/comfy_bridge.py b/freevideo_engine/comfy_bridge.py
index cfa1442..bcd7740 100644
--- a/freevideo_engine/comfy_bridge.py
+++ b/freevideo_engine/comfy_bridge.py
@@ -1346,6 +1346,11 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
media = extra.get('media') or {}
send_progress({'label': 'Retaining and checking input media', 'timing_phase': 'encoding',
'references': any(media.get(key) for key in ('first', 'last', 'references'))})
+ # A continued part keeps the cast's pictures; the engine then leaves out the film's first frame.
+ pictured = continue_from is not None and any(
+ row.get('kind') == 'image' for row in (extra.get('media') or {}).get('references', []))
+ if pictured:
+ anchored = False
from .media_request import task_for
from .two_pass import plan, sampling_canvas
from .generate import hide_tail_geometry
@@ -1355,11 +1360,12 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
# The engine samples this canvas; results, cache keys and labels keep the requested size.
sampled, output_size = sampling_canvas(generated_canvas, staged=bool(preview or upscale), media=extra.get('media'),
conditioned=bool(extra.get('conditioning')))
- planned = plan(sampled, two_pass, 'ref2va' if anchored else task_for(extra.get('media', {})),
+ planned = plan(sampled, two_pass, 'ref2va' if anchored or pictured else task_for(extra.get('media', {})),
base_steps=base_steps, refine_steps=refine_steps, staged=bool(preview or upscale))
if continue_from is not None:
from .continuation import ADALN_TASK, ANCHOR_ADALN_TASK, MISSING, validate_snapshot, summary
- validate_route(task='ref2va' if anchored else task_for(extra.get('media', {})), anchor=anchored,
+ validate_route(task='ref2va' if anchored or pictured else task_for(extra.get('media', {})),
+ anchor=anchored or pictured,
media=extra.get('media'))
if continuation is not None:
try:
@@ -1414,7 +1420,7 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
preparation_started = time.monotonic()
try:
# Reference audio selects its own tables; match the encoder's choice.
- asset_task = ((ANCHOR_ADALN_TASK if anchored else ADALN_TASK) if continue_from is not None
+ asset_task = ((ANCHOR_ADALN_TASK if anchored or pictured else ADALN_TASK) if continue_from is not None
else engine_task(extra.get('media', {}), media_base))
preparation = prepare_sampling_assets(root, machine, planned, asset_task,
progress=asset_progress, interrupted=interrupted, environ=environment)
diff --git a/freevideo_engine/comfy_chain.py b/freevideo_engine/comfy_chain.py
index 1eee671..3afecef 100644
--- a/freevideo_engine/comfy_chain.py
+++ b/freevideo_engine/comfy_chain.py
@@ -40,11 +40,27 @@ def seconds_for_frames(frames, minimum=1.625, maximum=60., step=.1):
class ComfyHost:
continuation_inputs = (*CONTINUE_INPUTS.values(), 'voice_reference', 'hide_tail')
- media_inputs = ('media', 'first', 'last', 'references', 'conditioning')
+ # Inputs a continued part drops. The media panel and references stay: the Generate node keeps their pictures.
+ media_inputs = ('first', 'last', 'conditioning')
def __init__(self, server):
self.server = server
+ def continued(self, prompt, node):
+ """A continued part's media panel keeps only the pictures it uses (prompt is this submission's copy)."""
+ link = prompt[node]['inputs'].get('media')
+ if not (isinstance(link, list) and len(link) == 2 and link[0] in prompt):
+ return
+ media = prompt[link[0]]
+ if not isinstance(media, dict) or media.get('class_type') != 'FreeVideoMedia':
+ return
+ inputs = media.setdefault('inputs', {})
+ for name in ('first', 'last', 'reference_audio'):
+ inputs.pop(name, None)
+ if isinstance(inputs.get('assets'), str):
+ from .comfy_assets import continued_assets
+ inputs['assets'] = continued_assets(inputs['assets'])
+
def inputs(self, block_inputs):
schema = _generate_inputs()
values = {key: block_inputs[key] for key in ('text', 'seed')}
diff --git a/freevideo_engine/comfy_media.py b/freevideo_engine/comfy_media.py
index d7abd95..ac37d2b 100644
--- a/freevideo_engine/comfy_media.py
+++ b/freevideo_engine/comfy_media.py
@@ -1,4 +1,5 @@
"""Native Comfy sockets -> retained local files, without model duplication."""
+import logging
from pathlib import Path
from .comfy_assets import REFERENCE_INPUTS
@@ -43,6 +44,22 @@ def _audio(value, path):
container.mux(packet)
+def continued(exported):
+ """What a continued part keeps of exported inputs: the pictures (at most three, one per person) and LoRAs.
+
+ It starts from the footage, so keyframes, pre-encoded conditioning, clips and sound are left out."""
+ from .continuation import PICTURES_MAX
+ media = (exported or {}).get('media') or {}
+ kept = {key: value for key, value in media.items()
+ if key not in ('first', 'last', 'references', 'conditioning_info')}
+ pictures = [row for row in media.get('references', []) if row.get('kind') == 'image']
+ if len(pictures) > PICTURES_MAX:
+ logging.warning('[FreeVideo] A continued part keeps the first %d of %d pictures', PICTURES_MAX, len(pictures))
+ if pictures:
+ kept['references'] = pictures[:PICTURES_MAX]
+ return {'media': kept} if len(kept) > 1 else {}
+
+
def export(run, canvas, *, first=None, last=None, references=None, loras=None, conditioning=None, assets=None):
media = {'version': 1}
if assets:
diff --git a/freevideo_engine/comfy_nodes.py b/freevideo_engine/comfy_nodes.py
index cd97898..06f103a 100644
--- a/freevideo_engine/comfy_nodes.py
+++ b/freevideo_engine/comfy_nodes.py
@@ -82,13 +82,12 @@ class FreeVideoGenerate(io.ComfyNode):
# Use presence checks: tensor inputs have no scalar truth value.
assets = kwargs.get('media')
connected = assets.get('_connected', {}) if isinstance(assets, dict) else {}
+ # References are not checked here: a continued part keeps only their pictures.
media = dict(first=kwargs.get('first') is not None or connected.get('first') is not None,
last=kwargs.get('last') is not None or connected.get('last') is not None,
- references=bool(kwargs.get('references')) or any(
- connected.get(key) is not None for key in ('reference', 'reference_audio')),
conditioning_info=kwargs.get('conditioning') is not None)
if isinstance(assets, dict):
- for key in ('first', 'last', 'references', 'conditioning_info'):
+ for key in ('first', 'last', 'conditioning_info'):
media[key] = media[key] or bool(assets.get(key))
options.update(two_pass=kwargs.get('two_pass', True), preview=kwargs.get('preview', False),
refine_from=kwargs.get('refine_from'), media=media)
@@ -125,7 +124,7 @@ class FreeVideoGenerate(io.ComfyNode):
from .background_compile import COMPILE
# Returns once the idle compile released the GPU and the engine lease.
COMPILE.stop(final=True)
- from .comfy_media import export
+ from .comfy_media import continued, export
import folder_paths
import comfy.model_management as memory
from comfy.utils import ProgressBar
@@ -220,8 +219,9 @@ class FreeVideoGenerate(io.ComfyNode):
base_steps=base_steps, refine_steps=refine_steps, comfy_metadata=graph,
preview=bool(preview), refine_from=refine_from or None,
interrupted=memory.throw_exception_if_processing_interrupted, release_models=release,
- export_inputs=lambda run, canvas: export(run, canvas, first=first, last=last,
- references=references, loras=loras, conditioning=conditioning, assets=media),
+ export_inputs=lambda run, canvas: (continued if options.get('continue_from') else dict)(
+ export(run, canvas, first=first, last=last, references=references, loras=loras,
+ conditioning=conditioning, assets=media)),
**options,
# Only a part that continues another can use it; other requests keep the existing bridge call.
**({'first_frame_reference': True} if first_frame_reference is True and options.get('continue_from') else {}),
diff --git a/freevideo_engine/continuation.py b/freevideo_engine/continuation.py
index b8b60b1..4e1d26a 100644
--- a/freevideo_engine/continuation.py
+++ b/freevideo_engine/continuation.py
@@ -33,6 +33,8 @@ VERSION = 1
MISSING = 'The previous video has no usable continuation data. Generate it again with this version of FreeVideo.'
SIZE_MISMATCH = 'Use the same width and height as the previous video.'
UNSUPPORTED = 'Video continuation requires full two-pass text generation on an NVIDIA GPU, without first frames, last frames or reference media.'
+# A continued part keeps the cast's pictures, one per person and at most three people in a frame.
+PICTURES_MAX = 3
INVALID_FRAMES = 'Frame count must be 5 + 17n and at least 39 (39, 56, 73, 90, ...).'
INVALID_FILE = 'Choose an existing MP4 video using its absolute path.'
@@ -71,16 +73,18 @@ def validate_frames(frames):
def validate_route(*, task='t2va', two_pass=True, preview=False, refine_from=None,
media=None, backend=None, anchor=False, sound=False):
+ """anchor: the part also takes pictures (an explicit anchor or the cast's pictures);
+ sound: the engine adds the film's opening sound as the one audio reference."""
media = media or {}
references = media.get('references')
- valid_reference = (anchor and isinstance(references, list) and len(references) == 1
- and isinstance(references[0], dict)
- and references[0].get('kind') == 'image')
+ kinds = ([row.get('kind') if isinstance(row, dict) else None for row in references]
+ if isinstance(references, list) else None)
+ valid_reference = (kinds is not None and kinds.count('image') + kinds.count('audio') == len(kinds)
+ and kinds.count('image') <= (PICTURES_MAX if anchor else 0)
+ and kinds.count('audio') == (1 if sound else 0))
valid_task = task == ('ref2va' if anchor else 't2va')
if sound:
- valid_reference = (not anchor and isinstance(references, list) and len(references) == 1
- and isinstance(references[0], dict) and references[0].get('kind') == 'audio')
- valid_task = task in ('t2va', 'ref2va', 'ref2va_audio') and valid_reference
+ valid_task = valid_reference and task in (('ref2va', 'ref2va_av') if anchor else ('t2va', 'ref2va', 'ref2va_audio'))
if (not supported()[0] or backend not in (None, 'cuda') or not valid_task
or not two_pass or preview or refine_from
or any(media.get(key) for key in ('first', 'last', 'conditioning_info'))
@@ -88,6 +92,26 @@ def validate_route(*, task='t2va', two_pass=True, preview=False, refine_from=Non
raise ValueError(UNSUPPORTED)
+def encoded_references(conditions, task, anchor):
+ """Check a continued part's encoded references: its pictures, then the engine's sound. True when the sound is there."""
+ rows = conditions or []
+ images = [row for row in rows if row['kind'] == 'image' and row.get('audio_latent') is None]
+ sound = (task == ('ref2va_av' if anchor else 'ref2va_audio') and len(rows) == len(images) + 1
+ and rows[-1]['kind'] == 'audio' and rows[-1].get('audio_latent') is not None)
+ if not rows or anchor != bool(images) or len(images) + sound != len(rows) or len(images) > PICTURES_MAX:
+ raise ValueError('Continuation pictures must be one to %d images, followed only by its own sound' % PICTURES_MAX)
+ return sound
+
+
+def continuation_pictures(media):
+ """The pictures a continued part takes: image references only, at most PICTURES_MAX (one per person)."""
+ references = media.get('references') or []
+ pictures = [row for row in references if row.get('kind') == 'image']
+ if len(pictures) != len(references) or len(pictures) > PICTURES_MAX:
+ raise ValueError(UNSUPPORTED)
+ return pictures
+
+
def anchor_media(media, path):
"""Add exactly one explicit global first-frame reference through the media encoder."""
if any(media.get(key) for key in ('first', 'last', 'references', 'conditioning_info')):
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index 727c407..6585e63 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -392,7 +392,7 @@ def _run(args):
raise
# A record of another version, other weights or another first-pass size.
value = dict(encoded_continuation(continue_from, canvas),
- **{key: value[key] for key in ('audio_context', 'source_video', 'anchor', 'sound') if key in value})
+ **{key: value[key] for key in ('audio_context', 'source_video', 'anchor', 'pictures', 'sound') if key in value})
return freeze_continuation(value) if continuation_directory is not None else value
frames = getattr(args, 'frames', None)
@@ -436,14 +436,20 @@ def _run(args):
if continue_anchor is not None:
from .continuation import anchor_media
media = anchor_media(media, continue_anchor)
+ # The cast's pictures, sent with a continued part like with a part that starts fresh.
+ pictures = []
+ if continue_from is not None and continue_anchor is None and media.get('references'):
+ from .continuation import continuation_pictures
+ pictures = continuation_pictures(media)
+ anchored = continue_anchor is not None or bool(pictures)
# Too small to sample cleanly: render larger, scale the picture down. Decided before anything
# compares or stores the canvas, so every later check sees the size that is sampled.
from .two_pass import sampling_canvas
canvas, output_size = sampling_canvas(canvas, staged=bool(preview or refine_source), media=media,
conditioned=bool(args.conditioning))
if continue_from is not None:
- validate_route(task=getattr(args, 'task', None) or ('ref2va' if continue_anchor else 't2va'),
- anchor=continue_anchor is not None, two_pass=two_pass,
+ validate_route(task=getattr(args, 'task', None) or ('ref2va' if anchored else 't2va'),
+ anchor=anchored, two_pass=two_pass,
preview=preview, refine_from=getattr(args, 'refine_from', None), media=media)
# Reject absent/mismatched context before text encoding or model loading.
if getattr(args, 'continuation_snapshot', None):
@@ -458,7 +464,10 @@ def _run(args):
# Nothing was stored for this file: its own ending is encoded when the run starts.
continuation = encoded_continuation(continue_from, canvas)
continuation = dict(continuation, audio_context=audio_context(), source_video=str(continue_from))
- if first_frame is not None:
+ if first_frame is not None and pictures:
+ # The cast's pictures already hold the people; the film's first frame is not added to them.
+ first_frame['reason'] = 'pictures'
+ elif first_frame is not None:
from .continuation import anchor_media, chain_first_frame_picture
try:
# A context encoded from the file carries no first frame; whoever planned this run saw none either.
@@ -480,10 +489,13 @@ def _run(args):
validate_route(task=getattr(args, 'task', None) or 'ref2va', anchor=True, two_pass=two_pass,
preview=preview, refine_from=getattr(args, 'refine_from', None), media=media)
first_frame.update(used=True, width=picture_width, height=picture_height)
- if continue_anchor is not None:
+ anchored = True
+ if anchored:
continuation['anchor'] = media['references'][0]
+ if pictures:
+ continuation['pictures'] = len(pictures)
if voice_reference is not None:
- if first_frame is not None:
+ if first_frame is not None and not pictures:
voice_reference['reason'] = 'first_frame'
elif continue_anchor is not None:
voice_reference['reason'] = 'anchor'
@@ -553,7 +565,7 @@ def _run(args):
manifest = json.loads((args.cache / 'manifest.json').read_text(encoding='utf-8'))
if continuation is not None:
from .two_pass import plan as continuation_plan
- validate_route(task=profile['engine'].get('task', 't2va'), anchor=continue_anchor is not None)
+ validate_route(task=profile['engine'].get('task', 't2va'), anchor=anchored)
planned = continuation_plan(canvas, two_pass, base_steps=base_steps, refine_steps=refine_steps)
continuation_first = planned['first']
continuation = usable_continuation(continuation, canvas, None if active_loras else manifest, planned)
@@ -590,6 +602,8 @@ def _run(args):
report['audio_context'] = continuation['audio_context']
if continue_anchor is not None:
report['continue_anchor'] = continuation['anchor']
+ if pictures:
+ report['continue_pictures'] = len(pictures)
if first_frame is not None:
report['first_frame_reference'] = first_frame
if voice_reference is not None:
@@ -651,11 +665,13 @@ def _run(args):
path = destination.with_suffix('.first-sound.wav')
path.write_bytes(sound)
from .media_request import digest
- media = dict(media, version=1, references=[dict(kind='audio', path=str(path),
- sha256=digest(path), bytes=path.stat().st_size)])
- validate_route(task=getattr(args, 'task', None) or 't2va', sound=True, two_pass=two_pass,
+ # After the cast's pictures: the sound is the last reference.
+ media = dict(media, version=1, references=[*media.get('references', []), dict(kind='audio',
+ path=str(path), sha256=digest(path), bytes=path.stat().st_size)])
+ validate_route(task=getattr(args, 'task', None) or ('ref2va' if anchored else 't2va'), sound=True,
+ anchor=anchored, two_pass=two_pass,
preview=preview, refine_from=getattr(args, 'refine_from', None), media=media)
- continuation['sound'] = media['references'][0]
+ continuation['sound'] = media['references'][-1]
args.task = profile['engine']['task'] = task_for(media)
voice_reference['used'] = True
resource_identity = local_identity(hardware, args.cache)
@@ -822,7 +838,7 @@ def _run(args):
staged=bool(preview or refine_source))
report['sampling_plan'] = sampling_plan
if continuation is not None:
- validate_route(task=profile['engine'].get('task', 't2va'), anchor=continue_anchor is not None,
+ validate_route(task=profile['engine'].get('task', 't2va'), anchor=anchored,
**(dict(sound=True, media=media) if voice_reference and voice_reference['used'] else {}))
continuation = usable_continuation(continuation, canvas,
json.loads((args.cache / 'manifest.json').read_text(encoding='utf-8')), sampling_plan)
@@ -948,7 +964,7 @@ def _run(args):
if continuation is not None:
from .continuation import ADALN_TASK, ANCHOR_ADALN_TASK
selected['engine'] = dict(selected['engine'],
- adaln_task=ANCHOR_ADALN_TASK if continue_anchor is not None else ADALN_TASK)
+ adaln_task=ANCHOR_ADALN_TASK if anchored else ADALN_TASK)
request.update(engine_options=selected['engine'], decoder_options=selected['decoder'],
ram_budget_bytes=round(selected['inference_ram_budget_gb'] * 1e9),
ram_budget_is_estimate=ram_budget_is_estimate(args),
diff --git a/freevideo_engine/runtime.py b/freevideo_engine/runtime.py
index b8b929c..c1f43d2 100644
--- a/freevideo_engine/runtime.py
+++ b/freevideo_engine/runtime.py
@@ -551,7 +551,7 @@ class Engine:
if continuation is not None:
from .continuation import validate_route
# Audio references are admitted below, after inspecting the encoded modalities.
- if self.task != 'ref2va_audio':
+ if self.task not in ('ref2va_audio', 'ref2va_av'):
validate_route(task=self.task, anchor=bool(continuation.get('anchor')))
if tuple(continuation['video'].shape[-2:]) != (height // 16, width // 16):
from .continuation import SIZE_MISMATCH
@@ -618,13 +618,10 @@ class Engine:
sampling_kwargs.update(condition_schedule=condition_schedule, condition_trace=early_receipt['steps'])
conditions = value.get('references') or None
if continuation is not None:
- sound = (not continuation.get('anchor') and self.task == 'ref2va_audio'
- and conditions is not None and len(conditions) == 1
- and conditions[0]['kind'] == 'audio' and conditions[0].get('audio_latent') is not None)
- if not sound and (conditions is None or len(conditions) != 1 or conditions[0]['kind'] != 'image' or conditions[0].get('audio_latent') is not None):
- raise ValueError('Continuation anchor requires exactly one image reference without audio')
- if sound:
- validate_route(task=self.task, sound=True, media=dict(references=conditions))
+ from .continuation import encoded_references
+ if encoded_references(conditions, self.task, bool(continuation.get('anchor'))):
+ validate_route(task=self.task, sound=True, anchor=bool(continuation.get('anchor')),
+ media=dict(references=[dict(kind=row['kind']) for row in conditions]))
# Ref2VA packs independent-size references before generated
# video rows in both passes. Their latents do not need the
# keyframe resize used by first/last-frame conditioning.