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.

First-frame reference: bridge and engine decide with one function

Bowen Xuec41d7814450e
diff --git a/freevideo_engine/comfy_bridge.py b/freevideo_engine/comfy_bridge.py
index cddb66c..231064b 100644
--- a/freevideo_engine/comfy_bridge.py
+++ b/freevideo_engine/comfy_bridge.py
@@ -634,9 +634,9 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
# The engine decides the same way from the same record: whether the film's first frame is there to use.
anchored = False
if continue_from is not None and first_frame_reference:
- from .continuation import chain_first_frame
+ from .continuation import chain_first_frame_picture
try:
- anchored = chain_first_frame(continuation, continue_from) is not None
+ anchored = chain_first_frame_picture(continuation, continue_from) is not None
except ValueError:
pass
environment = engine_environment(root, source, environ)
diff --git a/freevideo_engine/continuation.py b/freevideo_engine/continuation.py
index f4dc9b8..b262bb0 100644
--- a/freevideo_engine/continuation.py
+++ b/freevideo_engine/continuation.py
@@ -173,6 +173,18 @@ def chain_first_frame(request, video_path=None):
raise ValueError('Invalid first frame') from None
+def chain_first_frame_picture(request, video_path=None):
+ """(PNG bytes, width, height) of the picture a continuation of `request` is given; None when nothing
+ has the film's first frame. The bridge and the engine both decide with this, so they cannot disagree."""
+ try:
+ kept = chain_first_frame(request, video_path)
+ return None if kept is None else first_frame_reference(unpack_first_frame(kept))
+ except (ValueError, MemoryError):
+ raise
+ except Exception:
+ raise ValueError('Invalid first frame') from None
+
+
def _chain_first_frame(request, video_path):
metadata = _snapshot_value(request)['metadata']
if metadata.get('first_frame') is not None:
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index 6771089..d2137e5 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -395,9 +395,9 @@ def _run(args):
continuation = prepare_continuation(continue_from, canvas)
continuation = dict(continuation, audio_context=audio_context(), source_video=str(continue_from))
if first_frame is not None:
- from .continuation import anchor_media, chain_first_frame, first_frame_reference, unpack_first_frame
+ from .continuation import anchor_media, chain_first_frame_picture
try:
- kept = chain_first_frame(continuation, continue_from)
+ kept = chain_first_frame_picture(continuation, continue_from)
except ValueError:
kept = None
first_frame['reason'] = 'unreadable'
@@ -409,7 +409,7 @@ def _run(args):
raise FileExistsError(args.out.resolve())
args.out.resolve().parent.mkdir(parents=True, exist_ok=True)
continue_anchor = args.out.resolve().with_suffix('.first-frame.png')
- picture, picture_width, picture_height = first_frame_reference(unpack_first_frame(kept))
+ picture, picture_width, picture_height = kept
continue_anchor.write_bytes(picture)
media = anchor_media(media, continue_anchor)
validate_route(task=getattr(args, 'task', None) or 'ref2va', anchor=True, two_pass=two_pass,