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.

Hidden tails: hide 34 frames so dialogue parts keep moving through the seam

Bowen Xueabc34d479a56
diff --git a/freevideo_engine/adaptive.py b/freevideo_engine/adaptive.py
index 6fa6011..37d9a9b 100644
--- a/freevideo_engine/adaptive.py
+++ b/freevideo_engine/adaptive.py
@@ -660,11 +660,13 @@ def complete_observation(metrics, canvas, output, artifacts, telemetry):
from .validation import _retained_array_header, finite_number
expected = canvas['frames']
continuation = metrics.get('continuation')
- output_frames = expected
+ from .continuation import validate_hide_tail
+ hidden = validate_hide_tail(metrics.get('hide_tail_frames', 0))
+ output_frames = expected - hidden
if continuation is not None:
from .continuation import OVERLAP_FRAMES
if (not isinstance(continuation, dict) or continuation.get('overlap_frames') != OVERLAP_FRAMES
- or continuation.get('new_frames') != expected - OVERLAP_FRAMES):
+ or continuation.get('new_frames') != expected - hidden - OVERLAP_FRAMES):
raise ValueError('Invalid continuation output geometry')
output_frames = continuation['new_frames']
preview = metrics.get('preview') is True
diff --git a/freevideo_engine/chain_runner.py b/freevideo_engine/chain_runner.py
index cf71f20..4ab52cf 100644
--- a/freevideo_engine/chain_runner.py
+++ b/freevideo_engine/chain_runner.py
@@ -503,6 +503,7 @@ class ChainRunner:
self._save(record)
prompt = deepcopy(record['snapshot']['prompt'])
block_inputs = dict(block['inputs'])
+ block_inputs.update(index=block['index'], count=len(record['blocks']))
sources = self._sources(record, block)
extra = deepcopy(record['snapshot']['extra_data'])
if record['client_id'] is not None:
diff --git a/freevideo_engine/cli.py b/freevideo_engine/cli.py
index f60ab43..2059597 100644
--- a/freevideo_engine/cli.py
+++ b/freevideo_engine/cli.py
@@ -97,6 +97,8 @@ def main():
help='With --continue-from: also give the model the first frame of the whole film as a '
'reference picture. Reduces drift over many parts; holds framing and motion close to '
'the opening, so leave it off when later parts should move away from it')
+ generate.add_argument('--hide-tail', action='store_true',
+ help='Generate and discard 34 extra frames for dialogue segments.')
generate.add_argument('--voice-reference', action='store_true',
help='With --continue-from: use the opening six seconds as a voice reference when the prompt has dialogue')
generate.add_argument('--continue-anchor', type=Path, metavar='IMAGE',
diff --git a/freevideo_engine/comfy_assets.py b/freevideo_engine/comfy_assets.py
index 88d142e..844b379 100644
--- a/freevideo_engine/comfy_assets.py
+++ b/freevideo_engine/comfy_assets.py
@@ -162,6 +162,10 @@ def output_summary(report, relative_video):
video=relative_video.as_posix(), report=relative_video.with_suffix(
'.debug.json' if report.get('diagnostic_file') == relative_video.with_suffix('.debug.json').name
else '.request.json').as_posix())
+ if type(report.get('output_frames')) is int and report['output_frames'] > 0:
+ # Resource reports keep the generated canvas; result cards show only saved frames.
+ result['geometry'].update(frames=report['output_frames'],
+ seconds=report['output_frames'] / (result['geometry'].get('fps') or 24))
checkpoint = encoding.get('checkpoint') or {}
sizes = checkpoint.get('bytes'), checkpoint.get('expected_bytes')
# Reports are read back from disk; a malformed one gets no notice rather than failing the library.
diff --git a/freevideo_engine/comfy_bridge.py b/freevideo_engine/comfy_bridge.py
index d2fb88c..cfa1442 100644
--- a/freevideo_engine/comfy_bridge.py
+++ b/freevideo_engine/comfy_bridge.py
@@ -1155,11 +1155,13 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
release_models=None, export_inputs=None, two_pass=True, encoder_prewarm=None,
force_regenerate=False, base_steps=8, refine_steps=3, comfy_metadata=None,
prompt_rewrite_report=None, preview=False, refine_from=None, report_extra=None,
- continue_from=None, frames=None, first_frame_reference=False, voice_reference=False):
+ continue_from=None, frames=None, first_frame_reference=False, voice_reference=False, hide_tail=False):
if type(first_frame_reference) is not bool:
raise ValueError('First-frame reference must be a boolean')
if type(voice_reference) is not bool:
raise ValueError('Voice reference must be a boolean')
+ if type(hide_tail) is not bool:
+ raise ValueError('Hide tail must be a boolean')
if continue_from is not None:
from .continuation import validate_route
validate_route(two_pass=two_pass, preview=preview, refine_from=refine_from)
@@ -1266,6 +1268,8 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
command += ['--' + field.replace('_', '-'), str(reserve)]
if preview:
command.append('--preview')
+ if hide_tail:
+ command.append('--hide-tail')
state = {'status': 'starting', 'geometry': canvas, 'seed': seed, 'installation': str(root),
'command': command, 'output': str(output), 'source': str(source), 'resources': resources}
if preview:
@@ -1344,8 +1348,12 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
'references': any(media.get(key) for key in ('first', 'last', 'references'))})
from .media_request import task_for
from .two_pass import plan, sampling_canvas
+ from .generate import hide_tail_geometry
+ generated_canvas, hidden = hide_tail_geometry(canvas, None if extra.get('conditioning') else prompt,
+ hide_tail, preview=bool(preview or upscale))
+ hide_tail_frames = hidden['frames'] if hidden and hidden['used'] else 0
# The engine samples this canvas; results, cache keys and labels keep the requested size.
- sampled, output_size = sampling_canvas(canvas, staged=bool(preview or upscale), media=extra.get('media'),
+ 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', {})),
base_steps=base_steps, refine_steps=refine_steps, staged=bool(preview or upscale))
@@ -1356,7 +1364,7 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
if continuation is not None:
try:
continuation = validate_snapshot(continuation, sampled, sampling_plan=planned)
- state['continuation'] = summary(continuation)
+ state['continuation'] = summary(continuation, hide_tail_frames=hide_tail_frames)
except ValueError as error:
if str(error) != MISSING:
raise
@@ -1371,9 +1379,11 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
if continuation is None:
from .continuation import OVERLAP_FRAMES
state['continuation'] = dict(overlap_frames=OVERLAP_FRAMES,
- new_frames=sampled['frames'] - OVERLAP_FRAMES, encoded=True)
+ new_frames=sampled['frames'] - hide_tail_frames - OVERLAP_FRAMES, encoded=True)
# A preview is its own result; an upscale is always run from its preview.
keyed = dict(planned, preview=True) if preview else planned
+ if hide_tail_frames:
+ keyed = dict(keyed, hide_tail_frames=hide_tail_frames)
identify = lambda check: request_key(prompt, seed, canvas, keyed, extra, machine,
resources, source, environment, inspection=check)
state['result_cache'] = dict(enabled=False, hit=False, forced=force_regenerate)
@@ -1457,6 +1467,15 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
raise RuntimeError(generation_failure(run, process.returncode, repair=hint))
report = json.loads(output.with_suffix('.request.json').read_text(encoding='utf-8'))
engine = json.loads(output.with_suffix('.engine.json').read_text(encoding='utf-8'))
+ if hide_tail_frames and report.get('hide_tail') == dict(requested=True, used=False, reason='too_long'):
+ # Admission before encoding can decline the extra frames after the bridge's
+ # estimate. Validate the ordinary plan and don't cache it as a hidden-tail result.
+ # After encoding the conditioning is tied to the longer canvas, so a later refusal
+ # fails like any other request.
+ sampled, output_size = sampling_canvas(canvas, staged=bool(preview or upscale),
+ media=extra.get('media'), conditioned=bool(extra.get('conditioning')))
+ hidden, hide_tail_frames = report['hide_tail'], 0
+ cache_key = None
from .two_pass import steps, plan
completed_steps = steps(report.get('sampling_plan'))
expected_plan = plan(sampled, two_pass, report.get('profile', {}).get('engine', {}).get('task', 't2va'),
@@ -1472,6 +1491,7 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
or engine.get('sampling_plan') != report.get('sampling_plan')
or report.get('sampling_plan') != expected_plan
or bool(report.get('preview')) != preview or bool(report.get('upscaled_preview')) != bool(upscale)
+ or (hide_tail and report.get('hide_tail') != hidden)
or any(engine.get('geometry', {}).get(k) != shown[k] for k in ('width', 'height', 'frames'))
or (report.get('output_size') or None) != output_size):
from .comfy_launcher_api import repair_hint
diff --git a/freevideo_engine/comfy_chain.py b/freevideo_engine/comfy_chain.py
index 1e07903..1eee671 100644
--- a/freevideo_engine/comfy_chain.py
+++ b/freevideo_engine/comfy_chain.py
@@ -39,7 +39,7 @@ def seconds_for_frames(frames, minimum=1.625, maximum=60., step=.1):
class ComfyHost:
- continuation_inputs = (*CONTINUE_INPUTS.values(), 'voice_reference')
+ continuation_inputs = (*CONTINUE_INPUTS.values(), 'voice_reference', 'hide_tail')
media_inputs = ('media', 'first', 'last', 'references', 'conditioning')
def __init__(self, server):
@@ -61,6 +61,8 @@ class ComfyHost:
values[name] = '' if independent else block_inputs[key]
if 'voice_reference' in schema and values.get('continue_from'):
values['voice_reference'] = True
+ if 'hide_tail' in schema and not independent and block_inputs.get('index', 0) < block_inputs.get('count', 0) - 1:
+ values['hide_tail'] = True
return values
def work_exists(self, path):
diff --git a/freevideo_engine/comfy_nodes.py b/freevideo_engine/comfy_nodes.py
index 983e4bd..cd97898 100644
--- a/freevideo_engine/comfy_nodes.py
+++ b/freevideo_engine/comfy_nodes.py
@@ -66,6 +66,8 @@ class FreeVideoGenerate(io.ComfyNode):
optional=True, advanced=True, tooltip='Reduces drift.'),
io.Boolean.Input('voice_reference', display_name='Voice reference', default=False,
optional=True, advanced=True, tooltip='Keeps the opening voice consistent in continued dialogue.'),
+ io.Boolean.Input('hide_tail', display_name='Hide dialogue tail', default=False,
+ optional=True, advanced=True, tooltip='Generates and discards 34 extra frames to keep dialogue moving between parts.'),
],
outputs=[io.Video.Output('video'), io.String.Output('report', display_name='Report JSON')],
hidden=[io.Hidden.unique_id, io.Hidden.prompt, io.Hidden.extra_pnginfo],
@@ -111,7 +113,7 @@ class FreeVideoGenerate(io.ComfyNode):
def execute(cls, text, width, height, seconds, seed, first=None, last=None,
references=None, loras=None, conditioning=None, media=None, two_pass=True,
force_regenerate=False, base_steps=8, refine_steps=3, preview=False, refine_from='',
- continue_from='', frames=0, first_frame_reference=False, voice_reference=False):
+ continue_from='', frames=0, first_frame_reference=False, voice_reference=False, hide_tail=False):
from server import PromptServer
from .comfy_chain import block_context, block_finished, report_fields
node_id = cls.hidden.unique_id
@@ -224,6 +226,7 @@ class FreeVideoGenerate(io.ComfyNode):
# 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 {}),
**({'voice_reference': True} if voice_reference is True and options.get('continue_from') else {}),
+ **({'hide_tail': True} if hide_tail is True else {}),
**({'report_extra': {'chain': report_fields(chain)}} if chain is not None else {}))
relative = output.relative_to(output_root)
report = output.with_suffix('.request.json').read_text(encoding='utf-8')
diff --git a/freevideo_engine/continuation.py b/freevideo_engine/continuation.py
index 1905c88..b8b60b1 100644
--- a/freevideo_engine/continuation.py
+++ b/freevideo_engine/continuation.py
@@ -415,9 +415,12 @@ def validate_snapshot(request, canvas, manifest=None, sampling_plan=None):
return _prepare_snapshot(request, _snapshot_value(request), canvas, manifest, sampling_plan)
-def summary(request):
- return dict({key: request[key] for key in ('overlap_frames', 'new_frames', 'frame_origin', 'audio_origin', 'segment')},
- audio_lead_in_samples=request.get('audio_lead_in_samples', 0))
+def summary(request, *, hide_tail_frames=0):
+ result = dict({key: request[key] for key in ('overlap_frames', 'new_frames', 'frame_origin', 'audio_origin', 'segment')},
+ audio_lead_in_samples=request.get('audio_lead_in_samples', 0))
+ if hide_tail_frames:
+ result['new_frames'] -= validate_hide_tail(hide_tail_frames)
+ return result
def load(request, stage):
@@ -431,17 +434,33 @@ def load(request, stage):
audio=torch.from_numpy(value['audio'].copy()))
-def tail(video):
+# Dialogue parts settle into an ending over their last ~1.5 s; 17 frames hid only the pause, 34 also the pose reset.
+HIDE_TAIL_FRAMES = 34
+
+
+def validate_hide_tail(frames):
+ if type(frames) is not int or frames not in (0, 17, HIDE_TAIL_FRAMES):
+ raise ValueError('Hidden tail must be 0, 17 or 34 frames')
+ return frames
+
+
+def tail(video, *, hide_tail_frames=0):
# clone avoids keeping the entire clip's storage behind a small view.
+ hidden = validate_hide_tail(hide_tail_frames) // 17 * 5
+ if hidden:
+ return video[:, :, -hidden - LATENT_FRAMES:-hidden].detach().cpu().clone()
return video[:, :, -LATENT_FRAMES:].detach().cpu().clone()
-def tail_data(first, video, audio, canvas, sampling_plan, manifest, request=None):
+def tail_data(first, video, audio, canvas, sampling_plan, manifest, request=None, *, hide_tail_frames=0):
chain = ({key: request[key] for key in ('segment', 'frame_origin', 'audio_origin')} if request
else dict(segment=1, frame_origin=0, audio_origin=0))
- start = audio_origin(chain['frame_origin'] + canvas['frames'] - OVERLAP_FRAMES) - chain['audio_origin']
- return dict(video_lo=first, video_hi=tail(video), audio=audio[:, :, start:].detach().cpu().clone(),
- metadata=dict(identity=identity(manifest), geometry={key: canvas[key] for key in ('width', 'height', 'frames')},
+ kept = canvas['frames'] - validate_hide_tail(hide_tail_frames)
+ start = audio_origin(chain['frame_origin'] + kept - OVERLAP_FRAMES) - chain['audio_origin']
+ end = round(kept * 40 / 24) if hide_tail_frames else audio.shape[2]
+ return dict(video_lo=first, video_hi=tail(video, hide_tail_frames=hide_tail_frames),
+ audio=audio[:, :, start:end].detach().cpu().clone(),
+ metadata=dict(identity=identity(manifest), geometry=dict(width=canvas['width'], height=canvas['height'], frames=kept),
first_canvas={key: sampling_plan['first'][key] for key in ('width', 'height')}, chain=chain,
**({'source_id': request['source_id']} if request and 'source_id' in request else {})))
diff --git a/freevideo_engine/decode.py b/freevideo_engine/decode.py
index cedb222..2c6d79f 100644
--- a/freevideo_engine/decode.py
+++ b/freevideo_engine/decode.py
@@ -25,7 +25,10 @@ DECODE_LABELS = {
def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, prefetch=True, tile_group=False,
preload=False, pin_weights=False, artifacts_dir=None, phase_callback=None,
stream_output=False, stream_weights=False, resident_blocks=0, model_cache=None,
- linear_compute_cache=False, continuation=None, audio_lead_in_callback=None, output_size=None):
+ linear_compute_cache=False, continuation=None, audio_lead_in_callback=None, output_size=None,
+ hide_tail_frames=0):
+ from .continuation import validate_hide_tail
+ validate_hide_tail(hide_tail_frames)
def phase(name):
if phase_callback is not None:
phase_callback(name)
@@ -171,6 +174,9 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
chunk = (video[:, :, start:start + 8].float() * pixel_std + pixel_mean).clamp_(0, 1)
frames[start:start + chunk.shape[2]] = (chunk[0].permute(1, 2, 3, 0) * 255).round().to(torch.uint8)
del video
+ if hide_tail_frames:
+ kept_frames = len(frames) - hide_tail_frames
+ frames = frames[:kept_frames]
if continuation is not None:
from .continuation import OVERLAP_FRAMES
frames = frames[OVERLAP_FRAMES:]
@@ -181,12 +187,17 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
tick = time.perf_counter()
artifacts_dir = Path(artifacts_dir)
artifacts_dir.mkdir(parents=True, exist_ok=True)
- if not stream_output or continuation is not None:
- # A streamed mapping still contains the overlap. Replace its
+ if not stream_output or continuation is not None or hide_tail_frames:
+ # A streamed mapping still contains overlap/hidden frames. Replace its
# retained artifact after the mapping closes, below.
rgb_path = artifacts_dir / ('rgb-new.npy' if stream_output else 'rgb.npy')
np.save(rgb_path, frames.numpy() if hasattr(frames, 'numpy') else frames, allow_pickle=False)
artifact_seconds += time.perf_counter() - tick
+ elif stream_output and hide_tail_frames:
+ # render_rgb also retains a mapping when no explicit artifacts directory was requested.
+ import numpy as np
+ np.save(directory / 'rgb-new.npy', frames.numpy() if hasattr(frames, 'numpy') else frames,
+ allow_pickle=False)
audio_start = time.perf_counter()
phase('audio_load_decode')
audio_vae = None
@@ -212,6 +223,9 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
if audio_lead_in_callback is not None:
from .continuation import capture_audio_lead_in
audio_lead_in_callback(capture_audio_lead_in(audio, continuation, rate))
+ if hide_tail_frames:
+ audio = audio[:, :round(kept_frames * 40 / 24) * 800]
+ if continuation is not None:
audio = audio[:, continuation['audio_latents'] * 800:]
del audio_vae, audio_mean, audio_std
gc.collect()
@@ -248,8 +262,9 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
if rgb_mapping is not None:
del frames
rgb_mapping._mmap.close()
- if continuation is not None and artifacts_dir and (artifacts_dir / 'rgb-new.npy').is_file():
- (artifacts_dir / 'rgb-new.npy').replace(artifacts_dir / 'rgb.npy')
+ retained = Path(artifacts_dir) if artifacts_dir else directory
+ if (continuation is not None or hide_tail_frames) and (retained / 'rgb-new.npy').is_file():
+ (retained / 'rgb-new.npy').replace(retained / 'rgb.npy')
return {'vae_load_seconds': load_seconds, 'video_decode_seconds': video_decode_seconds,
'vae_linear_compute_cache': linear_compute_cache, 'vae_compute_cache_preparation': compute_cache_metrics,
'resident_vae_cache_hit': vae_cache_hit, 'resident_audio_vae_cache_hit': audio_cache_hit,
diff --git a/freevideo_engine/decode_resume.py b/freevideo_engine/decode_resume.py
index 4a27033..58fc241 100644
--- a/freevideo_engine/decode_resume.py
+++ b/freevideo_engine/decode_resume.py
@@ -94,6 +94,8 @@ def sampling_provenance(request):
result['upscaler_sha256'] = _digest(request['upscaler_checkpoint'])
if result['upscaler_sha256'] != request['sampling_plan']['upscaler_sha256']:
raise ValueError('Latent upscaler differs from the planned checkpoint')
+ if request.get('hide_tail_frames'):
+ result['hide_tail_frames'] = request['hide_tail_frames']
if request.get('continuation') is not None:
# A retry's identity binds the accepted bytes, without embedding the
# snapshot again or making a relocation change computation identity.
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index c581f6d..727c407 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -340,6 +340,33 @@ def run(args):
raise
+def dialogue_reason(prompt):
+ """Shared eligibility for opening-voice references and hidden dialogue tails."""
+ from .prompt_vlm.rules import split_source
+ if not prompt or not split_source(prompt)[2]:
+ return 'no_lines'
+ if re.search(r'(?i)\b(?:sing|sings|singing|sang|sung|lyrics)\b|唱', prompt):
+ return 'singing'
+ return None
+
+
+def hide_tail_geometry(canvas, prompt, requested=False, *, preview=False, max_frames=None):
+ """Plan the generated canvas while keeping the ordinary output duration."""
+ if not requested:
+ return canvas, None
+ from .continuation import HIDE_TAIL_FRAMES
+ from .geometry import geometry
+ # The product's longest selectable request is 60 seconds on the H3 grid.
+ limit = geometry(seconds=60)['frames'] if max_frames is None else max_frames
+ reason = 'preview' if preview else dialogue_reason(prompt)
+ if reason is None and canvas['frames'] + HIDE_TAIL_FRAMES > limit:
+ reason = 'too_long'
+ if reason is not None:
+ return canvas, dict(requested=True, used=False, reason=reason)
+ generated = dict(canvas, **geometry(canvas['width'], canvas['height'], frames=canvas['frames'] + HIDE_TAIL_FRAMES))
+ return generated, dict(requested=True, used=True, frames=HIDE_TAIL_FRAMES)
+
+
def _run(args):
from .hardware import detect
from .geometry import geometry
@@ -385,6 +412,12 @@ def _run(args):
validate_frames(frames)
canvas = geometry(getattr(args, 'width', 1344), getattr(args, 'height', 768),
frames=frames, seconds=getattr(args, 'seconds', None))
+ visible_canvas = canvas
+ canvas, hide_tail = hide_tail_geometry(canvas,
+ args.prompt_file.read_text(encoding='utf-8') if getattr(args, 'hide_tail', False) and args.prompt_file else None,
+ getattr(args, 'hide_tail', False),
+ preview=bool(getattr(args, 'preview', False) or getattr(args, 'refine_from', None)))
+ hide_tail_frames = hide_tail['frames'] if hide_tail and hide_tail['used'] else 0
continuation = None
from .two_pass import validate_steps
requested_steps = getattr(args, 'base_steps', None)
@@ -450,7 +483,6 @@ def _run(args):
if continue_anchor is not None:
continuation['anchor'] = media['references'][0]
if voice_reference is not None:
- from .prompt_vlm.rules import split_source
if first_frame is not None:
voice_reference['reason'] = 'first_frame'
elif continue_anchor is not None:
@@ -458,11 +490,9 @@ def _run(args):
elif args.conditioning:
# Preencoded conditioning cannot take another reference.
voice_reference['reason'] = 'conditioning'
- elif not args.prompt_file or not split_source(args.prompt_file.read_text(encoding='utf-8'))[2]:
- voice_reference['reason'] = 'no_lines'
- elif re.search(r'(?i)\b(?:sing|sings|singing|sang|sung|lyrics)\b|唱', args.prompt_file.read_text(encoding='utf-8')):
- # Quoted lyrics read as lines, but on music the opening sound did not hold steady.
- voice_reference['reason'] = 'singing'
+ else:
+ voice_reference['reason'] = dialogue_reason(
+ args.prompt_file.read_text(encoding='utf-8') if args.prompt_file else None)
active_loras = [row for row in media.get('loras', []) if row['strength'] != 0]
if media:
inferred_task = task_for(media)
@@ -479,7 +509,21 @@ def _run(args):
hardware, resident_credit = credit(detect())
profile = json.loads(args.profile.read_text(encoding='utf-8'))
else:
- hardware, resident_credit, profile = automatic_profile(args, canvas, stage='before-encoding', evidence=planning)
+ from .policy import ResourceBudgetError
+ try:
+ hardware, resident_credit, profile = automatic_profile(args, canvas, stage='before-encoding', evidence=planning)
+ except ResourceBudgetError:
+ if not hide_tail_frames:
+ raise
+ # The optional tail must fit this size/step tier too. Re-admit the
+ # original duration before encoding anything; never shorten it.
+ canvas, output_size = sampling_canvas(dict(canvas, **visible_canvas),
+ staged=bool(preview or refine_source), media=media, conditioned=bool(args.conditioning))
+ hardware, resident_credit, profile = automatic_profile(args, canvas, stage='before-encoding', evidence=planning)
+ hide_tail, hide_tail_frames = dict(requested=True, used=False, reason='too_long'), 0
+ if continuation is not None:
+ from .continuation import OVERLAP_FRAMES
+ continuation = dict(continuation, new_frames=canvas['frames'] - OVERLAP_FRAMES)
print(json.dumps(dict(event='compute_device', backend='CUDA', name=getattr(hardware, 'gpu_name', None),
uuid=getattr(hardware, 'gpu_uuid', None), vram_total_bytes=getattr(hardware, 'vram_total', None),
vram_free_bytes=getattr(hardware, 'vram_free', None))), flush=True)
@@ -540,7 +584,7 @@ def _run(args):
'reclaimable_resident_models': resident_credit,
'encoder_mode': 'native H3 encoder library child' if args.prompt_file else 'preencoded shared conditioning'}
if continuation is not None:
- report['continuation'] = continuation_summary(continuation)
+ report['continuation'] = continuation_summary(continuation, hide_tail_frames=hide_tail_frames)
if 'tail' in continuation:
report['continuation']['context'] = 'encoded'
report['audio_context'] = continuation['audio_context']
@@ -550,6 +594,11 @@ def _run(args):
report['first_frame_reference'] = first_frame
if voice_reference is not None:
report['voice_reference'] = voice_reference
+ if hide_tail is not None:
+ report['hide_tail'] = hide_tail
+ if hide_tail_frames:
+ report['output_frames'] = (report['continuation']['new_frames'] if continuation is not None
+ else canvas['frames'] - hide_tail_frames)
from .support_report import code_identity, write as write_debug
report['runtime_hardware'] = hardware.to_dict()
report['runtime_code'] = code_identity()
@@ -874,6 +923,8 @@ def _run(args):
'metrics': str(destination.with_suffix('.engine.json'))}
if continuation is not None:
request['continuation'] = continuation
+ if hide_tail_frames:
+ request['hide_tail_frames'] = hide_tail_frames
if preview:
request['preview'] = True
if allocator_limit_bytes is not None:
diff --git a/freevideo_engine/worker.py b/freevideo_engine/worker.py
index 8cc52ea..fb30a15 100644
--- a/freevideo_engine/worker.py
+++ b/freevideo_engine/worker.py
@@ -85,6 +85,10 @@ def generate(request, resident=None):
'torch_num_threads': torch.get_num_threads()}}}
save(request['metrics'], metrics)
try:
+ from .continuation import validate_hide_tail
+ hide_tail_frames = validate_hide_tail(request.get('hide_tail_frames', 0))
+ if hide_tail_frames:
+ metrics['hide_tail_frames'] = hide_tail_frames
if 'sampling_plan' in request:
from .two_pass import plan
expected = plan(request['geometry'], request['sampling_plan']['requested'],
@@ -115,7 +119,7 @@ def generate(request, resident=None):
request['continuation'] = continuation
request['engine_options'] = dict(request['engine_options'],
adaln_task=ANCHOR_ADALN_TASK if continuation.get('anchor') else ADALN_TASK)
- metrics['continuation'] = summary(continuation)
+ metrics['continuation'] = summary(continuation, hide_tail_frames=hide_tail_frames)
metrics['audio_context'] = continuation['audio_context']
metrics['device_memory'] = device_memory_report(request['gpu_budget_bytes'], request.get('allocator_limit_bytes'),
reserve_bytes=request.get('gpu_reserve_bytes', 0), capacity_trial=request.get('capacity_trial', False))
@@ -240,7 +244,7 @@ def generate(request, resident=None):
return
try:
from .continuation import tail
- first_tail = tail(video)
+ first_tail = tail(video, **({'hide_tail_frames': hide_tail_frames} if hide_tail_frames else {}))
except Exception as error:
tail_failure(error)
first_tail = None
@@ -253,7 +257,7 @@ def generate(request, resident=None):
**({'continuation_tail_callback': restore_tail} if continuable else {}))
metrics.update(sampled, phase='decode', decode_phase='latent_transfer')
if continuation is not None:
- metrics['continuation'] = summary(continuation)
+ metrics['continuation'] = summary(continuation, hide_tail_frames=hide_tail_frames)
save(request['metrics'], metrics)
print(json.dumps(dict(event='decode_resume', sampling_source_attempt=metrics['sampling_source_attempt'])), flush=True)
fit_decoder()
@@ -321,7 +325,8 @@ def generate(request, resident=None):
try:
from .continuation import tail_data
continuation_data = tail_data(first_tail, latents, audio, canvas,
- request['sampling_plan'], manifest, continuation)
+ request['sampling_plan'], manifest, continuation,
+ **({'hide_tail_frames': hide_tail_frames} if hide_tail_frames else {}))
except Exception as error:
tail_failure(error)
continuation_data = None
@@ -636,6 +641,7 @@ def generate(request, resident=None):
# Older retained sampling tails predate the predecessor binding.
continuation_data['metadata']['source_id'] = continuation['source_id']
metrics.update(decode_to_file(latents, audio, request['output'], base=base, artifacts_dir=artifacts,
+ **({'hide_tail_frames': hide_tail_frames} if hide_tail_frames else {}),
**({'continuation': continuation} if continuation is not None else {}),
**({'audio_lead_in_callback': keep_audio_lead_in}
if continuation is not None and continuation_data is not None else {}),