Update nodes_bernini.py

This commit is contained in:
kijai 2026-06-02 00:17:43 +03:00
parent 46ba987361
commit f87432bafb

View File

@ -24,10 +24,17 @@ class BerniniConditioning(io.ComfyNode):
which the Wan model appends as extra tokens with per-stream source_id rope.
The task is inferred from which inputs are connected:
(nothing) -> t2v
source_video -> v2v
source_video + ref images -> rv2v
ref images only -> r2v (each kept at native aspect)
(nothing) -> t2v
source_video -> v2v
source_video + ref images -> rv2v
ref images only -> r2v (each kept at native aspect)
source_video + ref_video -> video insertion / "ads2v"
source_video is the edit base / canvas (resized to width x height).
reference_video is moving content to composite in (e.g. a clip to play on a
screen), kept at its native aspect like the reference images. Streams are
ordered source_video, reference_video, then reference_images -> source_id
1, 2, 3... matching the reference repo's [base, content, refs].
"""
@classmethod
@ -46,7 +53,8 @@ class BerniniConditioning(io.ComfyNode):
io.Int.Input("height", default=480, min=16, max=8192, step=16),
io.Int.Input("length", default=81, min=1, max=8192, step=4),
io.Int.Input("batch_size", default=1, min=1, max=4096),
io.Image.Input("source_video", optional=True, tooltip="Source video to edit/restyle (original task v2v or rv2v). Resized to width/height and trimmed to length."),
io.Image.Input("source_video", optional=True, tooltip="Source video to edit/restyle (task v2v or rv2v). Resized to width/height and trimmed to length. Acts as the edit base / canvas."),
io.Image.Input("reference_video", optional=True, tooltip="Moving content to composite into the source video (video insertion / ads2v), e.g. a clip to play on a screen. Kept at native aspect (long edge capped at ref_max_size), trimmed to length."),
io.Image.Input("reference_images", optional=True, tooltip="Reference image(s) injected as in-context tokens (task r2v or rv2v). Each is kept at its native aspect ratio, long edge capped at ref_max_size."),
io.Int.Input("ref_max_size", default=848, min=16, max=8192, step=16, optional=True),
],
@ -59,17 +67,21 @@ class BerniniConditioning(io.ComfyNode):
@classmethod
def execute(cls, positive, negative, vae, width, height, length, batch_size,
source_video=None, reference_images=None, ref_max_size=848) -> io.NodeOutput:
source_video=None, reference_video=None, reference_images=None, ref_max_size=848) -> io.NodeOutput:
latent = torch.zeros([batch_size, 16, ((length - 1) // 4) + 1, height // 8, width // 8],
device=comfy.model_management.intermediate_device())
# Ordered list of condition streams: source video (source_id 1) first,
# then each reference image (source_id 2, 3, ...), the model assigns the source_id from list order.
# Ordered list of condition streams -> source_id by list order:
# source_video (1), reference_video (2), reference_images (3, 4, ...).
context = []
if source_video is not None:
vid = comfy.utils.common_upscale(source_video[:length, :, :, :3].movedim(-1, 1), width, height, "area", "center").movedim(1, -1)
context.append(vae.encode(vid[:, :, :, :3]))
if reference_video is not None:
ref_vid = _resize_long_edge(reference_video[:length], ref_max_size) # moving content, native aspect
context.append(vae.encode(ref_vid[:, :, :, :3]))
if reference_images is not None:
for i in range(reference_images.shape[0]):
img = _resize_long_edge(reference_images[i:i + 1], ref_max_size) # native aspect per ref