HEL-892: pin bounded VHS combine and video load reference contracts

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-30 04:11:19 +08:00
co-authored by multica-agent
parent 846d6fcbfe
commit ab4e47e662
88 changed files with 74883 additions and 28 deletions
@@ -33,6 +33,7 @@ from calliope.comfyui.serialization_reference import (
PROFILE,
REEL_PROFILE,
SEPARATION_PROFILE,
VHS_PROFILES,
resolve_reference_link,
serialize_case04_node,
serialize_promoted_node,
@@ -291,6 +292,7 @@ REFERENCE_PROFILES = (
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
)
@@ -455,10 +457,45 @@ def media_field_evidence(source, prompt, profile):
return fields
def vhs_field_evidence(source, prompt):
"""Re-read every final field from named source bytes or original links."""
fields = []
for i, node in enumerate(source["nodes"]):
nid = str(node["id"])
assert prompt[nid]["class_type"] == node["type"]
assert prompt[nid]["_meta"] == {"title": node.get("title") or node["type"]}
for name, value in prompt[nid]["inputs"].items():
socket = next(s for s in node["inputs"] if s["name"] == name)
if socket.get("link") is not None:
li, link = next(
(j, edge) for j, edge in enumerate(source["links"]) if edge[0] == socket["link"]
)
expected = [str(link[1]), link[2]]
pointer = f"/links/{li}"
else:
expected = node["widgets_values"][name]
pointer = f"/nodes/{i}/widgets_values/{name}"
assert type(value) is type(expected) and value == expected
fields.append(
{
"node_id": nid,
"class_type": node["type"],
"field": name,
"value": value,
"json_type": type(value).__name__,
"source_pointer": pointer,
}
)
return fields
def profile_attempt(source, profile):
expected = {**STRUCTURE_PROFILES, **PROMOTED_PROFILES, CASE04_PROFILE: "1.53.6"}.get(
profile, "1.37.11"
)
expected = {
**STRUCTURE_PROFILES,
**PROMOTED_PROFILES,
CASE04_PROFILE: "1.53.6",
**VHS_PROFILES,
}.get(profile, "1.37.11")
assumptions = {
"frontend": expected,
"unmodified_frontend_and_widgets": True,
@@ -522,8 +559,20 @@ def profile_attempt(source, profile):
"separation-reference/sources.json",
*assumptions["reference_sources"],
]
if profile in VHS_PROFILES:
assumptions["vhs_reference"] = {
"contracts": "vhs-reference/contract.json",
"unmodified_pinned_plugin_and_format_files": True,
"extension_overrides_and_target_installation": "unknown",
"named_mirror": "if present, assumed inert and required equal to VHS map",
"array_migration": "unsupported; never fill missing fields from defaults",
}
assumptions["reference_sources"] = [
"vhs-reference/sources.json",
"serialization-evidence/sources.json",
]
base = {"profile": profile, "assumptions": assumptions}
if profile in CROP_SPLIT_PROFILES:
if profile in (*CROP_SPLIT_PROFILES, *VHS_PROFILES):
base["source_declarations"] = [
{
"pointer": f"/nodes/{i}",
@@ -531,32 +580,48 @@ def profile_attempt(source, profile):
}
for i, n in enumerate(source.get("nodes", []))
]
base["verified_reference_facts"] = "crop-split-reference/verified-facts.json"
base["verified_reference_facts"] = (
"vhs-reference/contract.json"
if profile in VHS_PROFILES
else "crop-split-reference/verified-facts.json"
)
declared_frontend = (source.get("extra") or {}).get("frontendVersion")
assumptions["source_frontend_declaration"] = declared_frontend
if profile in VHS_PROFILES:
assumptions["vhs_reference"]["missing_frontend_policy"] = (
"explicit_1.37.11_reference_assumption"
if expected == "1.37.11"
else "requires_explicit_1.48.6"
)
assumptions["missing_frontend_policy"] = (
"explicit_media_reference_assumption"
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES)
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES)
else "explicit_legacy_reference_assumption"
if profile in (PROFILE, AUX_PROFILE, PRIMITIVE_PROFILE)
else "requires_explicit_declaration"
)
if profile in VHS_PROFILES and expected == "1.48.6":
assumptions["missing_frontend_policy"] = "requires_explicit_1.48.6"
assumptions["missing_node_declarations"] = [
n["pointer"]
for n in node_inventory(source, include_aux=profile in CROP_SPLIT_PROFILES)
if n["type"] not in ("Note", "MarkdownNote", "Reroute", "PrimitiveNode")
and (n["provider"] is None or n["version"] is None)
]
if declared_frontend != expected and not (
declared_frontend is None
and profile
in (
PROFILE,
AUX_PROFILE,
PRIMITIVE_PROFILE,
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
if (profile in VHS_PROFILES and expected == "1.48.6" and declared_frontend is None) or (
declared_frontend != expected
and not (
declared_frontend is None
and profile
in (
PROFILE,
AUX_PROFILE,
PRIMITIVE_PROFILE,
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
)
)
):
return {
@@ -593,8 +658,10 @@ def profile_attempt(source, profile):
**(
{"field_evidence": asr_field_evidence(source, result.prompt)}
if profile == ASR_PROFILE
else {"field_evidence": vhs_field_evidence(source, result.prompt)}
if profile in VHS_PROFILES
else {"field_evidence": media_field_evidence(source, result.prompt, profile)}
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES)
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES)
else {}
),
}
@@ -698,7 +765,10 @@ def audit_library(repo: Path, profiles=REFERENCE_PROFILES, *, baseline_profiles=
for cohort in ("without_companion", "with_companion")
}
if baseline_profiles is None:
baseline_profiles = tuple(p for p in profiles if p not in CROP_SPLIT_PROFILES)
excluded_profiles = (
VHS_PROFILES if any(p in VHS_PROFILES for p in profiles) else CROP_SPLIT_PROFILES
)
baseline_profiles = tuple(p for p in profiles if p not in excluded_profiles)
old_complete = {
row["source_path"]
for row in rows
@@ -754,6 +824,7 @@ def main():
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
PROFILE,
AUX_PROFILE,
PRIMITIVE_PROFILE,
@@ -10,6 +10,7 @@ installation is inferred.
from __future__ import annotations
import json
import math
from typing import Any
@@ -22,6 +23,13 @@ CROP_PROFILE = "comfy-frontend-1.37.11-audio-crop-1.4.0-core-0.3.68-reference"
SPLIT_PROFILE = "comfy-frontend-1.37.11-guhai-885cac3d-core-0.21.1-reference"
CROP_SPLIT_PROFILES = (CROP_PROFILE, SPLIT_PROFILE)
VHS_COMBINE_COMMIT = "4ee72c065db22c9d96c2427954dc69e7b908444b"
VHS_LOAD_COMMIT = "8550981384301e9bc5bfea83e5c2c75258102593"
VHS_PROFILES = {
"comfy-frontend-1.37.11-vhs-pinned-reference": "1.37.11",
"comfy-frontend-1.48.6-vhs-pinned-reference": "1.48.6",
}
ASR_PROFILE = "comfy-frontend-1.37.11-asr-b037d7be-reference"
PROFILE = "comfy-frontend-1.37.11-core-reference"
AUX_PROFILE = "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference"
@@ -92,6 +100,8 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
"output": outputs,
}
if profile in VHS_PROFILES:
return vhs_definitions()
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
return media_definitions(profile)
if profile == ASR_PROFILE:
@@ -166,6 +176,8 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
def serialize_reference_widgets(node: dict[str, Any], profile: str = PROFILE) -> dict[str, Any]:
"""Apply only the pinned identity serializers; reject any extra/missing value."""
if profile in VHS_PROFILES:
return serialize_vhs_node(node)
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
return serialize_media_node(node, profile)
if profile == ASR_PROFILE:
@@ -1316,3 +1328,186 @@ def serialize_media_node(node, profile):
if ct in ("LoadAudio", "SaveAudioMP3", "PreviewAudio"):
result["audioUI"] = ""
return result
# Only named-map state with every execution field present is covered. VHS's
# legacy six-value arrays run migrations/default fallbacks and are rejected.
# Sources: docs/hel-892/vhs-reference/{4ee72c06,85509813}/ and sources.json.
_VHS_COMBINE = {
"frame_rate": "FLOAT",
"loop_count": "INT",
"filename_prefix": "STRING",
"format": "COMBO",
"pingpong": "BOOLEAN",
"save_output": "BOOLEAN",
"pix_fmt": "COMBO",
"crf": "INT",
"save_metadata": "BOOLEAN",
"trim_to_audio": "BOOLEAN",
}
_VHS_LOAD = {
"video": "COMBO",
"force_rate": "FLOAT",
"custom_width": "INT",
"custom_height": "INT",
"frame_load_cap": "INT",
"skip_first_frames": "INT",
"select_every_nth": "INT",
"format": "COMBO",
}
def vhs_definitions():
"""Two fixed classes, h264-mp4/AnimateDiff, IMAGE without VAE only."""
def spec(required, optional, output):
return {
"input": {
"required": {k: [v] for k, v in required.items()},
"optional": {k: [v] for k, v in optional.items()},
},
"output": output,
}
return {
"VHS_VideoCombine": spec(
{"images": "IMAGE", **_VHS_COMBINE},
{"audio": "AUDIO", "meta_batch": "VHS_BatchManager", "vae": "VAE"},
["VHS_FILENAMES"],
),
"VHS_LoadVideo": spec(
{k: v for k, v in _VHS_LOAD.items() if k != "format"},
{"meta_batch": "VHS_BatchManager", "vae": "VAE", "format": "COMBO"},
["IMAGE", "INT", "AUDIO", "VHS_VIDEOINFO"],
),
}
def serialize_vhs_node(node):
"""Bounded restored state, before queue hooks; never run preview callbacks.
VHS useKVState calls callbacks during restore (unlike plain core restore).
Accept only values that are fixed points of the pinned callbacks. UI state
is persisted by onSerialize despite options.serialize=false, but excluded
from graphToPrompt. This does not assert target extensions or file access.
"""
ct, props = node.get("type"), node.get("properties") or {}
if ct not in vhs_definitions():
raise ValueError("VHS固定参考未覆盖此类")
expected = VHS_COMBINE_COMMIT if ct == "VHS_VideoCombine" else VHS_LOAD_COMMIT
if (
props.get("cnr_id") != "comfyui-videohelpersuite"
or props.get("ver") != expected
or props.get("aux_id") is not None
or type(node.get("mode", 0)) is not int
or node.get("mode", 0) != 0
):
raise ValueError("VHS提供方/完整提交/模式冲突;不使用发布号替代")
for container in (node, props):
if any(k in container for k in ("widgets", "serializeValue", "comfyDynamic")):
raise ValueError("VHS自定义控件或serializer覆盖未知")
ue = props.get("ue_properties") or {}
if "widgets_values_named" in props or any(
ue.get(k) for k in ("widget_ue_connectable", "input_ue_unconnectable")
):
raise ValueError("VHS不覆盖UE控件改写")
layout = _VHS_COMBINE if ct == "VHS_VideoCombine" else _VHS_LOAD
values = node.get("widgets_values")
# Upload button is skipped on restore and options.serialize=false in prompt.
allowed = set(layout) | {"videopreview"}
if ct == "VHS_LoadVideo":
allowed.add("choose video to upload")
if not isinstance(values, dict) or not set(layout) <= set(values) <= allowed:
raise ValueError("VHS仅覆盖完整具名对象;数组迁移/缺项/额外动态项不补默认")
named = node.get("widgets_values_named")
if named is not None and (
type(named) is not dict
or json.dumps(named, sort_keys=True, allow_nan=False)
!= json.dumps(values, sort_keys=True, allow_nan=False)
):
raise ValueError("VHS额外具名镜像冲突")
if "choose video to upload" in values and values["choose video to upload"] != "image":
raise ValueError("VHS上传按钮占位未知")
preview = values.get("videopreview")
if preview is not None and (
type(preview) is not dict
or set(preview) - {"hidden", "paused", "params", "muted"}
or any(type(preview[k]) is not bool for k in ("hidden", "paused", "muted") if k in preview)
or ("params" in preview and type(preview["params"]) is not dict)
):
raise ValueError("VHS持久化预览状态形状未知")
result = {}
for name, kind in layout.items():
value = values[name]
valid = (
type(value) in (int, float) and math.isfinite(value)
if kind == "FLOAT"
else type(value) is int
if kind == "INT"
else type(value) is bool
if kind == "BOOLEAN"
else type(value) is str
)
if not valid or (type(value) is int and abs(value) > 2**53 - 1):
raise ValueError(f"VHS字段{name}类型或JavaScript精确整数范围不符")
if type(value) is str and any(t in value for t in ("%", "{", "}")):
raise ValueError("VHS动态表达式不在字面量参考内")
result[name] = value
bounds = (
{"frame_rate": (1, float("inf")), "loop_count": (0, 100), "crf": (0, 100)}
if ct == "VHS_VideoCombine"
else {
"force_rate": (0, 60),
"custom_width": (0, 8192),
"custom_height": (0, 8192),
"frame_load_cap": (0, 2**53 - 1),
"skip_first_frames": (0, 2**53 - 1),
"select_every_nth": (1, 2**53 - 1),
}
)
for name, (low, high) in bounds.items():
if not low <= result[name] <= high:
raise ValueError(f"VHS字段{name}超出固定参考边界")
if ct == "VHS_VideoCombine":
if result["format"] != "video/h264-mp4" or result["pix_fmt"] not in (
"yuv420p",
"yuv420p10le",
):
raise ValueError("VHS仅证明固定h264-mp4及其四项动态控件")
elif result["format"] != "AnimateDiff" or any(
result[k] % 8 for k in ("custom_width", "custom_height")
):
raise ValueError("VHS仅证明AnimateDiff;尺寸必须是恢复回调的不变点(8倍数或0)")
spec = vhs_definitions()[ct]["input"]
slots = {k: v[0] for k, v in {**spec["required"], **spec["optional"]}.items()}
sockets = node.get("inputs", [])
names = [s.get("name") for s in sockets]
if len(names) != len(set(names)) or set(names) != set(slots):
raise ValueError("VHS输入槽缺失/额外/重复")
for socket in sockets:
name = socket["name"]
expected_type = ["yuv420p", "yuv420p10le"] if name == "pix_fmt" else slots[name]
# Some original workflow exports store the dynamic combo as COMBO;
# both are the pinned config's exact two-option combo representation.
valid_type = (
socket.get("type") in (expected_type, "COMBO")
if name == "pix_fmt"
else socket.get("type") == expected_type
)
if not valid_type:
raise ValueError("VHS输入槽类型与固定schema不符")
if socket.get("widget") != ({"name": name} if name in layout else None):
raise ValueError("VHS具名控件绑定不符")
if socket.get("link") is not None and (
name in ("vae", "meta_batch") or (name in layout and name != "frame_rate")
):
raise ValueError("VHS控件转连线/VAE/批次模式未覆盖")
outputs = node.get("outputs", [])
if [s.get("type") for s in outputs] != vhs_definitions()[ct]["output"]:
raise ValueError("VHS返回类型/槽不符")
for i, socket in enumerate(outputs):
if "slot_index" in socket and (
type(socket["slot_index"]) is not int or socket["slot_index"] != i
):
raise ValueError("VHS原输出槽索引冲突")
return result
@@ -23,6 +23,7 @@ from .serialization_reference import (
PRIMITIVE_PROFILE,
PROFILE,
SEPARATION_PROFILE,
VHS_PROFILES,
case04_definitions,
fold_reference_primitives,
promoted_definitions,
@@ -65,6 +66,7 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
AUX_PROFILE,
PRIMITIVE_PROFILE,
PREVIEW_PROFILE,
@@ -81,6 +83,12 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
True,
)
try:
if (
profile in VHS_PROFILES
and VHS_PROFILES[profile] == "1.48.6"
and (source.get("extra") or {}).get("frontendVersion") != "1.48.6"
):
raise ValueError("VHS 1.48.6参考要求显式前端声明;缺失仅选择1.37.11")
if profile in (*STRUCTURE_PROFILES, *PROMOTED_PROFILES, CASE04_PROFILE):
case04 = profile == CASE04_PROFILE
promoted = profile in PROMOTED_PROFILES or case04
@@ -128,11 +136,14 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
and (source.get("extra") or {}).get("frontendVersion") != "1.37.11"
):
raise ValueError("PreviewAny 需要显式1.37.11前端声明")
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES) and any(
node.get("type") == "Reroute" for node in source.get("nodes", [])
):
if profile in (
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
) and any(node.get("type") == "Reroute" for node in source.get("nodes", [])):
raise ValueError("媒体最小参考仅覆盖直接连线,不扩展虚拟节点")
if profile in (SEPARATION_PROFILE, *CROP_SPLIT_PROFILES) and any(
if profile in (SEPARATION_PROFILE, *CROP_SPLIT_PROFILES, *VHS_PROFILES) and any(
(source.get("extra") or {}).get(k) for k in ("ue_links", "links_added_by_ue")
):
raise ValueError("音频分离参考不覆盖UE附加连线")
@@ -147,7 +158,13 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
except (ValueError, TypeError, KeyError, AttributeError, IndexError) as exc:
return Conversion(None, [{"code": "invalid_reference_contract", "message": str(exc)}], True)
result.reference_only = True
if profile in (ASR_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
if profile in (
ASR_PROFILE,
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
):
result.serialization_stage = "restored_saved_state_before_queue_hooks"
return result
@@ -208,6 +225,7 @@ def _convert(
**STRUCTURE_PROFILES,
**PROMOTED_PROFILES,
CASE04_PROFILE: "1.53.6",
**VHS_PROFILES,
}.get(reference_profile, "1.37.11")
if frontend_version is not None and frontend_version != expected_version:
fail("reference_frontend_mismatch", "源图声明的前端版本与固定参考不一致")
@@ -228,7 +246,12 @@ def _convert(
for lid in links:
try:
resolve_reference_link(nodes, links, lid)
if reference_profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
if reference_profile in (
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
*VHS_PROFILES,
):
link = links[lid]
upstream = nodes[str(link[1])]["outputs"][link[2]]
downstream = nodes[str(link[3])]["inputs"][link[4]]
@@ -359,7 +359,11 @@ def test_old_mp3_profile_rejects_real_graph_and_new_profile_rejects_old_core():
def test_library_actual_delta_keeps_every_old_attempt_and_all_six_golden_comparisons():
previous = json.loads((REPO / "docs/hel-892/media-evidence/library.json").read_bytes())
profiles = tuple(p for p in audit.REFERENCE_PROFILES if p not in audit.CROP_SPLIT_PROFILES)
profiles = tuple(
p
for p in audit.REFERENCE_PROFILES
if p not in (*audit.CROP_SPLIT_PROFILES, *audit.VHS_PROFILES)
)
baseline = tuple(p for p in profiles if p != SEPARATION_PROFILE)
old = audit.audit_library(REPO, baseline)
current = audit.audit_library(REPO, profiles, baseline_profiles=baseline)
@@ -16,6 +16,7 @@ from calliope.comfyui.serialization_reference import (
CROP_SPLIT_PROFILES,
SEPARATION_PROFILE,
SPLIT_PROFILE,
VHS_PROFILES,
serialize_reference_widgets,
)
from calliope.comfyui.ui2api import convert, convert_reference
@@ -350,12 +351,13 @@ def test_two_disjoint_instances_preserve_nodes_links_and_values(profile):
def test_all_old_fourteen_profiles_attempts_gaps_and_six_differences_unchanged():
profiles = tuple(p for p in audit.REFERENCE_PROFILES if p not in CROP_SPLIT_PROFILES)
historical_profiles = tuple(p for p in audit.REFERENCE_PROFILES if p not in VHS_PROFILES)
profiles = tuple(p for p in historical_profiles if p not in CROP_SPLIT_PROFILES)
historical = json.loads((REPO / "docs/hel-892/separation-evidence/library.json").read_bytes())
baseline = audit.audit_library(REPO, profiles)
current = audit.audit_library(REPO)
current = audit.audit_library(REPO, historical_profiles)
assert baseline["gap_groups"] == historical["gap_groups"]
assert len(profiles) == 14 and len(audit.REFERENCE_PROFILES) == 16
assert len(profiles) == 14 and len(historical_profiles) == 16
assert current["coverage_delta"]["baseline_profiles"] == list(profiles)
assert current["coverage_delta"]["new_complete_paths"] == [CROP]
assert len(current["coverage_delta"]["current_complete_paths"]) == 8
@@ -0,0 +1,375 @@
"""Pinned source bytes and synthetic graphs only; no plugins/media are executed."""
from __future__ import annotations
import ast
import copy
import hashlib
import json
from pathlib import Path
import pytest
from scripts import audit_reference_conversion as audit
from scripts.verify_frontend_sources import verify
from calliope.comfyui.serialization_reference import (
VHS_COMBINE_COMMIT,
VHS_LOAD_COMMIT,
VHS_PROFILES,
serialize_vhs_node,
)
from calliope.comfyui.ui2api import convert, convert_reference
REPO = Path(__file__).resolve().parents[2]
ROOT = REPO / "docs/hel-892/vhs-reference"
PREFIX = "example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/"
LOAD = PREFIX + "多视频合成分屏展示.json"
COMBINE = (
"example_ComfyUI_workflows/4-视频生成/Minimax-h3/"
"Minimax_H3_T8双时钟采样_参考生视频-8步高质量极速版.json"
)
def real_node(path, nid):
return next(n for n in json.loads((REPO / path).read_bytes())["nodes"] if n["id"] == nid)
def synthetic():
# This pair is not a source workflow, target export or encoding/history test.
load, combine = real_node(LOAD, 17), real_node(COMBINE, 12)
for n in (load, combine):
n.pop("widgets_values_named", None)
for s in n["inputs"]:
s["link"] = None
for s in n["outputs"]:
s["links"] = []
load["outputs"][0]["links"] = [1]
load["outputs"][2]["links"] = [2]
combine["inputs"][0]["link"] = 1
combine["inputs"][1]["link"] = 2
return {
"nodes": [load, combine],
"links": [[1, 17, 0, 12, 0, "IMAGE"], [2, 17, 2, 12, 1, "AUDIO"]],
}
def test_pinned_bytes_registration_schema_and_js_boundaries():
assert len(verify(ROOT)["sources_verified"]) == len(
json.loads((ROOT / "sources.json").read_bytes())["sources"]
)
for commit, ct, clsname, filename in (
(VHS_COMBINE_COMMIT, "VHS_VideoCombine", "VideoCombine", "nodes.py"),
(VHS_LOAD_COMMIT, "VHS_LoadVideo", "LoadVideoUpload", "load_video_nodes.py"),
):
base = ROOT / commit[:8]
tree = ast.parse((base / "videohelpersuite" / filename).read_bytes())
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == clsname)
schema = next(
n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "INPUT_TYPES"
)
assert schema.lineno > 0
mappings = (base / "videohelpersuite/nodes.py").read_text()
assert f'"{ct}": {clsname},' in mappings
js = (base / "web/js/VHS.core.js").read_text()
assert "w.value = widgetDict[w.name];" in js
assert "w.callback?.(w.value)" in js
assert "info.widgets_values[w.name] = w.value;" in js
assert "uploadWidget.options.serialize = false;" in js
assert 'this.addDOMWidget("videopreview", "preview", element, {' in js
assert "serialize: false," in js
assert (
'VHS_VideoCombine : ["frame_rate", "loop_count", "filename_prefix", '
'"format", "pingpong", "save_image"]' in js
)
fmt = json.loads((ROOT / "4ee72c06/video_formats/h264-mp4.json").read_bytes())
assert fmt["main_pass"][4] == ["pix_fmt", ["yuv420p", "yuv420p10le"]]
assert fmt["main_pass"][6] == ["crf", "INT", {"default": 19, "min": 0, "max": 100, "step": 1}]
assert fmt["save_metadata"] == ["save_metadata", "BOOLEAN", {"default": True}]
assert fmt["trim_to_audio"] == ["trim_to_audio", "BOOLEAN", {"default": False}]
exe = (ROOT / "frontend-1.48.6/src/utils/executionUtil.ts").read_text()
assert "widget.options?.serialize === false" in exe
assert "await widget.serializeValue(node, i)" in exe
wrapper = (ROOT / "frontend-1.48.6/src/scripts/utils.ts").read_text()
assert "return _applyTextReplacements(app.rootGraph, value)" in wrapper
@pytest.mark.parametrize("profile", VHS_PROFILES)
def test_synthetic_complete_typed_fields_nonzero_audio_slot_and_ui_omission(profile):
source = synthetic()
if VHS_PROFILES[profile] == "1.48.6":
assert convert_reference(source, profile).prompt is None
assert audit.profile_attempt(source, profile)["status"] == "not_applicable"
source["extra"] = {"frontendVersion": VHS_PROFILES[profile]}
result = convert_reference(source, profile)
assert result.prompt is not None and result.reference_only
assert result.prompt["12"]["inputs"]["audio"] == ["17", 2]
assert result.prompt["12"]["inputs"]["images"] == ["17", 0]
assert len(audit.vhs_field_evidence(source, result.prompt)) == 20
assert not any("videopreview" in n["inputs"] for n in result.prompt.values())
assert not convert(source).prompt
before = copy.deepcopy(result.prompt)
source["nodes"][0]["widgets_values"]["videopreview"]["params"]["filename"] = "other.mp4"
source["nodes"][0]["widgets_values"]["choose video to upload"] = "image"
assert convert_reference(source, profile).prompt == before
source["nodes"][0]["widgets_values"]["video"] = "第二个.mp4"
source["nodes"][0]["widgets_values"]["skip_first_frames"] = 41
source["nodes"][1]["widgets_values"]["crf"] = 37
source["nodes"][1]["widgets_values"]["pix_fmt"] = "yuv420p10le"
prompt = convert_reference(source, profile).prompt
assert prompt["17"]["inputs"]["video"] == "第二个.mp4"
assert prompt["17"]["inputs"]["skip_first_frames"] == 41
assert prompt["12"]["inputs"]["crf"] == 37
assert prompt["12"]["inputs"]["pix_fmt"] == "yuv420p10le"
@pytest.mark.parametrize(
"index,field,value",
[
(0, "force_rate", True),
(0, "force_rate", None),
(0, "force_rate", float("inf")),
(0, "force_rate", -1),
(0, "force_rate", 61),
(0, "video", 12),
(0, "custom_width", 513),
(0, "custom_height", 8193),
(0, "custom_width", True),
(0, "frame_load_cap", 1.2),
(0, "frame_load_cap", 2**53),
(0, "skip_first_frames", -1),
(0, "select_every_nth", 0),
(0, "format", "Wan"),
(0, "format", "custom"),
(1, "format", "image/webp"),
(1, "format", "video/custom"),
(1, "pix_fmt", "rgb24"),
(1, "crf", 101),
(1, "crf", True),
(1, "frame_rate", float("nan")),
(1, "frame_rate", 0),
(1, "loop_count", -1),
(1, "loop_count", 1.0),
(1, "pingpong", 1),
(1, "save_output", None),
(1, "trim_to_audio", "false"),
(1, "filename_prefix", "%date:yyyy%"),
(1, "filename_prefix", "{unknown}"),
],
)
def test_invalid_fields_fail_whole_graph_without_partial_prompt(index, field, value):
source = synthetic()
source["nodes"][index]["widgets_values"][field] = value
result = convert_reference(source, next(iter(VHS_PROFILES)))
assert result.prompt is None and result.issues
@pytest.mark.parametrize(
"change",
[
"provider",
"release",
"other_commit",
"aux",
"array",
"extra_value",
"missing_value",
"mirror_type",
"mirror_value",
"binding",
"socket_type",
"extra_socket",
"missing_socket",
"mode",
"bool_mode",
"ue",
"override",
"prop_override",
"vae",
"batch",
"extra_output",
"output_type",
"output_index",
"bool_index",
"bad_source_slot",
"bad_target_slot",
"bad_link_type",
"missing_reciprocal",
"wrong_frontend",
"unknown_node",
"preview_shape",
],
)
def test_contract_mutations_reject(change):
source = synthetic()
n = source["nodes"][0]
if change == "provider":
n["properties"]["cnr_id"] = "same-name-plugin"
elif change == "release":
n["properties"]["ver"] = "1.7.7"
elif change == "other_commit":
n["properties"]["ver"] = VHS_COMBINE_COMMIT
elif change == "aux":
n["properties"]["aux_id"] = "other"
elif change == "array":
n["widgets_values"] = list(n["widgets_values"].values())
elif change == "extra_value":
n["widgets_values"]["custom"] = 1
elif change == "missing_value":
del n["widgets_values"]["format"]
elif change.startswith("mirror"):
n["widgets_values_named"] = copy.deepcopy(n["widgets_values"])
n["widgets_values_named"]["force_rate"] = 16.0 if change == "mirror_type" else 20
elif change == "binding":
n["inputs"][2]["widget"] = {"name": "wrong"}
elif change == "socket_type":
n["inputs"][2]["type"] = "STRING"
elif change == "extra_socket":
n["inputs"].append(copy.deepcopy(n["inputs"][0]))
elif change == "missing_socket":
n["inputs"].pop()
elif change == "mode":
n["mode"] = 4
elif change == "bool_mode":
n["mode"] = False
elif change == "ue":
n["properties"]["ue_properties"]["widget_ue_connectable"] = {"video": True}
elif change == "override":
n["serializeValue"] = "custom"
elif change == "prop_override":
n["properties"]["widgets"] = []
elif change == "vae":
n["inputs"][1]["link"] = 1
elif change == "batch":
n["inputs"][0]["link"] = 1
elif change == "extra_output":
n["outputs"].append({"type": "IMAGE", "links": []})
elif change == "output_type":
n["outputs"][0]["type"] = "LATENT"
elif change == "output_index":
n["outputs"][2]["slot_index"] = 0
elif change == "bool_index":
n["outputs"][0]["slot_index"] = False
elif change == "bad_source_slot":
source["links"][0][2] = 1
elif change == "bad_target_slot":
source["links"][0][4] = 2
elif change == "bad_link_type":
source["links"][0][5] = "LATENT"
elif change == "missing_reciprocal":
n["outputs"][0]["links"] = []
elif change == "wrong_frontend":
source["extra"] = {"frontendVersion": "1.7.9"}
elif change == "unknown_node":
source["nodes"].append({"id": 100, "type": "Unknown", "inputs": [], "outputs": []})
elif change == "preview_shape":
n["widgets_values"]["videopreview"] = "server/path.mp4"
assert convert_reference(source, next(iter(VHS_PROFILES))).prompt is None
def test_real_five_load_instances_are_distinct_and_modes_not_dropped():
source = json.loads((REPO / LOAD).read_bytes())
nodes = [n for n in source["nodes"] if n["type"] == "VHS_LoadVideo"]
assert len(nodes) == 5
for n in nodes:
if n["mode"] == 4:
with pytest.raises(ValueError):
serialize_vhs_node(n)
else:
values = serialize_vhs_node(n)
assert all(
type(v) is type(n["widgets_values"][k]) and v == n["widgets_values"][k]
for k, v in values.items()
)
assert convert_reference(source, next(iter(VHS_PROFILES))).prompt is None
def test_old_sixteen_attempts_gaps_candidates_and_six_comparisons_protected():
old = json.loads((REPO / "docs/hel-892/crop-split-evidence/library.json").read_bytes())
profiles = tuple(p for p in audit.REFERENCE_PROFILES if p not in VHS_PROFILES)
baseline = audit.audit_library(REPO, profiles)
now = audit.audit_library(REPO, baseline_profiles=profiles)
assert len(profiles) == 16 and len(now["profiles"]) == 18
assert old["gap_groups"] == baseline["gap_groups"]
for previous, before, after in zip(old["cases"], baseline["cases"], now["cases"]):
assert previous["attempts"] == before["attempts"] == after["attempts"][:-2]
assert previous.get("comparisons") == after.get("comparisons")
assert previous["status"] == after["status"]
assert previous["candidate_hashes"] == after["candidate_hashes"]
assert previous["comparison_status"] == after["comparison_status"]
assert len(now["coverage_delta"]["current_complete_paths"]) == 8
assert now["coverage_delta"]["new_complete_paths"] == []
assert now["coverage_delta"]["baseline_profiles"] == list(profiles)
def unavailable(r):
return {
c["source_path"]
for c in r["cases"]
if all(a["status"] == "not_applicable" for a in c["attempts"])
}
assert unavailable(old) == unavailable(now) and len(unavailable(now)) == 98
for raw in json.loads((ROOT / "sources.json").read_bytes())["sources"]:
assert hashlib.sha256((ROOT / raw["local_file"]).read_bytes()).hexdigest() == raw["sha256"]
def test_disjoint_instances_values_ids_links_not_shared():
first, second = synthetic(), synthetic()
for n in second["nodes"]:
n["id"] += 100
for socket in n["inputs"]:
if socket.get("link") is not None:
socket["link"] += 100
for socket in n["outputs"]:
socket["links"] = [lid + 100 for lid in socket.get("links", [])]
for link in second["links"]:
for i in (0, 1, 3):
link[i] += 100
second["nodes"][0]["widgets_values"]["video"] = "other-file.mp4"
second["nodes"][0]["widgets_values"]["force_rate"] = 29.97
second["nodes"][1]["widgets_values"]["frame_rate"] = 29.97
source = {"nodes": first["nodes"] + second["nodes"], "links": first["links"] + second["links"]}
prompt = convert_reference(source, next(iter(VHS_PROFILES))).prompt
assert set(prompt) == {"17", "12", "117", "112"}
assert prompt["112"]["inputs"]["audio"] == ["117", 2]
assert prompt["12"]["inputs"]["audio"] == ["17", 2]
assert prompt["117"]["inputs"]["video"] == "other-file.mp4"
assert prompt["17"]["inputs"]["video"] != "other-file.mp4"
assert prompt["112"]["inputs"]["frame_rate"] == 29.97
assert len(audit.vhs_field_evidence(source, prompt)) == 40
def test_all_five_real_combines_have_node_contract_even_when_other_nodes_close_graph():
seen = []
for path in (REPO / "example_ComfyUI_workflows").rglob("*"):
if not path.is_file():
continue
source = json.loads(path.read_bytes())
for n in source.get("nodes", []):
if n["type"] == "VHS_VideoCombine" and n["properties"].get("ver") == VHS_COMBINE_COMMIT:
frontend = source.get("extra", {}).get("frontendVersion") or "1.37.11"
if frontend not in VHS_PROFILES.values():
assert all(
audit.profile_attempt(source, p)["status"] == "not_applicable"
for p in VHS_PROFILES
)
continue
values = serialize_vhs_node(n)
assert values["crf"] == n["widgets_values"]["crf"]
assert values["frame_rate"] == n["widgets_values"]["frame_rate"]
seen.append((path, n["id"]))
profile = next(
p
for p, v in VHS_PROFILES.items()
if v == (source.get("extra", {}).get("frontendVersion") or "1.37.11")
)
result = convert_reference(source, profile)
assert result.prompt is None
node_issues = [i for i in result.issues if i.get("node_id") == str(n["id"])]
# The source upstream classes still have no schema in this
# minimal profile; preserve those edge errors, not a partial prompt.
assert node_issues
assert {i["code"] for i in node_issues} <= {
"invalid_output_slot",
"missing_required_input",
}
assert len(seen) == 5
@@ -0,0 +1,437 @@
{
"sha": "4ee72c065db22c9d96c2427954dc69e7b908444b",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/4ee72c065db22c9d96c2427954dc69e7b908444b",
"tree": [
{
"path": ".github",
"mode": "040000",
"type": "tree",
"sha": "7a7002793ebbe7911dded77df496f4b141a46661",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/7a7002793ebbe7911dded77df496f4b141a46661"
},
{
"path": ".github/workflows",
"mode": "040000",
"type": "tree",
"sha": "a0920d307e4ff5f6199f39cf7cd22e853ed9c139",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/a0920d307e4ff5f6199f39cf7cd22e853ed9c139"
},
{
"path": ".github/workflows/publish.yml",
"mode": "100644",
"type": "blob",
"sha": "27bcdb11695ea19286da34cd5f36cf75155a4dbb",
"size": 640,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/27bcdb11695ea19286da34cd5f36cf75155a4dbb"
},
{
"path": ".gitignore",
"mode": "100644",
"type": "blob",
"sha": "9b5379e8f93da3909706b0a7d37f5c8ab5e2a2a5",
"size": 3101,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/9b5379e8f93da3909706b0a7d37f5c8ab5e2a2a5"
},
{
"path": "LICENSE",
"mode": "100644",
"type": "blob",
"sha": "f288702d2fa16d3cdf0035b15a9fcbc552cd88e7",
"size": 35149,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f288702d2fa16d3cdf0035b15a9fcbc552cd88e7"
},
{
"path": "README.md",
"mode": "100644",
"type": "blob",
"sha": "753fcecf9979b40b2427869c6ad5bed1b61df482",
"size": 8877,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/753fcecf9979b40b2427869c6ad5bed1b61df482"
},
{
"path": "__init__.py",
"mode": "100755",
"type": "blob",
"sha": "9fa995f0ac7e296a62bcba9df68b5250a0f7d041",
"size": 398,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/9fa995f0ac7e296a62bcba9df68b5250a0f7d041"
},
{
"path": "pyproject.toml",
"mode": "100644",
"type": "blob",
"sha": "39793ee53bd813c5188a2f65836a72bf541b4d9c",
"size": 425,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/39793ee53bd813c5188a2f65836a72bf541b4d9c"
},
{
"path": "requirements.txt",
"mode": "100644",
"type": "blob",
"sha": "4fa34aa21b85c4b974e2a2b6891eae5fd6dd4164",
"size": 29,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4fa34aa21b85c4b974e2a2b6891eae5fd6dd4164"
},
{
"path": "testframework",
"mode": "040000",
"type": "tree",
"sha": "cb29518c671c9b91a4c2799b026d19260d5dfc33",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/cb29518c671c9b91a4c2799b026d19260d5dfc33"
},
{
"path": "testframework/README.md",
"mode": "100644",
"type": "blob",
"sha": "93cd503563080c9c7d785d419bef7dddc4c11cd8",
"size": 466,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/93cd503563080c9c7d785d419bef7dddc4c11cd8"
},
{
"path": "testframework/__init__.py",
"mode": "100755",
"type": "blob",
"sha": "c75b11c164596ef873898dd843700c7164cc0932",
"size": 184,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/c75b11c164596ef873898dd843700c7164cc0932"
},
{
"path": "testframework/server.py",
"mode": "100644",
"type": "blob",
"sha": "a9c20ea3eab31bab288d6089a89410ff409d43ad",
"size": 2836,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/a9c20ea3eab31bab288d6089a89410ff409d43ad"
},
{
"path": "testframework/web",
"mode": "040000",
"type": "tree",
"sha": "5beb5445842a7c69a29942eadbd100ec0458556f",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/5beb5445842a7c69a29942eadbd100ec0458556f"
},
{
"path": "testframework/web/js",
"mode": "040000",
"type": "tree",
"sha": "a351c437f1cccb93448fb0140d8e0fc17ffab368",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/a351c437f1cccb93448fb0140d8e0fc17ffab368"
},
{
"path": "testframework/web/js/testRunner.js",
"mode": "100644",
"type": "blob",
"sha": "521a2204b9a2a3202441818461231872ea8a15c8",
"size": 3132,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/521a2204b9a2a3202441818461231872ea8a15c8"
},
{
"path": "tests",
"mode": "040000",
"type": "tree",
"sha": "6341d1c56315d281322b2d4dd4a9abd4ef3cb345",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/6341d1c56315d281322b2d4dd4a9abd4ef3cb345"
},
{
"path": "tests/README.md",
"mode": "100644",
"type": "blob",
"sha": "ec025a7d169c7783f34523c63a0a6ae9a2e00fdb",
"size": 140,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/ec025a7d169c7783f34523c63a0a6ae9a2e00fdb"
},
{
"path": "tests/audio.json",
"mode": "100644",
"type": "blob",
"sha": "cae3d766731f7fe3ae4866f6fa8c0cc86a2ca46d",
"size": 6092,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/cae3d766731f7fe3ae4866f6fa8c0cc86a2ca46d"
},
{
"path": "tests/batch4x4.json",
"mode": "100644",
"type": "blob",
"sha": "34b9647329642a9e5ca233a60b8bbf2ca8f72aca",
"size": 10236,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/34b9647329642a9e5ca233a60b8bbf2ca8f72aca"
},
{
"path": "tests/converted-format-input.json",
"mode": "100644",
"type": "blob",
"sha": "e9722580df540b89a4b9185260a8de180ddd63aa",
"size": 4514,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/e9722580df540b89a4b9185260a8de180ddd63aa"
},
{
"path": "tests/converted-input.json",
"mode": "100644",
"type": "blob",
"sha": "41a93a049ea95ea9ddda92ed3a5152b55581938f",
"size": 5917,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/41a93a049ea95ea9ddda92ed3a5152b55581938f"
},
{
"path": "tests/loop.json",
"mode": "100644",
"type": "blob",
"sha": "aa5dd4ecdaac29d04b71dbf3bbc8349f2d1210af",
"size": 3643,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/aa5dd4ecdaac29d04b71dbf3bbc8349f2d1210af"
},
{
"path": "tests/old-prores.json",
"mode": "100644",
"type": "blob",
"sha": "17e77c1547663d39b5356ac15d74f807c69dc671",
"size": 8694,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/17e77c1547663d39b5356ac15d74f807c69dc671"
},
{
"path": "tests/old-vae-conversion.json",
"mode": "100644",
"type": "blob",
"sha": "e751918b6473cae2f38536d8433bc40b2283a3f6",
"size": 4430,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/e751918b6473cae2f38536d8433bc40b2283a3f6"
},
{
"path": "tests/simple.json",
"mode": "100644",
"type": "blob",
"sha": "4d7f8ddd68a24cc90519ecd127daae9d8ab81b85",
"size": 2820,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4d7f8ddd68a24cc90519ecd127daae9d8ab81b85"
},
{
"path": "video_formats",
"mode": "040000",
"type": "tree",
"sha": "71ef56a606010f67ad85ab3e27e04ea0a3af5a7e",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/71ef56a606010f67ad85ab3e27e04ea0a3af5a7e"
},
{
"path": "video_formats/16bit-png.json",
"mode": "100644",
"type": "blob",
"sha": "b768bdbcfe8950cb7bde37d02444f0191ad29f51",
"size": 139,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b768bdbcfe8950cb7bde37d02444f0191ad29f51"
},
{
"path": "video_formats/8bit-png.json",
"mode": "100644",
"type": "blob",
"sha": "88b27a75f9c979f18979ec46da8c8843a82e0759",
"size": 75,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/88b27a75f9c979f18979ec46da8c8843a82e0759"
},
{
"path": "video_formats/ProRes.json",
"mode": "100644",
"type": "blob",
"sha": "eddd3acf931c5ab3486197c18ba88a3959d3e1d6",
"size": 943,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/eddd3acf931c5ab3486197c18ba88a3959d3e1d6"
},
{
"path": "video_formats/av1-webm.json",
"mode": "100644",
"type": "blob",
"sha": "659ea166fb140e18109f09f3d5710363af9c2294",
"size": 625,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/659ea166fb140e18109f09f3d5710363af9c2294"
},
{
"path": "video_formats/ffmpeg-gif.json",
"mode": "100644",
"type": "blob",
"sha": "3ca0865033c7dabc06176c737652f375e7badb27",
"size": 366,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/3ca0865033c7dabc06176c737652f375e7badb27"
},
{
"path": "video_formats/ffv1-mkv.json",
"mode": "100644",
"type": "blob",
"sha": "3248e5fc6425feeb1d55ccdb8bd8d49cb0e3401c",
"size": 1111,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/3248e5fc6425feeb1d55ccdb8bd8d49cb0e3401c"
},
{
"path": "video_formats/gifski.json",
"mode": "100644",
"type": "blob",
"sha": "c96b358ab0ae59dbd97c52a699c8ee9825c5d351",
"size": 287,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/c96b358ab0ae59dbd97c52a699c8ee9825c5d351"
},
{
"path": "video_formats/h264-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "4aa0bd57c6a4cc65334d82e5cdaa7aadb8372321",
"size": 619,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4aa0bd57c6a4cc65334d82e5cdaa7aadb8372321"
},
{
"path": "video_formats/h265-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "559c35073edf9ed74baec0eeffc56fde2b0438c5",
"size": 645,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/559c35073edf9ed74baec0eeffc56fde2b0438c5"
},
{
"path": "video_formats/nvenc_av1-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "ed8294fcf0c9cc1a4780dc6e2454913a969f533b",
"size": 606,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/ed8294fcf0c9cc1a4780dc6e2454913a969f533b"
},
{
"path": "video_formats/nvenc_h264-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "f8676304effd31fb41ae13dd972d92736b122009",
"size": 607,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f8676304effd31fb41ae13dd972d92736b122009"
},
{
"path": "video_formats/nvenc_hevc-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "a374ecde4d0e0c2a2f0042c282f8b1915e307aca",
"size": 632,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/a374ecde4d0e0c2a2f0042c282f8b1915e307aca"
},
{
"path": "video_formats/webm.json",
"mode": "100644",
"type": "blob",
"sha": "6323f619ad2850ba60cd5e31b32cdfc060e030c9",
"size": 589,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/6323f619ad2850ba60cd5e31b32cdfc060e030c9"
},
{
"path": "videohelpersuite",
"mode": "040000",
"type": "tree",
"sha": "7fa5fea7a3a28e78b03a369d1656de9230174e8c",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/7fa5fea7a3a28e78b03a369d1656de9230174e8c"
},
{
"path": "videohelpersuite/batched_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "624bb84f73cce1d8e51abf4fef0b80367ad4b9a3",
"size": 1790,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/624bb84f73cce1d8e51abf4fef0b80367ad4b9a3"
},
{
"path": "videohelpersuite/documentation.py",
"mode": "100644",
"type": "blob",
"sha": "857de6c6a5b4a3917f49d0b1c5c142f274203f22",
"size": 43805,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/857de6c6a5b4a3917f49d0b1c5c142f274203f22"
},
{
"path": "videohelpersuite/image_latent_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "62b4e3e6452b51b42e3e49852d27a1bb9921edc2",
"size": 19039,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/62b4e3e6452b51b42e3e49852d27a1bb9921edc2"
},
{
"path": "videohelpersuite/latent_preview.py",
"mode": "100644",
"type": "blob",
"sha": "a0a22b8ad028fb9de25cb9818b857a6e4aa0f3e1",
"size": 5500,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/a0a22b8ad028fb9de25cb9818b857a6e4aa0f3e1"
},
{
"path": "videohelpersuite/load_images_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "43f3387c4f907d7372c207f7f1aeb626c27b836b",
"size": 8120,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/43f3387c4f907d7372c207f7f1aeb626c27b836b"
},
{
"path": "videohelpersuite/load_video_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "b23e40f535c8166ae05fa6a541d159cdadb368f7",
"size": 29032,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b23e40f535c8166ae05fa6a541d159cdadb368f7"
},
{
"path": "videohelpersuite/logger.py",
"mode": "100755",
"type": "blob",
"sha": "6e7b8d64bda275608ba6bf8ee28d2a2112e3e2be",
"size": 1057,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/6e7b8d64bda275608ba6bf8ee28d2a2112e3e2be"
},
{
"path": "videohelpersuite/nodes.py",
"mode": "100755",
"type": "blob",
"sha": "4389f5de534d0fdc66fdc922257166125e26e444",
"size": 48222,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4389f5de534d0fdc66fdc922257166125e26e444"
},
{
"path": "videohelpersuite/server.py",
"mode": "100755",
"type": "blob",
"sha": "f67e342400eb250b731245554bbd495864719f8f",
"size": 12178,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f67e342400eb250b731245554bbd495864719f8f"
},
{
"path": "videohelpersuite/utils.py",
"mode": "100644",
"type": "blob",
"sha": "5b35ad47fa3d1412773ab561598031ba6a3b38bc",
"size": 17044,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/5b35ad47fa3d1412773ab561598031ba6a3b38bc"
},
{
"path": "web",
"mode": "040000",
"type": "tree",
"sha": "780545bc455811920531b200a1940657ae25aebd",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/780545bc455811920531b200a1940657ae25aebd"
},
{
"path": "web/js",
"mode": "040000",
"type": "tree",
"sha": "0dea6ab5e00f897006aecd295ce034630d13f79c",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/0dea6ab5e00f897006aecd295ce034630d13f79c"
},
{
"path": "web/js/VHS.core.js",
"mode": "100755",
"type": "blob",
"sha": "fcbf03ffc7eb517e8a0a7b5ce045aa9bee5d8e43",
"size": 106686,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/fcbf03ffc7eb517e8a0a7b5ce045aa9bee5d8e43"
},
{
"path": "web/js/videoinfo.js",
"mode": "100644",
"type": "blob",
"sha": "b1a9871067e07dc09b37a8dd666ce531c2c5f56b",
"size": 4313,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b1a9871067e07dc09b37a8dd666ce531c2c5f56b"
}
],
"truncated": false
}
+674
View File
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -0,0 +1,9 @@
from .videohelpersuite.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
import folder_paths
from .videohelpersuite.server import server
from .videohelpersuite import documentation
from .videohelpersuite import latent_preview
WEB_DIRECTORY = "./web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
documentation.format_descriptions(NODE_CLASS_MAPPINGS)
@@ -0,0 +1,15 @@
[project]
name = "comfyui-videohelpersuite"
description = "Nodes related to video workflows"
version = "1.7.9"
license = { file = "LICENSE" }
dependencies = ["opencv-python", "imageio-ffmpeg"]
[project.urls]
Repository = "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"
# Used by Comfy Registry https://comfyregistry.org
[tool.comfy]
PublisherId = "kosinkadink"
DisplayName = "ComfyUI-VideoHelperSuite"
Icon = ""
@@ -0,0 +1,9 @@
{
"main_pass":
[
"-n",
"-pix_fmt", "rgba64"
],
"input_color_depth": "16bit",
"extension": "%03d.png"
}
@@ -0,0 +1,7 @@
{
"main_pass":
[
"-n"
],
"extension": "%03d.png"
}
@@ -0,0 +1,22 @@
{
"main_pass":
[
"-n", "-c:v", "prores_ks",
"-profile:v", [["$profile"]],
["profile", {
"lt": [[]], "1": [[]], "standard": [[]], "2": [[]], "hq": [[]], "3": [[]],
"4": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}],
"4444": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}],
"4444xq": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}]
}],
"-vf", "scale=out_color_matrix=bt709",
"-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "pcm_s16le"],
"extension": "mov",
"extra_widgets": [["profile", ["lt", "standard", "hq", "4444", "4444xq"], {"default": "hq"}]]
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n", "-c:v", "libsvtav1",
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
"-crf", ["crf","INT", {"default": 23, "min": 0, "max": 100, "step": 1}],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "libopus"],
"input_color_depth": ["input_color_depth", ["8bit", "16bit"]],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "webm",
"environment": {"SVT_LOG": "1"}
}
@@ -0,0 +1,8 @@
{
"main_pass":
[
"-n",
"-filter_complex", ["dither", ["bayer", "heckbert", "floyd_steinberg", "sierra2", "sierra2_4a", "sierra3", "burkes", "atkinson", "none"], {"default": "sierra2_4a"}, "[0:v] split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse=dither=$val"]
],
"extension": "gif"
}
@@ -0,0 +1,18 @@
{
"main_pass": [
"-n",
"-c:v", "ffv1",
"-level", ["level", ["0", "1", "3"], {"default": "3"}],
"-coder", ["coder", ["0", "1", "2"], {"default": "1"}],
"-context", ["context", ["0", "1"], {"default": "1"}],
"-g", ["gop_size", "INT", {"default": 1, "min": 1, "max": 300, "step": 1}],
"-slices", ["slices", ["4", "6", "9", "12", "16", "20", "24", "30"], {"default": "16"}],
"-slicecrc", ["slicecrc", ["0", "1"], {"default": "1"}],
"-pix_fmt", ["pix_fmt", ["rgba64le", "bgra", "yuv420p", "yuv422p", "yuv444p", "yuva420p", "yuva422p", "yuva444p", "yuv420p10le", "yuv422p10le", "yuv444p10le", "yuv420p12le", "yuv422p12le", "yuv444p12le", "yuv420p14le", "yuv422p14le", "yuv444p14le", "yuv420p16le", "yuv422p16le", "yuv444p16le", "gray", "gray10le", "gray12le", "gray16le"], {"default": "rgba64le"}]
],
"audio_pass": ["-c:a", "flac"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"input_color_depth": "16bit",
"extension": "mkv"
}
@@ -0,0 +1,12 @@
{
"main_pass":
[
"-pix_fmt", "yuv444p",
"-vf", "scale=out_color_matrix=bt709:out_range=pc",
"-color_range", "pc"
],
"extension": "gif",
"gifski_pass": [
"-Q", ["quality","INT", {"default": 90, "min": 1, "max": 100, "step": 1}]
]
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "libx264",
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
"-crf", ["crf","INT", {"default": 19, "min": 0, "max": 100, "step": 1}],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac", "-movflags", "use_metadata_tags"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"extension": "mp4"
}
@@ -0,0 +1,17 @@
{
"main_pass":
[
"-n", "-c:v", "libx265",
"-vtag", "hvc1",
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
"-crf", ["crf","INT", {"default": 22, "min": 0, "max": 100, "step": 1}],
"-preset", "medium",
"-x265-params", "log-level=quiet",
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac", "-movflags", "use_metadata_tags"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "av1_nvenc",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac", "-movflags", "use_metadata_tags"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "h264_nvenc",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac", "-movflags", "use_metadata_tags"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n", "-c:v", "hevc_nvenc",
"-vtag", "hvc1",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac", "-movflags", "use_metadata_tags"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n",
"-pix_fmt", ["pix_fmt",["yuv420p","yuva420p"]],
"-crf", ["crf","INT", {"default": 20, "min": 0, "max": 100, "step": 1}],
"-b:v", "0",
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "libvorbis"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"extension": "webm"
}
@@ -0,0 +1,56 @@
import torch
from nodes import VAEEncode
from comfy.utils import ProgressBar
class VAEDecodeBatched:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"samples": ("LATENT", ),
"vae": ("VAE", ),
"per_batch": ("INT", {"default": 16, "min": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
RETURN_TYPES = ("IMAGE",)
FUNCTION = "decode"
def decode(self, vae, samples, per_batch):
decoded = []
pbar = ProgressBar(samples["samples"].shape[0])
for start_idx in range(0, samples["samples"].shape[0], per_batch):
decoded.append(vae.decode(samples["samples"][start_idx:start_idx+per_batch]))
pbar.update(per_batch)
return (torch.cat(decoded, dim=0), )
class VAEEncodeBatched:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"pixels": ("IMAGE", ), "vae": ("VAE", ),
"per_batch": ("INT", {"default": 16, "min": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
RETURN_TYPES = ("LATENT",)
FUNCTION = "encode"
def encode(self, vae, pixels, per_batch):
t = []
pbar = ProgressBar(pixels.shape[0])
for start_idx in range(0, pixels.shape[0], per_batch):
try:
sub_pixels = vae.vae_encode_crop_pixels(pixels[start_idx:start_idx+per_batch])
except:
sub_pixels = VAEEncode.vae_encode_crop_pixels(pixels[start_idx:start_idx+per_batch])
t.append(vae.encode(sub_pixels[:,:,:,:3]))
pbar.update(per_batch)
return ({"samples": torch.cat(t, dim=0)}, )
@@ -0,0 +1,616 @@
from .logger import logger
def image(src):
return f'<img src={src} loading=lazy style="width: 0px; min-width: 100%">'
def video(src):
return f'<video preload="none" src={src} muted loop controls controlslist="nodownload noremoteplayback noplaybackrate" style="width: 0px; min-width: 100%" class="VHS_loopedvideo">'
def short_desc(desc):
return f'<div id=VHS_shortdesc>{desc}</div>'
def format_each(desc, **kwargs):
if isinstance(desc, dict):
res = {}
for k,v in desc.items():
res[format_each(k, **kwargs)] = format_each(v, **kwargs)
return res
if isinstance(desc, list):
res = []
for v in desc:
res.append(format_each(v, **kwargs))
return res
return desc.format(**kwargs)
def format_type(desc, lower, lowers=None, upper=None, uppers=None, cap=None):
"""Utility function for nodes with image/latent/mask variants"""
if lowers is None:
lowers = lower + 's'
if cap is None:
cap = lower.capitalize()
if upper is None:
upper = lower.upper()
if uppers is None:
uppers = lowers.upper()
return format_each(desc, lower=lower, lowers=lowers, upper=upper, uppers=uppers, cap=cap)
common_descriptions = {
'merge_strategy': [
'Determines what the output resolution will be if input resolutions don\'t match',
{'match A': 'Always use the resolution for A',
'match B': 'Always use the resolution for B',
'match smaller': 'Pick the smaller resolution by area',
'match larger': 'Pick the larger resolution by area',
}],
'scale_method': [
'Determines what method to use if scaling is required',
],
'crop_method': 'When sizes don\'t match, should the resized image have it\'s aspect ratio changed, or be cropped to maintain aspect ratio',
'VHS_PATH': [
'This is a VHS_PATH input. When edited, it provides a list of possible valid files or directories',
video('https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/assets/4284322/729b7185-1fca-41d8-bc8d-a770bb2a5ce6'),
'The current top-most completion may be selected with Tab',
'You can navigate up a directory by pressing Ctrl+B (or Ctrl+W if supported by browser)',
'The filter on suggested file types can be disabled by pressing Ctrl+G.',
'If converted to an input, this functions as a string',
],
"GetCount": ['Get {cap} Count 🎥🅥🅗🅢', short_desc('Return the number of {lowers} in an input as an INT'),
{'Inputs': {
'{lowers}': 'The input {lower}',
},
'Outputs': {
'count': 'The number of {lowers} in the input',
},
}],
"SelectEveryNth": ['Select Every Nth {cap} 🎥🅥🅗🅢', short_desc('Keep only 1 {lower} for every interval'),
{'Inputs': {
'{lowers}': 'The input {lower}',
},
'Outputs': {
'{upper}': 'The output {lowers}',
'count': 'The number of {lowers} in the input',
},
'Widgets':{
'select_every_nth': 'The interval from which one frame is kept. 1 means no frames are skipped.',
'skip_first_{lowers}': 'A number of frames which that is skipped from the start. This applies before select_every_nth. As a result, multiple copies of the node can each have a different skip_first_frames to divide the {lower} into groups'
},
}],
}
descriptions = {
'VHS_VideoCombine': ['Video Combine 🎥🅥🅗🅢', short_desc('Combine an image sequence into a video'), {
'Inputs': {
'images': 'The images to be turned into a video',
'audio':'(optional) audio to add to the video',
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long image sequences into sub batches. See the documentation for Meta Batch Manager',
'vae':['(optional) If provided, the node will take latents as input instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
"Unlike on Load Video, this isn't always a strict upgrade over using a standalone VAE Decode.",
"If you have multiple Video Combine outputs, then the VAE decode will be performed for each output node increasing execution time",
"If you make any change to output settings on the Video Combine (such as changing the output format), the VAE decode will be performed again as the decoded result is (by design) not cached",
]
},
'Widgets':{
'frame_rate': 'The frame rate which will be used for the output video. Consider converting this to an input and connecting this to a Load Video with Video Info(Loaded)->fps. When including audio, failure to properly set this will result in audio desync',
'loop_count': 'The number of additional times the video should repeat. Can cause performance issues when used with long (100+ frames) sequences',
'filename_prefix': 'A prefix to add to the name of the output filename. This can include subfolders or format strings.',
'format': 'The output format to use. Formats starting with, \'image\' are saved with PIL, but formats starting with \'video\' utilize the video_formats system. \'video\' options require ffmpeg and selecting one frequently adds additional options to the node.',
'pingpong': 'Play the video normally, then repeat the video in reverse so that it \'pingpongs\' back and forth. This is frequently used to minimize the appearance of skips on very short animations.',
'save_output': 'Specifies if output files should be saved to the output folder, or the temporary output folder',
'videopreview': 'Displays a preview for the processed result. If advanced previews is enabled, the output is always converted to a format viewable from the browser. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
},
'Common Format Widgets': {
'crf': 'Determines how much to prioritize quality over filesize. Numbers vary between formats, but on each format that includes it, the default value provides visually loss less output',
'pix_fmt': ['The pixel format to use for output. Alternative options will often have higher quality at the cost of increased file size and reduced compatibility with external software.', {
'yuv420p': 'The most common and default format',
'yuv420p10le': 'Use 10 bit color depth. This can improve color quality when combined with 16bit input color depth',
'yuva420p': 'Include transparency in the output video'
}],
'input_color_depth': 'VHS supports outputting 16bit images. While this produces higher quality output, the difference usually isn\'t visible without postprocessing and it significantly increases file size and processing time.',
'save_metadata': 'Determines if metadata for the workflow should be included in the output video file',
}
}],
'VHS_LoadVideo': ['Load Video 🎥🅥🅗🅢', short_desc('Loads a video from the input folder'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'frame_count': 'The length of images just returned',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': 'The video file to be loaded. Lists all files with a video extension in the ComfyUI/Input folder',
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'choose video to upload': 'An upload button is provided to upload local files to the input folder',
'videopreview': 'Displays a preview for the selected video input. If advanced previews is enabled, this preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoFFmpeg': ['Load Video FFmpeg 🎥🅥🅗🅢', short_desc('Loads a video from the input folder using ffmpeg instead of opencv'),
'Provides faster execution speed, transparency support, and allows specifying start time in seconds',
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'mask': 'Transparency data from the loaded video',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': 'The video file to be loaded. Lists all files with a video extension in the ComfyUI/Input folder',
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'start_time': 'A timestamp, in seconds from the start of the video, to start loading frames from. ',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'choose video to upload': 'An upload button is provided to upload local files to the input folder',
'videopreview': 'Displays a preview for the selected video input. If advanced previews is enabled, this preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoPath': ['Load Video (Path) 🎥🅥🅗🅢', short_desc('Loads a video from an arbitrary path'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'frame_count': 'The length of images just returned',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': ['The video file to be loaded.', 'You can also select an image to load it as a single frame'] + common_descriptions['VHS_PATH'],
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoFFmpegPath': ['Load Video FFmpeg (Path) 🎥🅥🅗🅢', short_desc('Loads a video from an arbitrary path using ffmpeg instead of opencv'),
'Provides faster execution speed, transparency support, and allows specifying start time in seconds',
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'mask': 'Transparency data from the loaded video',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': ['The video file to be loaded.', 'You can also select an image to load it as a single frame'] + common_descriptions['VHS_PATH'],
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImages': ['Load Images 🎥🅥🅗🅢', short_desc('Loads a sequence of images from a subdirectory of the input folder'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
'frame_count': 'The length of images just returned',
},
'Widgets': {
'directory': 'The directory images will be loaded from. Filtered to process jpg, png, ppm, bmp, tif, and webp files',
'image_load_cap': 'The maximum number of images to load. If 0, all images are loaded.',
'start_time': 'A timestamp, in seconds from the start of the video, to start loading frames from. ',
'choose folder to upload': 'An upload button is provided to upload a local folder containing images to the input folder',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImagesPath': ['Load Images (Path) 🎥🅥🅗🅢', short_desc('Loads a sequence of images from an arbitrary path'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
'frame_count': 'The length of images just returned',
},
'Widgets': {
'directory': ['The directory images will be loaded from. Filtered to process jpg, png, ppm, bmp, tif, and webp files'] + common_descriptions['VHS_PATH'],
'image_load_cap': 'The maximum number of images to load. If 0, all images are loaded.',
'skip_first_images': 'A number of images which are discarded before producing output.',
'select_every_nth': 'Keeps only the first of every n frames and discard the rest.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImagePath': ['Load Image (Path) 🎥🅥🅗🅢', short_desc('Load a single image from a given path'),
{'Inputs': {
'vae': '(optional) If provided the node will output latents instead of images.',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
},
'Widgets': {
'image': ['The image file to be loaded.'] + common_descriptions['VHS_PATH'],
'force_size': ['Allows for conveniently scaling the input without requiring an additional node. Provides options to maintain aspect ratio or conveniently target common training formats for Animate Diff', {'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set'}],
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
"VHS_LoadAudio": ['Load Audio (Path) 🎥🅥🅗🅢', short_desc('Loads an audio file from an arbitrary path'),
{'Outputs': {
'audio': 'The loaded audio',
},
'Widgets': {
'audio_file': ['The audio file to be loaded.'] + common_descriptions['VHS_PATH'],
'seek_seconds': 'An offset from the start of the sound file that the audio should start from',
}
}],
"VHS_LoadAudioUpload": ['Load Audio (Upload) 🎥🅥🅗🅢', short_desc('Loads an audio file from the input directory'),
"Very similar in functionality to the built-in LoadAudio. It was originally added before VHS swapped to use Comfy's internal AUDIO format, but provides the additional options for start time and duration",
{'Outputs': {
'audio': 'The loaded audio',
},
'Widgets': {
'audio': 'The audio file to be loaded.',
'start_time': 'An offset from the start of the sound file that the audio should start from',
'duration': 'A maximum limit for the audio. Disabled if 0',
'choose audio to upload': 'An upload button is provided to upload an audio file to the input folder',
}
}],
"VHS_AudioToVHSAudio": ['Audio to legacy VHS_AUDIO 🎥🅥🅗🅢', short_desc('utility function for compatibility with external nodes'),
"VHS used to use an internal VHS_AUDIO format for routing audio between inputs and outputs. This format was intended to only be used internally and was designed with a focus on performance over ease of use. Since ComfyUI now has an internal AUDIO format, VHS now uses this format. However, some custom node packs were made that are external to both ComfyUI and VHS that use VHS_AUDIO. This node was added so that those external nodes can still function",
{'Inputs': {
'audio': 'An input in the standardized AUDIO format',
},
'Outputs': {
'vhs_audio': 'An output in the legacy VHS_AUDIO format for use with external nodes',
},
}],
"VHS_VHSAudioToAudio": ['Legacy VHS_AUDIO to Audio 🎥🅥🅗🅢', short_desc('utility function for compatibility with external nodes'),
"VHS used to use an internal VHS_AUDIO format for routing audio between inputs and outputs. This format was intended to only be used internally and was designed with a focus on performance over ease of use. Since ComfyUI now has an internal AUDIO format, VHS now uses this format. However, some custom node packs were made that are external to both ComfyUI and VHS that use VHS_AUDIO. This node was added so that those external nodes can still function",
{'Inputs': {
'vhs_audio': 'An input in the legacy VHS_AUDIO format produced by an external node',
},
'Outputs': {
'vhs_audio': 'An output in the standardized AUDIO format',
},
}],
"VHS_PruneOutputs": ['Prune Outputs 🎥🅥🅗🅢', short_desc('Automates deletion of undesired outputs from a Video Combine node.'),
'Video Combine produces a number of file outputs in addition to the final output. Some of these, such as a video file without audio included, are implementation limitations and are not feasible to solve. As an alternative, the Prune Outputs node is added to automate the deletion of these file outputs if they are not desired',
{'Inputs': {
'filenames': 'A connection from a Video Combine node to indicate which outputs should be pruned',
},
'Widgets': {
'options': ['Which files should be deleted',
{'Intermediate': 'Delete any files that were required for intermediate processing but are not the final output, like the no-audio output file when audio is included',
'Intermediate and Utility': 'Delete all produced files that aren\'t the final output, including the first frame png',
}]}
}],
"VHS_BatchManager": ['Meta Batch Manager 🎥🅥🅗🅢', short_desc('Split the processing of a very long video into sets of smaller Meta Batches'),
"The Meta Batch Manager allows for extremely long input videos to be processed when all other methods for fitting the content in RAM fail. It does not effect VRAM usage.",
"It must be connected to at least one Input (a Load Video or Load Images) AND at least one Video Combine",
image("https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/assets/4284322/7cb3fb7e-59d8-4cb2-a09f-9c6698de8b1f"),
"It functions by holding both the inputs and ouputs open between executions, and automatically requeue's the workflow until one of the inputs is unable to provide additional images.",
"Because each sub execution only contains a subset of the total frames, each sub execution creates a hard window which temporal smoothing can not be applied across. This results in jumps in the output.",
{'Outputs': {
'meta_batch': 'Add all connected nodes to this Meta Batch',
},
'Widgets': {
'frames_per_batch': 'How many frames to process for each sub execution. If loading as image, each frame will use about 50MB of RAM (not VRAM), and this can safely be set in the 100-1000 range, depending on available memory. When loading and combining from latent space (no blue image noodles exist), this value can be much higher, around the 2,000 to 20,000 range',
}
}],
"VHS_VideoInfo": ['Video Info 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'source_fps🟨': 'The frame rate of the video',
'source_frame_count🟨': 'How many total frames the video contains before accounting for frame rate or select_every_nth',
'source_duration🟨': 'The length of images just returned in seconds',
'source_width🟨': 'The width',
'source_height🟨': 'The height',
'loaded_fps🟦': 'The frame rate after accounting for force_rate and select_every_nth. This output is of particular use as it can be connected to the converted frame_rate input of a Video Combine node to ensure audio remains synchronized.',
'loaded_frame_count🟦': 'The number of frames returned by the current execution. Identical to the frame_count returned by the node itself',
'loaded_duration🟦': 'The duration in seconds of returned images after accounting for frame_load_cap',
'loaded_width🟦': 'The width of the video after scaling. These coordinates are in image space even if loading to latent space',
'loaded_height🟦': 'The height of the video after scaling. These coordinates are in image space even if loading to latent space',
},
}],
"VHS_VideoInfoSource": ['Video Info Source 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs describing the file itself without accounting for load options'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'source_fps🟨': 'The frame rate of the video',
'source_frame_count🟨': 'How many total frames the video contains before accounting for frame rate or select_every_nth',
'source_duration🟨': 'The length of images just returned in seconds',
'source_width🟨': 'The original width',
'source_height🟨': 'The original height',
}
}],
"VHS_VideoInfoLoaded": ['Video Info Loaded 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs describing the file itself after accounting for load options'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'loaded_fps🟦': 'The frame rate after accounting for force_rate and select_every_nth. This output is of particular use as it can be connected to the converted frame_rate input of a Video Combine node to ensure audio remains synchronized.',
'loaded_frame_count🟦': 'The number of frames returned by the current execution. Identical to the frame_count returned by the node itself',
'loaded_duration🟦': 'The duration in seconds of returned images after accounting for frame_load_cap',
'loaded_width🟦': 'The width of the video after scaling. This is the dimension of the corresponding image even if loading as a latent directly',
'loaded_height🟦': 'The height of the video after scaling. This is the dimension of the corresponding image even if loading as a latent directly',
}
}],
"VHS_SelectFilename": ['VAE Select Filename 🎥🅥🅗🅢', short_desc('Select a single filename from the VHS_FILENAMES output by a Video Combine and return it as a string'),
'Take care when combining this node with Prune Outputs. The VHS_FILENAMES object is immutable and will always contain the full list of output files, but execution order is undefined behavior (currently, Prune Outputs will generally execute first) and SelectFilename may return a path to a file that no longer exists.',
{'Inputs': {
'filenames': 'A VHS_FILENAMES from a Video Combine node',
},
'Outputs': {
'filename': 'A string representation of the full output path for the chosen file',
},
'Widgets': {
'index': 'The index of which file should be selected. The default, -1, chooses the most complete output',
},
}],
# Batched Nodes
"VHS_VAEEncodeBatched": ['VAE Encode Batched 🎥🅥🅗🅢', short_desc('Encode images as latents with a manually specified batch size.'),
"Some people have ran into VRAM issues when encoding or decoding large batches of images. As a workaround, this node lets you manually set a batch size when encoding images.",
"Unless these issues have been encountered, it is simpler to use the native VAE Encode or to encode directly from a Load Video",
{'Inputs': {
'pixels': 'The images to be encoded.',
'vae': 'The VAE to use when encoding.',
},
'Outputs': {
'LATENT': 'The encoded latents.',
},
'Widgets': {
'per_batch': 'The maximum number of images to encode in each batch.',
},
}],
"VHS_VAEDecodeBatched": ['VAE Decode Batched 🎥🅥🅗🅢', short_desc('Decode latents to images with a manually specified batch size'),
"Some people have ran into VRAM issues when encoding or decoding large batches of images. As a workaround, this node lets you manually set a batch size when decoding latents.",
"Unless these issues have been encountered, it is simpler to use the native VAE Decode or to decode from a Video Combine directly",
{'Inputs': {
'samples': 'The latents to be decoded.',
'vae': 'The VAE to use when decoding.',
},
'Outputs': {
'IMAGE': 'The decoded images.',
},
'Widgets': {
'per_batch': 'The maximum number of images to decode in each batch.',
},
}],
# Latent and Image nodes
"VHS_SplitLatents": ['Split Latents 🎥🅥🅗🅢', short_desc('Split a set of latents into two groups'),
{'Inputs': {
'latents': 'The latents to be split.',
},
'Outputs': {
'LATENT_A': 'The first group of latents',
'A_count': 'The number of latents in group A. This will be equal to split_index unless the latents input has length less than split_index',
'LATENT_B': 'The second group of latents',
'B_count': 'The number of latents in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_SplitImages": ['Split Images 🎥🅥🅗🅢', short_desc('Split a set of images into two groups'),
{'Inputs': {
'images': 'The images to be split.',
},
'Outputs': {
'IMAGE_A': 'The first group of images',
'A_count': 'The number of images in group A. This will be equal to split_index unless the images input has length less than split_index',
'IMAGE_B': 'The second group of images',
'B_count': 'The number of images in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_SplitMasks": ['Split Masks 🎥🅥🅗🅢', short_desc('Split a set of masks into two groups'),
{'Inputs': {
'mask': 'The masks to be split.',
},
'Outputs': {
'MASK_A': 'The first group of masks',
'A_count': 'The number of masks in group A. This will be equal to split_index unless the mask input has length less than split_index',
'MASK_B': 'The second group of masks',
'B_count': 'The number of masks in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_MergeLatents": ['Merge Latents 🎥🅥🅗🅢', short_desc('Combine two groups of latents into a single group of latents'),
{'Inputs': {
'latents_A': 'The first group of latents',
'latents_B': 'The first group of latents',
},
'Outputs': {
'LATENT': 'The combined group of latents',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_MergeImages": ['Merge Images 🎥🅥🅗🅢', short_desc('Combine two groups of images into a single group of images'),
{'Inputs': {
'images_A': 'The first group of images',
'images_B': 'The first group of images',
},
'Outputs': {
'IMAGE': 'The combined group of images',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_MergeMasks": ['Merge Masks 🎥🅥🅗🅢', short_desc('Combine two groups of masks into a single group of masks'),
{'Inputs': {
'mask_A': 'The first group of masks',
'mask_B': 'The first group of masks',
},
'Outputs': {
'MASK': 'The combined group of masks',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_GetLatentCount": format_type(common_descriptions['GetCount'], 'latent'),
"VHS_GetImageCount": format_type(common_descriptions['GetCount'], 'image'),
"VHS_GetMaskCount": format_type(common_descriptions['GetCount'], 'mask'),
"VHS_DuplicateLatents": ['Repeat Latents 🎥🅥🅗🅢', short_desc('Append copies of a latent to itself so it repeats'),
{'Inputs': {
'latents': 'The latents to be repeated',
},
'Outputs': {
'LATENT': 'The latent with repeats',
'count': 'The number of latents in the output. Equal to the length of the input latent * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the latent should repeat. 1, the default, means no change.',
},
}],
"VHS_DuplicateImages": ['Repeat Images 🎥🅥🅗🅢', short_desc('Append copies of a image to itself so it repeats'),
{'Inputs': {
'IMAGES': 'The image to be repeated',
},
'Outputs': {
'IMAGE': 'The image with repeats',
'count': 'The number of image in the output. Equal to the length of the input image * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the mask should repeat. 1, the default, means no change.',
},
}],
"VHS_DuplicateMasks": ['Repeat Masks 🎥🅥🅗🅢', short_desc('Append copies of a mask to itself so it repeats'),
{'Inputs': {
'masks': 'The masks to be repeated',
},
'Outputs': {
'LATENT': 'The mask with repeats',
'count': 'The number of mask in the output. Equal to the length of the input mask * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the mask should repeat. 1, the default, means no change.',
},
}],
"VHS_SelectEveryNthLatent": format_type(common_descriptions['SelectEveryNth'], 'latent'),
"VHS_SelectEveryNthImage": format_type(common_descriptions['SelectEveryNth'], 'image'),
#TODO: fix discrepency of input being mask instead of masks?
"VHS_SelectEveryNthMask": format_type(common_descriptions['SelectEveryNth'], 'mask', lowers='mask'),
#TODO: port documentation for select nodes to new system
#"VHS_SelectLatents": None,
#"VHS_SelectImages": None,
#"VHS_SelectMasks": None,
"VHS_Unbatch": ['Unbatch 🎥🅥🅗🅢', short_desc('Unbatch a list of items into a single concatenated item'),
"Useful for when you want a single video output from a complex workflow",
"Has no relation to the Meta Batch system of VHS",
{'Inputs': {
'batched': 'Any input which may or may not be batched',
},
'Outputs': {
'unbatched': 'A single output element. Torch tensors are concatenated across dim 0, all other types are added which functions as concatenation for strings and arrays, but may give undesired results for other types',
},
}],
"VHS_SelectLatest": ['Select Latest 🎥🅥🅗🅢', short_desc('Experimental virtual node to select the most recently modified file from a given folder'),
"Assists in the creation of workflows where outputs from one execution are used elsewhere in subsequent executions.",
{'Inputs': {
'filename_prefix': 'A path which can consist of a combination of folders and a prefix which candidate files must match',
'filename_postfix': 'A string which chich the selected file must end with. Useful for limiting to a target extension.',
},
'Outputs': {
'Filename': 'A string representing a file path to the most recently modified file.',
},
}],
}
def as_html(entry, depth=0):
if isinstance(entry, dict):
size = 0.8 if depth < 2 else 1
html = ''
for k in entry:
if k == "collapsed":
continue
collapse_single = k.endswith("_collapsed")
if collapse_single:
name = k[:-len("_collapsed")]
else:
name = k
collapse_flag = ' VHS_precollapse' if entry.get("collapsed", False) or collapse_single else ''
html += f'<div vhs_title=\"{name}\" style=\"display: flex; font-size: {size}em\" class=\"VHS_collapse{collapse_flag}\"><div style=\"color: #AAA; height: 1.5em;\">[<span style=\"font-family: monospace\">-</span>]</div><div style=\"width: 100%\">{name}: {as_html(entry[k], depth=depth+1)}</div></div>'
return html
if isinstance(entry, list):
if depth == 0:
depth += 1
size = .8
else:
size = 1
html = ''
html += entry[0]
for i in entry[1:]:
html += f'<div style=\"font-size: {size}em\">{as_html(i, depth=depth)}</div>'
return html
return str(entry)
def format_descriptions(nodes):
for k in descriptions:
if k.endswith("_collapsed"):
k = k[:-len("_collapsed")]
nodes[k].DESCRIPTION = as_html(descriptions[k])
undocumented_nodes = []
for k in nodes:
if not hasattr(nodes[k], "DESCRIPTION"):
undocumented_nodes.append(k)
if len(undocumented_nodes) > 0:
logger.warning('Some nodes have not been documented %s', undocumented_nodes)
@@ -0,0 +1,554 @@
from torch import Tensor
import torch
import comfy.utils
from .utils import BIGMIN, BIGMAX, select_indexes_from_str, convert_str_to_indexes, select_indexes
class MergeStrategies:
MATCH_A = "match A"
MATCH_B = "match B"
MATCH_SMALLER = "match smaller"
MATCH_LARGER = "match larger"
list_all = [MATCH_A, MATCH_B, MATCH_SMALLER, MATCH_LARGER]
class ScaleMethods:
NEAREST_EXACT = "nearest-exact"
BILINEAR = "bilinear"
AREA = "area"
BICUBIC = "bicubic"
BISLERP = "bislerp"
list_all = [NEAREST_EXACT, BILINEAR, AREA, BICUBIC, BISLERP]
class CropMethods:
DISABLED = "disabled"
CENTER = "center"
list_all = [DISABLED, CENTER]
class SplitLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT", "LATENT", "INT")
RETURN_NAMES = ("LATENT_A", "A_count", "LATENT_B", "B_count")
FUNCTION = "split_latents"
def split_latents(self, latents: dict[str, Tensor], split_index: int):
latents_len = len(latents["samples"])
group_a = latents.copy()
group_b = latents.copy()
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
group_a[key] = latents[key][:split_index]
group_b[key] = latents[key][split_index:]
return (group_a, group_a["samples"].size(0), group_b, group_b["samples"].size(0))
class SplitImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT", "IMAGE", "INT")
RETURN_NAMES = ("IMAGE_A", "A_count", "IMAGE_B", "B_count")
FUNCTION = "split_images"
def split_images(self, images: Tensor, split_index: int):
group_a = images[:split_index]
group_b = images[split_index:]
return (group_a, group_a.size(0), group_b, group_b.size(0))
class SplitMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT", "MASK", "INT")
RETURN_NAMES = ("MASK_A", "A_count", "MASK_B", "B_count")
FUNCTION = "split_masks"
def split_masks(self, mask: Tensor, split_index: int):
group_a = mask[:split_index]
group_b = mask[split_index:]
return (group_a, group_a.size(0), group_b, group_b.size(0))
class MergeLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents_A": ("LATENT",),
"latents_B": ("LATENT",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "merge"
def merge(self, latents_A: dict, latents_B: dict, merge_strategy: str, scale_method: str, crop: str):
latents = []
latents_A = latents_A.copy()["samples"]
latents_B = latents_B.copy()["samples"]
# TODO: handle other properties on latents besides just "samples"
# if not same dimensions, do scaling
if latents_A.shape[3] != latents_B.shape[3] or latents_A.shape[2] != latents_B.shape[2]:
A_size = latents_A.shape[3] * latents_A.shape[2]
B_size = latents_B.shape[3] * latents_B.shape[2]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# apply scaling
if use_A_as_template:
latents_B = comfy.utils.common_upscale(latents_B, latents_A.shape[3], latents_A.shape[2], scale_method, crop)
else:
latents_A = comfy.utils.common_upscale(latents_A, latents_B.shape[3], latents_B.shape[2], scale_method, crop)
latents.append(latents_A)
latents.append(latents_B)
merged = {"samples": torch.cat(latents, dim=0)}
return (merged, len(merged["samples"]),)
class MergeImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images_A": ("IMAGE",),
"images_B": ("IMAGE",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "merge"
def merge(self, images_A: Tensor, images_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
images = []
# if not same dimensions, do scaling
if images_A.shape[3] != images_B.shape[3] or images_A.shape[2] != images_B.shape[2]:
images_A = images_A.movedim(-1,1)
images_B = images_B.movedim(-1,1)
A_size = images_A.shape[3] * images_A.shape[2]
B_size = images_B.shape[3] * images_B.shape[2]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# apply scaling
if use_A_as_template:
images_B = comfy.utils.common_upscale(images_B, images_A.shape[3], images_A.shape[2], scale_method, crop)
else:
images_A = comfy.utils.common_upscale(images_A, images_B.shape[3], images_B.shape[2], scale_method, crop)
images_A = images_A.movedim(1,-1)
images_B = images_B.movedim(1,-1)
images.append(images_A)
images.append(images_B)
all_images = torch.cat(images, dim=0)
return (all_images, all_images.size(0),)
class MergeMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask_A": ("MASK",),
"mask_B": ("MASK",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "merge"
def merge(self, mask_A: Tensor, mask_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
masks = []
# if not same dimensions, do scaling
if mask_A.shape[2] != mask_B.shape[2] or mask_A.shape[1] != mask_B.shape[1]:
A_size = mask_A.shape[2] * mask_A.shape[1]
B_size = mask_B.shape[2] * mask_B.shape[1]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# add dimension where image channels would be expected to work with common_upscale
mask_A = torch.unsqueeze(mask_A, 1)
mask_B = torch.unsqueeze(mask_B, 1)
# apply scaling
if use_A_as_template:
mask_B = comfy.utils.common_upscale(mask_B, mask_A.shape[3], mask_A.shape[2], scale_method, crop)
else:
mask_A = comfy.utils.common_upscale(mask_A, mask_B.shape[3], mask_B.shape[2], scale_method, crop)
# undo dimension increase
mask_A = torch.squeeze(mask_A, 1)
mask_B = torch.squeeze(mask_B, 1)
masks.append(mask_A)
masks.append(mask_B)
all_masks = torch.cat(masks, dim=0)
return (all_masks, all_masks.size(0),)
class SelectEveryNthLatent:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_latents": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "select_latents"
def select_latents(self, latents: dict[str, Tensor], select_every_nth: int, skip_first_latents: int):
latents = latents.copy()
latents_len = len(latents["samples"])
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
latents[key] = val[skip_first_latents::select_every_nth]
return (latents, latents["samples"].size(0))
class SelectEveryNthImage:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "select_images"
def select_images(self, images: Tensor, select_every_nth: int, skip_first_images: int):
sub_images = images[skip_first_images::select_every_nth]
return (sub_images, sub_images.size(0))
class SelectEveryNthMask:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_masks": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "select_masks"
def select_masks(self, mask: Tensor, select_every_nth: int, skip_first_masks: int):
sub_mask = mask[skip_first_masks::select_every_nth]
return (sub_mask, sub_mask.size(0))
class GetLatentCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, latents: dict):
return (latents["samples"].size(0),)
class GetImageCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, images: Tensor):
return (images.size(0),)
class GetMaskCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, mask: Tensor):
return (mask.size(0),)
class RepeatLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, latents: dict[str, Tensor], multiply_by: int):
latents = latents.copy()
latents_len = len(latents["samples"])
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
full_latents = []
for _ in range(0, multiply_by):
full_latents.append(latents[key])
latents[key] = torch.cat(full_latents, dim=0)
return (latents, latents["samples"].size(0),)
class RepeatImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, images: Tensor, multiply_by: int):
full_images = []
for n in range(0, multiply_by):
full_images.append(images)
new_images = torch.cat(full_images, dim=0)
return (new_images, new_images.size(0),)
class RepeatMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, mask: Tensor, multiply_by: int):
full_masks = []
for n in range(0, multiply_by):
full_masks.append(mask)
new_mask = torch.cat(full_masks, dim=0)
return (new_mask, new_mask.size(0),)
select_description = """Use comma-separated indexes to select items in the given order.
Supports negative indexes, python-style ranges (end index excluded),
as well as range step.
Acceptable entries (assuming 16 items provided, so idxs 0 to 15 exist):
0 -> Returns [0]
-1 -> Returns [15]
0, 1, 13 -> Returns [0, 1, 13]
0:5, 13 -> Returns [0, 1, 2, 3, 4, 13]
0:-1 -> Returns [0, 1, 2, ..., 13, 14]
0:5:-1 -> Returns [4, 3, 2, 1, 0]
0:5:2 -> Returns [0, 2, 4]
::-1 -> Returns [15, 14, 13, ..., 2, 1, 0]
"""
class SelectLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latent": ("LATENT",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT",)
FUNCTION = "select"
def select(self, latent: dict[str, Tensor], indexes: str, err_if_missing: bool, err_if_empty: bool):
# latents are a dict and may contain different stuff (like noise_mask), so need to account for it all
latent = latent.copy()
latents_len = len(latent["samples"])
real_idxs = convert_str_to_indexes(indexes, latents_len, allow_missing=not err_if_missing)
if err_if_empty and len(real_idxs) == 0:
raise Exception(f"Nothing was selected based on indexes found in '{indexes}'.")
for key, val in latent.items():
if type(val) == Tensor and len(val) == latents_len:
latent[key] = select_indexes(val, real_idxs)
return (latent,)
class SelectImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE",)
FUNCTION = "select"
def select(self, image: Tensor, indexes: str, err_if_missing: bool, err_if_empty: bool):
to_return = select_indexes_from_str(input_obj=image, indexes=indexes,
err_if_missing=err_if_missing, err_if_empty=err_if_empty)
to_return_type = type(to_return)
return (to_return,)
class SelectMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK",)
FUNCTION = "select"
def select(self, mask: Tensor, indexes: str, err_if_missing: bool, err_if_empty: bool):
return (select_indexes_from_str(input_obj=mask, indexes=indexes,
err_if_missing=err_if_missing, err_if_empty=err_if_empty),)
@@ -0,0 +1,114 @@
from PIL import Image
import time
import io
import struct
from threading import Thread
import torch.nn.functional as F
import torch
import latent_preview
import server
serv = server.PromptServer.instance
from .utils import hook
rates_table = {'Mochi': 24//6, 'LTXV': 24//8, 'HunyuanVideo': 24//4,
'Cosmos1CV8x8x8': 24//8, 'Wan21': 16//4, 'Wan22': 24//4}
class WrappedPreviewer(latent_preview.LatentPreviewer):
def __init__(self, previewer, rate=8):
self.first_preview = True
self.last_time = 0
self.c_index = 0
self.rate = rate
if hasattr(previewer, 'taesd'):
self.taesd = previewer.taesd
elif hasattr(previewer, 'latent_rgb_factors'):
self.latent_rgb_factors = previewer.latent_rgb_factors
self.latent_rgb_factors_bias = previewer.latent_rgb_factors_bias
self.latent_rgb_factors_reshape = getattr(previewer, 'latent_rgb_factors_reshape', None)
else:
raise Exception('Unsupported preview type for VHS animated previews')
def decode_latent_to_preview_image(self, preview_format, x0):
if x0.ndim == 5:
#Keep batch major
x0 = x0.movedim(2,1)
x0 = x0.reshape((-1,)+x0.shape[-3:])
num_images = x0.size(0)
new_time = time.time()
num_previews = int((new_time - self.last_time) * self.rate)
self.last_time = self.last_time + num_previews/self.rate
if num_previews > num_images:
num_previews = num_images
elif num_previews <= 0:
return None
if self.first_preview:
self.first_preview = False
serv.send_sync('VHS_latentpreview', {'length':num_images, 'rate': self.rate, 'id': serv.last_node_id})
self.last_time = new_time + 1/self.rate
if self.c_index + num_previews > num_images:
x0 = x0.roll(-self.c_index, 0)[:num_previews]
else:
x0 = x0[self.c_index:self.c_index + num_previews]
Thread(target=self.process_previews, args=(x0, self.c_index,
num_images)).run()
self.c_index = (self.c_index + num_previews) % num_images
return None
def process_previews(self, image_tensor, ind, leng):
image_tensor = self.decode_latent_to_preview(image_tensor)
if image_tensor.size(1) > 512 or image_tensor.size(2) > 512:
image_tensor = image_tensor.movedim(-1,0)
if image_tensor.size(2) < image_tensor.size(3):
height = (512 * image_tensor.size(2)) // image_tensor.size(3)
image_tensor = F.interpolate(image_tensor, (height,512), mode='bilinear')
else:
width = (512 * image_tensor.size(3)) // image_tensor.size(2)
image_tensor = F.interpolate(image_tensor, (512, width), mode='bilinear')
image_tensor = image_tensor.movedim(0,-1)
previews_ubyte = (((image_tensor + 1.0) / 2.0).clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
).to(device="cpu", dtype=torch.uint8)
for preview in previews_ubyte:
i = Image.fromarray(preview.numpy())
message = io.BytesIO()
message.write((1).to_bytes(length=4, byteorder='big')*2)
message.write(ind.to_bytes(length=4, byteorder='big'))
message.write(struct.pack('16p', serv.last_node_id.encode('ascii')))
i.save(message, format="JPEG", quality=95, compress_level=1)
#NOTE: send sync already uses call_soon_threadsafe
serv.send_sync(server.BinaryEventTypes.PREVIEW_IMAGE,
message.getvalue(), serv.client_id)
ind = (ind + 1) % leng
def decode_latent_to_preview(self, x0):
if hasattr(self, 'taesd'):
x_sample = self.taesd.decode(x0).movedim(1, 3)
return x_sample
else:
if self.latent_rgb_factors_reshape is not None:
x0 = self.latent_rgb_factors_reshape(x0)
self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device)
if self.latent_rgb_factors_bias is not None:
self.latent_rgb_factors_bias = self.latent_rgb_factors_bias.to(dtype=x0.dtype, device=x0.device)
latent_image = F.linear(x0.movedim(1, -1), self.latent_rgb_factors,
bias=self.latent_rgb_factors_bias)
return latent_image
@hook(latent_preview, 'get_previewer')
def get_latent_video_previewer(device, latent_format, *args, **kwargs):
node_id = serv.last_node_id
previewer = get_latent_video_previewer.__wrapped__(device, latent_format, *args, **kwargs)
try:
extra_info = next(serv.prompt_queue.currently_running.values().__iter__()) \
[3]['extra_pnginfo']['workflow']['extra']
prev_setting = extra_info.get('VHS_latentpreview', False)
if extra_info.get('VHS_latentpreviewrate', 0) != 0:
rate_setting = extra_info['VHS_latentpreviewrate']
else:
rate_setting = rates_table.get(latent_format.__class__.__name__, 8)
except:
#For safety since there's lots of keys, any of which can fail
prev_setting = False
if not prev_setting or not hasattr(previewer, "decode_latent_to_preview"):
return previewer
return WrappedPreviewer(previewer, rate_setting)
@@ -0,0 +1,206 @@
import os
import hashlib
import numpy as np
import torch
from PIL import Image, ImageOps
import itertools
import folder_paths
from comfy.k_diffusion.utils import FolderOfImages
from comfy.utils import common_upscale, ProgressBar
from .logger import logger
from .utils import BIGMAX, calculate_file_hash, get_sorted_dir_files_from_directory, validate_path, strip_path
def is_changed_load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, **kwargs):
if not os.path.isdir(directory):
return False
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if image_load_cap != 0:
dir_files = dir_files[:image_load_cap]
m = hashlib.sha256()
for filepath in dir_files:
m.update(calculate_file_hash(filepath).encode()) # strings must be encoded before hashing
return m.digest().hex()
def validate_load_images(directory: str):
if not os.path.isdir(directory):
return f"Directory '{directory}' cannot be found."
dir_files = os.listdir(directory)
if len(dir_files) == 0:
return f"No files in directory '{directory}'."
return True
def images_generator(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, meta_batch=None, unique_id=None):
if not os.path.isdir(directory):
raise FileNotFoundError(f"Directory '{directory} cannot be found.")
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if len(dir_files) == 0:
raise FileNotFoundError(f"No files in directory '{directory}'.")
if image_load_cap > 0:
dir_files = dir_files[:image_load_cap]
sizes = {}
has_alpha = False
for image_path in dir_files:
i = Image.open(image_path)
#exif_transpose can only ever rotate, but rotating can swap width/height
i = ImageOps.exif_transpose(i)
has_alpha |= 'A' in i.getbands()
count = sizes.get(i.size, 0)
sizes[i.size] = count +1
size = max(sizes.items(), key=lambda x: x[1])[0]
yield size[0], size[1], has_alpha
if meta_batch is not None:
yield min(image_load_cap, len(dir_files)) or len(dir_files)
iformat = "RGBA" if has_alpha else "RGB"
def load_image(file_path):
i = Image.open(file_path)
i = ImageOps.exif_transpose(i)
i = i.convert(iformat)
i = np.array(i, dtype=np.float32)
#This nonsense provides a nearly 50% speedup on my system
torch.from_numpy(i).div_(255)
if i.shape[0] != size[1] or i.shape[1] != size[0]:
i = torch.from_numpy(i).movedim(-1, 0).unsqueeze(0)
i = common_upscale(i, size[0], size[1], "lanczos", "center")
i = i.squeeze(0).movedim(0, -1).numpy()
if has_alpha:
i[:,:,-1] = 1 - i[:,:,-1]
return i
total_images = len(dir_files)
processed_images = 0
pbar = ProgressBar(total_images)
images = map(load_image, dir_files)
try:
prev_image = next(images)
while True:
next_image = next(images)
yield prev_image
processed_images += 1
pbar.update_absolute(processed_images, total_images)
prev_image = next_image
except StopIteration:
pass
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_image is not None:
yield prev_image
def load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, meta_batch=None, unique_id=None):
if meta_batch is None or unique_id not in meta_batch.inputs:
gen = images_generator(directory, image_load_cap, skip_first_images, select_every_nth, meta_batch, unique_id)
(width, height, has_alpha) = next(gen)
if meta_batch is not None:
meta_batch.inputs[unique_id] = (gen, width, height, has_alpha)
meta_batch.total_frames = min(meta_batch.total_frames, next(gen))
else:
gen, width, height, has_alpha = meta_batch.inputs[unique_id]
if meta_batch is not None:
gen = itertools.islice(gen, meta_batch.frames_per_batch)
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (height, width, 3 + has_alpha)))))
if has_alpha:
#tensors are not continuous. Rewrite will be required if this is an issue
masks = images[:,:,:,3]
images = images[:,:,:,:3]
else:
masks = torch.zeros((images.size(0), 64, 64), dtype=torch.float32, device="cpu")
if len(images) == 0:
raise FileNotFoundError(f"No images could be loaded from directory '{directory}'.")
return images, masks, images.size(0)
class LoadImagesFromDirectoryUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
directories = []
for item in os.listdir(input_dir):
if not os.path.isfile(os.path.join(input_dir, item)) and item != "clipspace":
directories.append(item)
return {
"required": {
"directory": (directories,),
},
"optional": {
"image_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"meta_batch": ("VHS_BatchManager",),
},
"hidden": {
"unique_id": "UNIQUE_ID"
},
}
RETURN_TYPES = ("IMAGE", "MASK", "INT")
RETURN_NAMES = ("IMAGE", "MASK", "frame_count")
FUNCTION = "load_images"
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
def load_images(self, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return load_images(directory, **kwargs)
@classmethod
def IS_CHANGED(s, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return is_changed_load_images(directory, **kwargs)
@classmethod
def VALIDATE_INPUTS(s, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return validate_load_images(directory)
class LoadImagesFromDirectoryPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"directory": ("STRING", {"placeholder": "X://path/to/images", "vhs_path_extensions": []}),
},
"optional": {
"image_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"meta_batch": ("VHS_BatchManager",),
},
"hidden": {
"unique_id": "UNIQUE_ID"
},
}
RETURN_TYPES = ("IMAGE", "MASK", "INT")
RETURN_NAMES = ("IMAGE", "MASK", "frame_count")
FUNCTION = "load_images"
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
def load_images(self, directory: str, **kwargs):
directory = strip_path(directory)
if directory is None or validate_load_images(directory) != True:
raise Exception("directory is not valid: " + directory)
return load_images(directory, **kwargs)
@classmethod
def IS_CHANGED(s, directory: str, **kwargs):
if directory is None:
return "input"
return is_changed_load_images(directory, **kwargs)
@classmethod
def VALIDATE_INPUTS(s, directory: str, **kwargs):
if directory is None:
return True
return validate_load_images(strip_path(directory))
@@ -0,0 +1,671 @@
import os
import itertools
import numpy as np
import torch
from PIL import Image, ImageOps
import cv2
import psutil
import subprocess
import re
import time
import folder_paths
from comfy.utils import common_upscale, ProgressBar
import nodes
from comfy.k_diffusion.utils import FolderOfImages
from .logger import logger
from .utils import BIGMAX, DIMMAX, calculate_file_hash, get_sorted_dir_files_from_directory,\
lazy_get_audio, hash_path, validate_path, strip_path, try_download_video, \
is_url, imageOrLatent, ffmpeg_path, ENCODE_ARGS, floatOrInt
video_extensions = ['webm', 'mp4', 'mkv', 'gif', 'mov']
VHSLoadFormats = {
'None': {},
'AnimateDiff': {'target_rate': 8, 'dim': (8,0,512,512)},
'Mochi': {'target_rate': 24, 'dim': (16,0,848,480), 'frames':(6,1)},
'LTXV': {'target_rate': 24, 'dim': (32,0,768,512), 'frames':(8,1)},
'Hunyuan': {'target_rate': 24, 'dim': (16,0,848,480), 'frames':(4,1)},
'Cosmos': {'target_rate': 24, 'dim': (16,0,1280,704), 'frames':(8,1)},
'Wan': {'target_rate': 16, 'dim': (8,0,832,480), 'frames':(4,1)},
}
"""
External plugins may add additional formats to nodes.VHSLoadFormats
In addition to shorthand options, direct widget names will map a given dict to options.
Adding a third arguement to a frames tuple can enable strict checks on number
of loaded frames, i.e (8,1,True)
"""
if not hasattr(nodes, 'VHSLoadFormats'):
nodes.VHSLoadFormats = {}
def get_load_formats():
#TODO: check if {**extra_config.VHSLoafFormats, **VHSLoadFormats} has minimum version
formats = {}
formats.update(nodes.VHSLoadFormats)
formats.update(VHSLoadFormats)
return (list(formats.keys()),
{'default': 'AnimateDiff', 'formats': formats})
def get_format(format):
if format in VHSLoadFormats:
return VHSLoadFormats[format]
return nodes.VHSLoadFormats.get(format, {})
def is_gif(filename) -> bool:
file_parts = filename.split('.')
return len(file_parts) > 1 and file_parts[-1] == "gif"
def target_size(width, height, custom_width, custom_height, downscale_ratio=8) -> tuple[int, int]:
if downscale_ratio is None:
downscale_ratio = 8
if custom_width == 0 and custom_height == 0:
pass
elif custom_height == 0:
height *= custom_width/width
width = custom_width
elif custom_width == 0:
width *= custom_height/height
height = custom_height
else:
width = custom_width
height = custom_height
width = int(width/downscale_ratio + 0.5) * downscale_ratio
height = int(height/downscale_ratio + 0.5) * downscale_ratio
return (width, height)
def cv_frame_generator(video, force_rate, frame_load_cap, skip_first_frames,
select_every_nth, meta_batch=None, unique_id=None):
video_cap = cv2.VideoCapture(video)
if not video_cap.isOpened() or not video_cap.grab():
raise ValueError(f"{video} could not be loaded with cv.")
# extract video metadata
fps = video_cap.get(cv2.CAP_PROP_FPS)
width = int(video_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
total_frames = int(video_cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = total_frames / fps
width = 0
if width <=0 or height <=0:
_, frame = video_cap.retrieve()
height, width, _ = frame.shape
# set video_cap to look at start_index frame
total_frame_count = 0
total_frames_evaluated = -1
frames_added = 0
base_frame_time = 1 / fps
prev_frame = None
if force_rate == 0:
target_frame_time = base_frame_time
else:
target_frame_time = 1/force_rate
if total_frames > 0:
if force_rate != 0:
yieldable_frames = int(total_frames / fps * force_rate)
else:
yieldable_frames = total_frames
if select_every_nth:
yieldable_frames //= select_every_nth
if frame_load_cap != 0:
yieldable_frames = min(frame_load_cap, yieldable_frames)
else:
yieldable_frames = 0
yield (width, height, fps, duration, total_frames, target_frame_time, yieldable_frames)
pbar = ProgressBar(yieldable_frames)
time_offset=target_frame_time
while video_cap.isOpened():
if time_offset < target_frame_time:
is_returned = video_cap.grab()
# if didn't return frame, video has ended
if not is_returned:
break
time_offset += base_frame_time
if time_offset < target_frame_time:
continue
time_offset -= target_frame_time
# if not at start_index, skip doing anything with frame
total_frame_count += 1
if total_frame_count <= skip_first_frames:
continue
else:
total_frames_evaluated += 1
# if should not be selected, skip doing anything with frame
if total_frames_evaluated%select_every_nth != 0:
continue
# opencv loads images in BGR format (yuck), so need to convert to RGB for ComfyUI use
# follow up: can videos ever have an alpha channel?
# To my testing: No. opencv has no support for alpha
unused, frame = video_cap.retrieve()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# convert frame to comfyui's expected format
# TODO: frame contains no exif information. Check if opencv2 has already applied
frame = np.array(frame, dtype=np.float32)
torch.from_numpy(frame).div_(255)
if prev_frame is not None:
inp = yield prev_frame
if inp is not None:
#ensure the finally block is called
return
prev_frame = frame
frames_added += 1
if pbar is not None:
pbar.update_absolute(frames_added, yieldable_frames)
# if cap exists and we've reached it, stop processing frames
if frame_load_cap > 0 and frames_added >= frame_load_cap:
break
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_frame is not None:
yield prev_frame
def ffmpeg_frame_generator(video, force_rate, frame_load_cap, start_time,
custom_width, custom_height, downscale_ratio=8,
meta_batch=None, unique_id=None):
args_input = ["-i", video]
args_dummy = [ffmpeg_path] + args_input +['-c', 'copy', '-frames:v', '1', "-f", "null", "-"]
size_base = None
fps_base = None
try:
dummy_res = subprocess.run(args_dummy, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the ffmpeg subprocess:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
lines = dummy_res.stderr.decode(*ENCODE_ARGS)
if "Video: vp9 " in lines:
args_input = ["-c:v", "libvpx-vp9"] + args_input
args_dummy = [ffmpeg_path] + args_input +['-c', 'copy', '-frames:v', '1', "-f", "null", "-"]
try:
dummy_res = subprocess.run(args_dummy, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the ffmpeg subprocess:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
lines = dummy_res.stderr.decode(*ENCODE_ARGS)
for line in lines.split('\n'):
match = re.search("^ *Stream .* Video.*, ([1-9]|\\d{2,})x(\\d+)", line)
if match is not None:
size_base = [int(match.group(1)), int(match.group(2))]
fps_match = re.search(", ([\\d\\.]+) fps", line)
if fps_match:
fps_base = float(fps_match.group(1))
else:
fps_base = 1
alpha = re.search("(yuva|rgba|bgra|gbra)", line) is not None
break
else:
raise Exception("Failed to parse video/image information. FFMPEG output:\n" + lines)
durs_match = re.search("Duration: (\\d+:\\d+:\\d+\\.\\d+),", lines)
if durs_match:
durs = durs_match.group(1).split(':')
duration = int(durs[0])*3600 + int(durs[1])*60 + float(durs[2])
else:
duration = 0
if start_time > 0:
if start_time > 4:
post_seek = ['-ss', '4']
args_input = ['-ss', str(start_time - 4)] + args_input
else:
post_seek = ['-ss', str(start_time)]
else:
post_seek = []
args_all_frames = [ffmpeg_path, "-v", "error", "-an"] + \
args_input + ["-pix_fmt", "rgba64le"] + post_seek
vfilters = []
if force_rate != 0:
vfilters.append("fps=fps="+str(force_rate))
if custom_width != 0 or custom_height != 0:
size = target_size(size_base[0], size_base[1], custom_width,
custom_height, downscale_ratio=downscale_ratio)
ar = float(size[0])/float(size[1])
if abs(size_base[0]*ar-size_base[1]) >= 1:
#Aspect ratio is changed. Crop to new aspect ratio before scale
vfilters.append(f"crop=if(gt({ar}\\,a)\\,iw\\,ih*{ar}):if(gt({ar}\\,a)\\,iw/{ar}\\,ih)")
size_arg = ':'.join(map(str,size))
vfilters.append(f"scale={size_arg}")
else:
size = size_base
if len(vfilters) > 0:
args_all_frames += ["-vf", ",".join(vfilters)]
yieldable_frames = (force_rate or fps_base)*duration
if frame_load_cap > 0:
args_all_frames += ["-frames:v", str(frame_load_cap)]
yieldable_frames = min(yieldable_frames, frame_load_cap)
yield (size_base[0], size_base[1], fps_base, duration, fps_base * duration,
1/(force_rate or fps_base), yieldable_frames, size[0], size[1], alpha)
args_all_frames += ["-f", "rawvideo", "-"]
pbar = ProgressBar(yieldable_frames)
try:
with subprocess.Popen(args_all_frames, stdout=subprocess.PIPE) as proc:
#Manually buffer enough bytes for an image
bpi = size[0] * size[1] * 8
current_bytes = bytearray(bpi)
current_offset=0
prev_frame = None
while True:
bytes_read = proc.stdout.read(bpi - current_offset)
if bytes_read is None:#sleep to wait for more data
time.sleep(.1)
continue
if len(bytes_read) == 0:#EOF
break
current_bytes[current_offset:len(bytes_read)] = bytes_read
current_offset+=len(bytes_read)
if current_offset == bpi:
if prev_frame is not None:
yield prev_frame
pbar.update(1)
prev_frame = np.frombuffer(current_bytes, dtype=np.dtype(np.uint16).newbyteorder("<")).reshape(size[1], size[0], 4) / (2**16-1)
if not alpha:
prev_frame = prev_frame[:, :, :-1]
current_offset = 0
except BrokenPipeError as e:
raise Exception("An error occured in the ffmpeg subprocess:\n" \
+ proc.stderr.read().decode(*ENCODE_ARGS))
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_frame is not None:
yield prev_frame
#Python 3.12 adds an itertools.batched, but it's easily replicated for legacy support
def batched(it, n):
while batch := tuple(itertools.islice(it, n)):
yield batch
def batched_vae_encode(images, vae, frames_per_batch):
for batch in batched(images, frames_per_batch):
image_batch = torch.from_numpy(np.array(batch))
yield from vae.encode(image_batch).numpy()
def resized_cv_frame_gen(custom_width, custom_height, downscale_ratio, **kwargs):
gen = cv_frame_generator(**kwargs)
info = next(gen)
width, height = info[0], info[1]
frames_per_batch = (1920 * 1080 * 16) // (width * height) or 1
if kwargs.get('meta_batch', None) is not None:
frames_per_batch = min(frames_per_batch, kwargs['meta_batch'].frames_per_batch)
if custom_width != 0 or custom_height != 0 or downscale_ratio is not None:
new_size = target_size(width, height, custom_width, custom_height, downscale_ratio)
yield (*info, new_size[0], new_size[1], False)
if new_size[0] != width or new_size[1] != height:
def rescale(frame):
s = torch.from_numpy(np.fromiter(frame, np.dtype((np.float32, (height, width, 3)))))
s = s.movedim(-1,1)
s = common_upscale(s, new_size[0], new_size[1], "lanczos", "center")
return s.movedim(1,-1).numpy()
yield from itertools.chain.from_iterable(map(rescale, batched(gen, frames_per_batch)))
return
else:
yield (*info, info[0], info[1], False)
yield from gen
def load_video(meta_batch=None, unique_id=None, memory_limit_mb=None, vae=None,
generator=resized_cv_frame_gen, format='None', **kwargs):
if 'force_size' in kwargs:
kwargs.pop('force_size')
logger.warn("force_size has been removed. Did you reload the webpage after updating?")
format = get_format(format)
kwargs['video'] = strip_path(kwargs['video'])
if vae is not None:
downscale_ratio = getattr(vae, "downscale_ratio", 8)
else:
downscale_ratio = format.get('dim', (1,))[0]
if meta_batch is None or unique_id not in meta_batch.inputs:
gen = generator(meta_batch=meta_batch, unique_id=unique_id, downscale_ratio=downscale_ratio, **kwargs)
(width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha) = next(gen)
if meta_batch is not None:
meta_batch.inputs[unique_id] = (gen, width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha)
if yieldable_frames:
meta_batch.total_frames = min(meta_batch.total_frames, yieldable_frames)
else:
(gen, width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha) = meta_batch.inputs[unique_id]
memory_limit = None
if memory_limit_mb is not None:
memory_limit *= 2 ** 20
else:
#TODO: verify if garbage collection should be performed here.
#leaves ~128 MB unreserved for safety
try:
memory_limit = (psutil.virtual_memory().available + psutil.swap_memory().free) - 2 ** 27
except:
logger.warn("Failed to calculate available memory. Memory load limit has been disabled")
memory_limit = BIGMAX
if vae is not None:
#space required to load as f32, exist as latent with wiggle room, decode to f32
max_loadable_frames = int(memory_limit//(width*height*3*(4+4+1/10)))
else:
#TODO: use better estimate for when vae is not None
#Consider completely ignoring for load_latent case?
max_loadable_frames = int(memory_limit//(width*height*3*(.1)))
if meta_batch is not None:
if 'frames' in format:
if meta_batch.frames_per_batch % format['frames'][0] != format['frames'][1]:
error = (meta_batch.frames_per_batch - format['frames'][1]) % format['frames'][0]
suggested = meta_batch.frames_per_batch - error
if error > format['frames'][0] / 2:
suggested += format['frames'][0]
raise RuntimeError(f"The chosen frames per batch is incompatible with the selected format. Try {suggested}")
if meta_batch.frames_per_batch > max_loadable_frames:
raise RuntimeError(f"Meta Batch set to {meta_batch.frames_per_batch} frames but only {max_loadable_frames} can fit in memory")
gen = itertools.islice(gen, meta_batch.frames_per_batch)
else:
original_gen = gen
gen = itertools.islice(gen, max_loadable_frames)
frames_per_batch = (1920 * 1080 * 16) // (width * height) or 1
if vae is not None:
gen = batched_vae_encode(gen, vae, frames_per_batch)
vw,vh = new_width//downscale_ratio, new_height//downscale_ratio
channels = getattr(vae, 'latent_channels', 4)
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (channels,vh,vw)))))
else:
#Some minor wizardry to eliminate a copy and reduce max memory by a factor of ~2
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (new_height, new_width, 4 if alpha else 3)))))
if meta_batch is None and memory_limit is not None:
try:
next(original_gen)
raise RuntimeError(f"Memory limit hit after loading {len(images)} frames. Stopping execution.")
except StopIteration:
pass
if len(images) == 0:
raise RuntimeError("No frames generated")
if 'frames' in format and len(images) % format['frames'][0] != format['frames'][1]:
err_msg = f"The number of frames loaded {len(images)}, does not match the requirements of the currently selected format."
if len(format['frames']) > 2 and format['frames'][2]:
raise RuntimeError(err_msg)
div, mod = format['frames'][:2]
frames = (len(images) - mod) // div * div + mod
images = images[:frames]
#Commenting out log message since it's displayed in UI. consider further
#logger.warn(err_msg + f" Output has been truncated to {len(images)} frames.")
if 'start_time' in kwargs:
start_time = kwargs['start_time']
else:
start_time = kwargs['skip_first_frames'] * target_frame_time
target_frame_time *= kwargs.get('select_every_nth', 1)
#Setup lambda for lazy audio capture
audio = lazy_get_audio(kwargs['video'], start_time, kwargs['frame_load_cap']*target_frame_time)
#Adjust target_frame_time for select_every_nth
video_info = {
"source_fps": fps,
"source_frame_count": total_frames,
"source_duration": duration,
"source_width": width,
"source_height": height,
"loaded_fps": 1/target_frame_time,
"loaded_frame_count": len(images),
"loaded_duration": len(images) * target_frame_time,
"loaded_width": new_width,
"loaded_height": new_height,
}
if vae is None:
return (images, len(images), audio, video_info)
else:
return ({"samples": images}, len(images), audio, video_info)
class LoadVideoUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = []
for f in os.listdir(input_dir):
if os.path.isfile(os.path.join(input_dir, f)):
file_parts = f.split('.')
if len(file_parts) > 1 and (file_parts[-1].lower() in video_extensions):
files.append(f)
return {"required": {
"video": (sorted(files),),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"skip_first_frames": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
kwargs['video'] = folder_paths.get_annotated_filepath(strip_path(kwargs['video']))
return load_video(**kwargs)
@classmethod
def IS_CHANGED(s, video, **kwargs):
image_path = folder_paths.get_annotated_filepath(video)
return calculate_file_hash(image_path)
@classmethod
def VALIDATE_INPUTS(s, video):
if not folder_paths.exists_annotated_filepath(video):
return "Invalid video file: {}".format(video)
return True
class LoadVideoPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"video": ("STRING", {"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"skip_first_frames": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
if kwargs['video'] is None or validate_path(kwargs['video']) != True:
raise Exception("video is not a valid path: " + kwargs['video'])
if is_url(kwargs['video']):
kwargs['video'] = try_download_video(kwargs['video']) or kwargs['video']
return load_video(**kwargs)
@classmethod
def IS_CHANGED(s, video, **kwargs):
return hash_path(video)
@classmethod
def VALIDATE_INPUTS(s, video):
return validate_path(video, allow_none=True)
class LoadVideoFFmpegUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = []
for f in os.listdir(input_dir):
if os.path.isfile(os.path.join(input_dir, f)):
file_parts = f.split('.')
if len(file_parts) > 1 and (file_parts[-1].lower() in video_extensions):
files.append(f)
return {"required": {
"video": (sorted(files),),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"start_time": ("FLOAT", {"default": 0, "min": 0, "max": BIGMAX, "step": .001, "widgetType": "VHSTIMESTAMP"}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "mask", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
kwargs['video'] = folder_paths.get_annotated_filepath(strip_path(kwargs['video']))
image, _, audio, video_info = load_video(**kwargs, generator=ffmpeg_frame_generator)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3], audio, video_info)
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"), audio, video_info)
@classmethod
def IS_CHANGED(s, video, **kwargs):
image_path = folder_paths.get_annotated_filepath(video)
return calculate_file_hash(image_path)
@classmethod
def VALIDATE_INPUTS(s, video):
if not folder_paths.exists_annotated_filepath(video):
return "Invalid video file: {}".format(video)
return True
class LoadVideoFFmpegPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"video": ("STRING", {"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"start_time": ("FLOAT", {"default": 0, "min": 0, "max": BIGMAX, "step": .001, "widgetType": "VHSTIMESTAMP"}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "mask", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
if kwargs['video'] is None or validate_path(kwargs['video']) != True:
raise Exception("video is not a valid path: " + kwargs['video'])
if is_url(kwargs['video']):
kwargs['video'] = try_download_video(kwargs['video']) or kwargs['video']
image, _, audio, video_info = load_video(**kwargs, generator=ffmpeg_frame_generator)
if isinstance(image, dict):
return (image, None, audio, video_info)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3], audio, video_info)
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"), audio, video_info)
@classmethod
def IS_CHANGED(s, video, **kwargs):
return hash_path(video)
@classmethod
def VALIDATE_INPUTS(s, video):
return validate_path(video, allow_none=True)
class LoadImagePath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("STRING", {"placeholder": "X://insert/path/here.png", "vhs_path_extensions": list(FolderOfImages.IMG_EXTENSIONS)}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, "step": 8, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, "step": 8, 'disable': 0}),
},
"optional": {
"vae": ("VAE",),
},
"hidden": {
"force_size": "STRING",
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK")
RETURN_NAMES = ("IMAGE", "mask")
FUNCTION = "load_image"
def load_image(self, **kwargs):
if kwargs['image'] is None or validate_path(kwargs['image']) != True:
raise Exception("image is not a valid path: " + kwargs['image'])
kwargs.update({'video': kwargs['image'], 'force_rate': 0, 'frame_load_cap': 0,
'start_time': 0})
kwargs.pop('image')
image, _, _, _ = load_video(**kwargs, generator=ffmpeg_frame_generator)
if isinstance(image, dict):
return (image, None)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3])
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"))
@classmethod
def IS_CHANGED(s, image, **kwargs):
return hash_path(image)
@classmethod
def VALIDATE_INPUTS(s, image):
return validate_path(image, allow_none=True)
@@ -0,0 +1,36 @@
import sys
import copy
import logging
class ColoredFormatter(logging.Formatter):
COLORS = {
"DEBUG": "\033[0;36m", # CYAN
"INFO": "\033[0;32m", # GREEN
"WARNING": "\033[0;33m", # YELLOW
"ERROR": "\033[0;31m", # RED
"CRITICAL": "\033[0;37;41m", # WHITE ON RED
"RESET": "\033[0m", # RESET COLOR
}
def format(self, record):
colored_record = copy.copy(record)
levelname = colored_record.levelname
seq = self.COLORS.get(levelname, self.COLORS["RESET"])
colored_record.levelname = f"{seq}{levelname}{self.COLORS['RESET']}"
return super().format(colored_record)
# Create a new logger
logger = logging.getLogger("VideoHelperSuite")
logger.propagate = False
# Add handler if we don't have one.
if not logger.handlers:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(ColoredFormatter("[%(name)s] - %(levelname)s - %(message)s"))
logger.addHandler(handler)
# Configure logger
loglevel = logging.INFO
logger.setLevel(loglevel)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,294 @@
import server
import folder_paths
import os
import subprocess
import re
import asyncio
import av
from .utils import is_url, get_sorted_dir_files_from_directory, ffmpeg_path, \
validate_sequence, is_safe_path, strip_path, try_download_video, ENCODE_ARGS
from comfy.k_diffusion.utils import FolderOfImages
web = server.web
@server.PromptServer.instance.routes.get("/vhs/viewvideo")
@server.PromptServer.instance.routes.get("/viewvideo")
async def view_video(request):
query = request.rel_url.query
path_res = await resolve_path(query)
if isinstance(path_res, web.Response):
return path_res
file, filename, output_dir = path_res
if ffmpeg_path is None:
#Don't just return file, that provides arbitrary read access to any file
if is_safe_path(output_dir, strict=True):
return web.FileResponse(path=file)
frame_rate = query.get('frame_rate', 8)
if query.get('format', 'video') == "folder":
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
concat_file = os.path.join(folder_paths.get_temp_directory(), "image_sequence_preview.txt")
skip_first_images = int(query.get('skip_first_images', 0))
select_every_nth = int(query.get('select_every_nth', 1)) or 1
valid_images = get_sorted_dir_files_from_directory(file, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if len(valid_images) == 0:
return web.Response(status=204)
with open(concat_file, "w") as f:
f.write("ffconcat version 1.0\n")
for path in valid_images:
f.write("file '" + os.path.abspath(path) + "'\n")
f.write("duration 0.125\n")
in_args = ["-safe", "0", "-i", concat_file]
else:
in_args = ["-i", file]
if '%' in file:
in_args = ['-framerate', str(frame_rate)] + in_args
#Do prepass to pull info
#breaks skip_first frames if this default is ever actually needed
base_fps = 30
try:
proc = await asyncio.create_subprocess_exec(ffmpeg_path, *in_args, '-t',
'0','-f', 'null','-', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
_, res_stderr = await proc.communicate()
match = re.search(': Video: (\\w+) .+, (\\d+) fps,', res_stderr.decode(*ENCODE_ARGS))
if match:
base_fps = float(match.group(2))
if match.group(1) == 'vp9':
#force libvpx for transparency
in_args = ['-c:v', 'libvpx-vp9'] + in_args
except subprocess.CalledProcessError as e:
print("An error occurred in the ffmpeg prepass:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
return web.Response(status=500)
vfilters = []
target_rate = float(query.get('force_rate', 0)) or base_fps
modified_rate = target_rate / (float(query.get('select_every_nth',1)) or 1)
start_time = 0
if 'start_time' in query:
start_time = float(query['start_time'])
elif float(query.get('skip_first_frames', 0)) > 0:
start_time = float(query.get('skip_first_frames'))/target_rate
if start_time > 1/modified_rate:
start_time += 1/modified_rate
if start_time > 0:
if start_time > 4:
post_seek = ['-ss', '4']
pre_seek = ['-ss', str(start_time - 4)]
else:
post_seek = ['-ss', str(start_time)]
pre_seek = []
else:
pre_seek = []
post_seek = []
args = [ffmpeg_path, "-v", "error"] + pre_seek + in_args + post_seek
if target_rate != 0:
args += ['-r', str(modified_rate)]
if query.get('force_size','Disabled') != "Disabled":
size = query['force_size'].split('x')
if size[0] == '?' or size[1] == '?':
size[0] = "-2" if size[0] == '?' else f"'min({size[0]},iw)'"
size[1] = "-2" if size[1] == '?' else f"'min({size[1]},ih)'"
else:
#Aspect ratio is likely changed. A more complex command is required
#to crop the output to the new aspect ratio
ar = float(size[0])/float(size[1])
vfilters.append(f"crop=if(gt({ar}\\,a)\\,iw\\,ih*{ar}):if(gt({ar}\\,a)\\,iw/{ar}\\,ih)")
size = ':'.join(size)
vfilters.append(f"scale={size}")
if len(vfilters) > 0:
args += ["-vf", ",".join(vfilters)]
if float(query.get('frame_load_cap', 0)) > 0:
args += ["-frames:v", query['frame_load_cap'].split('.')[0]]
#TODO:reconsider adding high frame cap/setting default frame cap on node
if query.get('deadline', 'realtime') == 'good':
deadline = 'good'
else:
deadline = 'realtime'
args += ['-c:v', 'libvpx-vp9','-deadline', deadline, '-cpu-used', '8', '-f', 'webm', '-']
try:
proc = await asyncio.create_subprocess_exec(*args, stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL)
try:
resp = web.StreamResponse()
resp.content_type = 'video/webm'
resp.headers["Content-Disposition"] = f"filename=\"{filename}\""
await resp.prepare(request)
while len(bytes_read := await proc.stdout.read(2**20)) != 0:
await resp.write(bytes_read)
#Of dubious value given frequency of kill calls, but more correct
await proc.wait()
except (ConnectionResetError, ConnectionError) as e:
proc.kill()
except BrokenPipeError as e:
pass
return resp
@server.PromptServer.instance.routes.get("/vhs/viewaudio")
async def view_audio(request):
query = request.rel_url.query
path_res = await resolve_path(query)
if isinstance(path_res, web.Response):
return path_res
file, filename, output_dir = path_res
if ffmpeg_path is None:
#Don't just return file, that provides arbitrary read access to any file
if is_safe_path(output_dir, strict=True):
return web.FileResponse(path=file)
in_args = ["-i", file]
start_time = 0
if 'start_time' in query:
start_time = float(query['start_time'])
args = [ffmpeg_path, "-v", "error", '-vn'] + in_args + ['-ss', str(start_time)]
if float(query.get('duration', 0)) > 0:
args += ['-t', str(query['duration'])]
if query.get('deadline', 'realtime') == 'good':
deadline = 'good'
else:
deadline = 'realtime'
args += ['-c:a', 'libopus','-deadline', deadline, '-cpu-used', '8', '-f', 'webm', '-']
try:
proc = await asyncio.create_subprocess_exec(*args, stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL)
try:
resp = web.StreamResponse()
resp.content_type = 'audio/webm'
resp.headers["Content-Disposition"] = f"filename=\"{filename}\""
await resp.prepare(request)
while len(bytes_read := await proc.stdout.read(2**20)) != 0:
await resp.write(bytes_read)
#Of dubious value given frequency of kill calls, but more correct
await proc.wait()
except (ConnectionResetError, ConnectionError) as e:
proc.kill()
except BrokenPipeError as e:
pass
return resp
query_cache = {}
@server.PromptServer.instance.routes.get("/vhs/queryvideo")
async def query_video(request):
query = request.rel_url.query
filepath = await resolve_path(query)
#TODO: cache lookup
if isinstance(filepath, web.Response):
return filepath
filepath = filepath[0]
if filepath.endswith(".webp"):
# ffmpeg doesn't support decoding animated WebP https://trac.ffmpeg.org/ticket/4907
return web.json_response({})
if filepath in query_cache and query_cache[filepath][0] == os.stat(filepath).st_mtime:
source = query_cache[filepath][1]
else:
source = {}
try:
with av.open(filepath) as cont:
stream = cont.streams.video[0]
source['fps'] = float(stream.average_rate)
source['duration'] = float(cont.duration / av.time_base)
if stream.codec_context.name == 'vp9':
cc = av.Codec('libvpx-vp9', 'r').create()
else:
cc = stream
def fit():
for packet in cont.demux(video=0):
yield from cc.decode(packet)
frame = next(fit())
source['size'] = [frame.width, frame.height]
source['alpha'] = 'a' in frame.format.name
source['frames'] = stream.metadata.get('NUMBER_OF_FRAMES', round(source['duration'] * source['fps']))
query_cache[filepath] = (os.stat(filepath).st_mtime, source)
except Exception:
pass
if not 'frames' in source:
return web.json_response({})
loaded = {}
loaded['duration'] = source['duration']
loaded['duration'] -= float(query.get('start_time',0))
loaded['fps'] = float(query.get('force_rate', 0)) or source.get('fps',1)
loaded['duration'] -= int(query.get('skip_first_frames', 0)) / loaded['fps']
loaded['fps'] /= int(query.get('select_every_nth', 1)) or 1
loaded['frames'] = round(loaded['duration'] * loaded['fps'])
return web.json_response({'source': source, 'loaded': loaded})
async def resolve_path(query):
if "filename" not in query:
return web.Response(status=204)
filename = query["filename"]
#Path code misformats urls on windows and must be skipped
if is_url(filename):
file = await asyncio.to_thread(try_download_video, filename) or file
filname, output_dir = os.path.split(file)
return file, filename, output_dir
else:
filename, output_dir = folder_paths.annotated_filepath(filename)
type = query.get("type", "output")
if type == "path":
#special case for path_based nodes
#NOTE: output_dir may be empty, but non-None
output_dir, filename = os.path.split(strip_path(filename))
if output_dir is None:
output_dir = folder_paths.get_directory_by_type(type)
if output_dir is None:
return web.Response(status=204)
if not is_safe_path(output_dir):
return web.Response(status=204)
if "subfolder" in query:
output_dir = os.path.join(output_dir, query["subfolder"])
filename = os.path.basename(filename)
file = os.path.join(output_dir, filename)
if not os.path.exists(file):
return web.Response(status=204)
if query.get('format', 'video') == 'folder':
if not os.path.isdir(file):
return web.Response(status=204)
else:
if not os.path.isfile(file) and not validate_sequence(file):
return web.Response(status=204)
return file, filename, output_dir
@server.PromptServer.instance.routes.get("/vhs/getpath")
@server.PromptServer.instance.routes.get("/getpath")
async def get_path(request):
query = request.rel_url.query
if "path" not in query:
return web.Response(status=204)
#NOTE: path always ends in `/`, so this is functionally an lstrip
path = os.path.abspath(strip_path(query["path"]))
if not os.path.exists(path) or not is_safe_path(path):
return web.json_response([])
#Use get so None is default instead of keyerror
valid_extensions = query.get("extensions")
valid_items = []
for item in os.scandir(path):
try:
if item.is_dir():
valid_items.append(item.name + "/")
continue
if valid_extensions is None or item.name.split(".")[-1].lower() in valid_extensions:
valid_items.append(item.name)
except OSError:
#Broken symlinks can throw a very unhelpful "Invalid argument"
pass
valid_items.sort(key=lambda f: os.stat(os.path.join(path,f)).st_mtime)
return web.json_response(valid_items)
@@ -0,0 +1,443 @@
import hashlib
import os
from typing import Iterable
import shutil
import subprocess
import re
import time
from collections.abc import Mapping
from typing import Union
import functools
import torch
from torch import Tensor
import server
from .logger import logger
import folder_paths
BIGMIN = -(2**53-1)
BIGMAX = (2**53-1)
DIMMAX = 8192
ENCODE_ARGS = ("utf-8", 'backslashreplace')
def ffmpeg_suitability(path):
try:
version = subprocess.run([path, "-version"], check=True,
capture_output=True).stdout.decode(*ENCODE_ARGS)
except:
return 0
score = 0
#rough layout of the importance of various features
simple_criterion = [("libvpx", 20),("264",10), ("265",3),
("svtav1",5),("libopus", 1)]
for criterion in simple_criterion:
if version.find(criterion[0]) >= 0:
score += criterion[1]
#obtain rough compile year from copyright information
copyright_index = version.find('2000-2')
if copyright_index >= 0:
copyright_year = version[copyright_index+6:copyright_index+9]
if copyright_year.isnumeric():
score += int(copyright_year)
return score
class MultiInput(str):
def __new__(cls, string, allowed_types="*"):
res = super().__new__(cls, string)
res.allowed_types=allowed_types
return res
def __ne__(self, other):
if self.allowed_types == "*" or other == "*":
return False
return other not in self.allowed_types
imageOrLatent = MultiInput("IMAGE", ["IMAGE", "LATENT"])
floatOrInt = MultiInput("FLOAT", ["FLOAT", "INT"])
class ContainsAll(dict):
def __contains__(self, other):
return True
def __getitem__(self, key):
return super().get(key, (None, {}))
if "VHS_FORCE_FFMPEG_PATH" in os.environ:
ffmpeg_path = os.environ.get("VHS_FORCE_FFMPEG_PATH")
else:
ffmpeg_paths = []
try:
from imageio_ffmpeg import get_ffmpeg_exe
imageio_ffmpeg_path = get_ffmpeg_exe()
ffmpeg_paths.append(imageio_ffmpeg_path)
except:
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
raise
logger.warn("Failed to import imageio_ffmpeg")
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
ffmpeg_path = imageio_ffmpeg_path
else:
system_ffmpeg = shutil.which("ffmpeg")
if system_ffmpeg is not None:
ffmpeg_paths.append(system_ffmpeg)
if os.path.isfile("ffmpeg"):
ffmpeg_paths.append(os.path.abspath("ffmpeg"))
if os.path.isfile("ffmpeg.exe"):
ffmpeg_paths.append(os.path.abspath("ffmpeg.exe"))
if len(ffmpeg_paths) == 0:
logger.error("No valid ffmpeg found.")
ffmpeg_path = None
elif len(ffmpeg_paths) == 1:
#Evaluation of suitability isn't required, can take sole option
#to reduce startup time
ffmpeg_path = ffmpeg_paths[0]
else:
ffmpeg_path = max(ffmpeg_paths, key=ffmpeg_suitability)
gifski_path = os.environ.get("VHS_GIFSKI", None)
if gifski_path is None:
gifski_path = os.environ.get("JOV_GIFSKI", None)
if gifski_path is None:
gifski_path = shutil.which("gifski")
ytdl_path = os.environ.get("VHS_YTDL", None) or shutil.which('yt-dlp') \
or shutil.which('youtube-dl')
download_history = {}
def try_download_video(url):
if ytdl_path is None:
return None
if url in download_history:
return download_history[url]
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
#Format information could be added to only download audio for Load Audio,
#but this gets hairy if same url is also used for video.
#Best to just always keep defaults
#dl_format = ['-f', 'ba'] if is_audio else []
try:
res = subprocess.run([ytdl_path, "--print", "after_move:filepath",
"-P", folder_paths.get_temp_directory(), url],
capture_output=True, check=True)
#strip newline
file = res.stdout.decode(*ENCODE_ARGS)[:-1]
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the yt-dl process:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
file = None
download_history[url] = file
return file
def is_safe_path(path, strict=False):
if "VHS_STRICT_PATHS" not in os.environ and not strict:
return True
basedir = os.path.abspath('.')
try:
common_path = os.path.commonpath([basedir, path])
except:
#Different drive on windows
return False
return common_path == basedir
def get_sorted_dir_files_from_directory(directory: str, skip_first_images: int=0, select_every_nth: int=1, extensions: Iterable=None):
directory = strip_path(directory)
dir_files = os.listdir(directory)
dir_files = sorted(dir_files)
dir_files = [os.path.join(directory, x) for x in dir_files]
dir_files = list(filter(lambda filepath: os.path.isfile(filepath), dir_files))
# filter by extension, if needed
if extensions is not None:
extensions = list(extensions)
new_dir_files = []
for filepath in dir_files:
ext = "." + filepath.split(".")[-1]
if ext.lower() in extensions:
new_dir_files.append(filepath)
dir_files = new_dir_files
# start at skip_first_images
dir_files = dir_files[skip_first_images:]
dir_files = dir_files[0::select_every_nth]
return dir_files
# modified from https://stackoverflow.com/questions/22058048/hashing-a-file-in-python
def calculate_file_hash(filename: str, hash_every_n: int = 1):
#Larger video files were taking >.5 seconds to hash even when cached,
#so instead the modified time from the filesystem is used as a hash
h = hashlib.sha256()
h.update(filename.encode())
h.update(str(os.path.getmtime(filename)).encode())
return h.hexdigest()
prompt_queue = server.PromptServer.instance.prompt_queue
def requeue_workflow_unchecked():
"""Requeues the current workflow without checking for multiple requeues"""
currently_running = prompt_queue.currently_running
value = next(iter(currently_running.values()))
# Handle both old (5 values) and new (6 values) ComfyUI versions
if len(value) == 6:
(_, prompt_id, prompt, extra_data, outputs_to_execute, _) = value
else:
(_, prompt_id, prompt, extra_data, outputs_to_execute) = value
#Ensure batch_managers are marked stale
prompt = prompt.copy()
for uid in prompt:
if prompt[uid]['class_type'] == 'VHS_BatchManager':
prompt[uid]['inputs']['requeue'] = prompt[uid]['inputs'].get('requeue',0)+1
#execution.py has guards for concurrency, but server doesn't.
#TODO: Check that this won't be an issue
number = -server.PromptServer.instance.number
server.PromptServer.instance.number += 1
prompt_id = str(server.uuid.uuid4())
# Put back with 6 elements to match what ComfyUI expects
sensitive = value[5] if len(value) > 5 else {}
prompt_queue.put((number, prompt_id, prompt, extra_data, outputs_to_execute, sensitive))
requeue_guard = [None, 0, 0, {}]
def requeue_workflow(requeue_required=(-1,True)):
assert(len(prompt_queue.currently_running) == 1)
global requeue_guard
value = next(iter(prompt_queue.currently_running.values()))
# Handle both old (5 values) and new (6 values) ComfyUI versions
if len(value) == 6:
(run_number, _, prompt, extra_data, outputs_to_execute, _) = value
else:
(run_number, _, prompt, extra_data, outputs_to_execute) = value
if requeue_guard[0] != run_number:
#Calculate a count of how many outputs are managed by a batch manager
managed_outputs=0
for bm_uid in prompt:
if prompt[bm_uid]['class_type'] == 'VHS_BatchManager':
for output_uid in prompt:
if prompt[output_uid]['class_type'] in ["VHS_VideoCombine"]:
for inp in prompt[output_uid]['inputs'].values():
if inp == [bm_uid, 0]:
managed_outputs+=1
requeue_guard = [run_number, 0, managed_outputs, {}]
requeue_guard[1] = requeue_guard[1]+1
requeue_guard[3][requeue_required[0]] = requeue_required[1]
if requeue_guard[1] == requeue_guard[2] and max(requeue_guard[3].values()):
requeue_workflow_unchecked()
def get_audio(file, start_time=0, duration=0):
args = [ffmpeg_path, "-i", file]
if start_time > 0:
args += ["-ss", str(start_time)]
if duration > 0:
args += ["-t", str(duration)]
try:
#TODO: scan for sample rate and maintain
res = subprocess.run(args + ["-f", "f32le", "-"],
capture_output=True, check=True)
audio = torch.frombuffer(bytearray(res.stdout), dtype=torch.float32)
match = re.search(', (\\d+) Hz, (\\w+), ',res.stderr.decode(*ENCODE_ARGS))
except subprocess.CalledProcessError as e:
raise Exception(f"VHS failed to extract audio from {file}:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
if match:
ar = int(match.group(1))
#NOTE: Just throwing an error for other channel types right now
#Will deal with issues if they come
ac = {"mono": 1, "stereo": 2}[match.group(2)]
else:
ar = 44100
ac = 2
audio = audio.reshape((-1,ac)).transpose(0,1).unsqueeze(0)
return {'waveform': audio, 'sample_rate': ar}
class LazyAudioMap(Mapping):
def __init__(self, file, start_time, duration):
self.file = file
self.start_time=start_time
self.duration=duration
self._dict=None
def __getitem__(self, key):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return self._dict[key]
def __iter__(self):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return iter(self._dict)
def __len__(self):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return len(self._dict)
def lazy_get_audio(file, start_time=0, duration=0, **kwargs):
return LazyAudioMap(file, start_time, duration)
def is_url(url):
return url.split("://")[0] in ["http", "https"]
def validate_sequence(path):
#Check if path is a valid ffmpeg sequence that points to at least one file
(path, file) = os.path.split(path)
if not os.path.isdir(path):
return False
match = re.search('%0?\\d+d', file)
if not match:
return False
seq = match.group()
if seq == '%d':
seq = '\\\\d+'
else:
seq = '\\\\d{%s}' % seq[1:-1]
file_matcher = re.compile(re.sub('%0?\\d+d', seq, file))
for file in os.listdir(path):
if file_matcher.fullmatch(file):
return True
return False
def strip_path(path):
#This leaves whitespace inside quotes and only a single "
#thus ' ""test"' -> '"test'
#consider path.strip(string.whitespace+"\"")
#or weightier re.fullmatch("[\\s\"]*(.+?)[\\s\"]*", path).group(1)
path = path.strip()
if path.startswith("\""):
path = path[1:]
if path.endswith("\""):
path = path[:-1]
return path
def hash_path(path):
if path is None:
return "input"
if is_url(path):
return "url"
if not os.path.isfile(path):
return "DNE"
return calculate_file_hash(strip_path(path))
def validate_path(path, allow_none=False, allow_url=True):
if path is None:
return allow_none
if is_url(path):
#Probably not feasible to check if url resolves here
if not allow_url:
return "URLs are unsupported for this path"
return is_safe_path(path)
if not os.path.isfile(strip_path(path)):
return "Invalid file path: {}".format(path)
return is_safe_path(path)
def validate_index(index: int, length: int=0, is_range: bool=False, allow_negative=False, allow_missing=False) -> int:
# if part of range, do nothing
if is_range:
return index
# otherwise, validate index
# validate not out of range - only when latent_count is passed in
if length > 0 and index > length-1 and not allow_missing:
raise IndexError(f"Index '{index}' out of range for {length} item(s).")
# if negative, validate not out of range
if index < 0:
if not allow_negative:
raise IndexError(f"Negative indeces not allowed, but was '{index}'.")
conv_index = length+index
if conv_index < 0 and not allow_missing:
raise IndexError(f"Index '{index}', converted to '{conv_index}' out of range for {length} item(s).")
index = conv_index
return index
def convert_to_index_int(raw_index: str, length: int=0, is_range: bool=False, allow_negative=False, allow_missing=False) -> int:
try:
return validate_index(int(raw_index), length=length, is_range=is_range, allow_negative=allow_negative, allow_missing=allow_missing)
except ValueError as e:
raise ValueError(f"Index '{raw_index}' must be an integer.", e)
def convert_str_to_indexes(indexes_str: str, length: int=0, allow_missing=False) -> list[int]:
if not indexes_str:
return []
int_indexes = list(range(0, length))
allow_negative = length > 0
chosen_indexes = []
# parse string - allow positive ints, negative ints, and ranges separated by ':'
groups = indexes_str.split(",")
groups = [g.strip() for g in groups]
for g in groups:
# parse range of indeces (e.g. 2:16)
if ':' in g:
index_range = g.split(":", 2)
index_range = [r.strip() for r in index_range]
start_index = index_range[0]
if len(start_index) > 0:
start_index = convert_to_index_int(start_index, length=length, is_range=True, allow_negative=allow_negative, allow_missing=allow_missing)
else:
start_index = 0
end_index = index_range[1]
if len(end_index) > 0:
end_index = convert_to_index_int(end_index, length=length, is_range=True, allow_negative=allow_negative, allow_missing=allow_missing)
else:
end_index = length
# support step as well, to allow things like reversing, every-other, etc.
step = 1
if len(index_range) > 2:
step = index_range[2]
if len(step) > 0:
step = convert_to_index_int(step, length=length, is_range=True, allow_negative=True, allow_missing=True)
else:
step = 1
# if latents were passed in, base indeces on known latent count
if len(int_indexes) > 0:
chosen_indexes.extend(int_indexes[start_index:end_index][::step])
# otherwise, assume indeces are valid
else:
chosen_indexes.extend(list(range(start_index, end_index, step)))
# parse individual indeces
else:
chosen_indexes.append(convert_to_index_int(g, length=length, allow_negative=allow_negative, allow_missing=allow_missing))
return chosen_indexes
def select_indexes(input_obj: Union[Tensor, list], idxs: list):
if type(input_obj) == Tensor:
return input_obj[idxs]
else:
return [input_obj[i] for i in idxs]
def merge_filter_args(args, ftype="-vf"):
#TODO This doesn't account for filter_complex
#Will likely need to convert all filters to filter complex in the future
#But that requires source/output deduplication
try:
start_index = args.index(ftype)+1
index = start_index
while True:
index = args.index(ftype, index)
args[start_index] += ',' + args[index+1]
args.pop(index)
args.pop(index)
except ValueError:
pass
def select_indexes_from_str(input_obj: Union[Tensor, list], indexes: str, err_if_missing=True, err_if_empty=True):
real_idxs = convert_str_to_indexes(indexes, len(input_obj), allow_missing=not err_if_missing)
if err_if_empty and len(real_idxs) == 0:
raise Exception(f"Nothing was selected based on indexes found in '{indexes}'.")
return select_indexes(input_obj, real_idxs)
def hook(obj, attr):
def dec(f):
f = functools.update_wrapper(f, getattr(obj,attr))
setattr(obj,attr,f)
return f
return dec
def cached(duration):
def dec(f):
cached_ret = None
cache_time = 0
def cached_func():
nonlocal cache_time, cached_ret
if time.time() > cache_time + duration or cached_ret is None:
cache_time = time.time()
cached_ret = f()
return cached_ret
return cached_func
return dec
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,101 @@
import { app } from '../../../scripts/app.js'
function getVideoMetadata(file) {
return new Promise((r) => {
const reader = new FileReader();
reader.onload = (event) => {
const videoData = new Uint8Array(event.target.result);
const dataView = new DataView(videoData.buffer);
let decoder = new TextDecoder();
// Check for known valid magic strings
if (dataView.getUint32(0) == 0x1A45DFA3) {
//webm/mkv (both use EBML/Matroska format)
//see http://wiki.webmproject.org/webm-metadata/global-metadata
//and https://www.matroska.org/technical/elements.html
//contrary to specs, tag seems consistently at start
//COMMENT + 0x4487 + packed length?
//length 0x8d8 becomes 0x48d8
//
//description for variable length ints https://github.com/ietf-wg-cellar/ebml-specification/blob/master/specification.markdown
let offset = 4 + 8; //COMMENT is 7 chars + 1 to realign
while(offset < videoData.length-16) {
//Check for text tags
if (dataView.getUint16(offset) == 0x4487) {
//check that name of tag is COMMENT
const name = String.fromCharCode(...videoData.slice(offset-7,offset));
if (name === "COMMENT") {
let vint = dataView.getUint32(offset+2);
let n_octets = Math.clz32(vint)+1;
if (n_octets < 4) {//250MB sanity cutoff
let length = (vint >> (8*(4-n_octets))) & ~(1 << (7*n_octets));
const content = decoder.decode(videoData.slice(offset+2+n_octets, offset+2+n_octets+length));
let json = JSON.parse(content);
r(json);
return;
}
}
}
offset+=1;
}
} else if (dataView.getUint32(4) == 0x66747970 && dataView.getUint32(8) == 0x69736F6D) {
//mp4
//see https://developer.apple.com/documentation/quicktime-file-format
//Seems to make no guarantee for alignment
let offset = videoData.length-4;
while (offset > 16) {//rough safe guess
if (dataView.getUint32(offset) == 0x64617461) {//any data tag
if (dataView.getUint32(offset - 8) == 0xa9636d74) {//cmt data tag
let type = dataView.getUint32(offset+4); //seemingly 1
let locale = dataView.getUint32(offset+8); //seemingly 0
let size = dataView.getUint32(offset-4) - 4*4;
const content = decoder.decode(videoData.slice(offset+12, offset+12+size));
const json = JSON.parse(content);
r(json);
return;
}
}
offset-=1;
}
} else {
console.error("Unknown magic: " + dataView.getUint32(0))
}
r();
return;
};
reader.readAsArrayBuffer(file);
});
}
function isVideoFile(file) {
if (file?.name?.endsWith(".webm")) {
return true;
}
if (file?.name?.endsWith(".mp4")) {
return true;
}
if (file?.name?.endsWith(".mkv")) {
return true;
}
return false;
}
let originalHandleFile = app.handleFile;
app.handleFile = handleFile;
let fileInput = document.getElementById("comfy-file-input")
//hijack comfy-file-input to allow webm/mp4/mkv
fileInput.accept += ",video/webm,video/mp4,video/x-matroska";
async function handleFile(file) {
if (file?.type?.startsWith("video/") || isVideoFile(file)) {
const videoInfo = await getVideoMetadata(file);
if (videoInfo?.workflow) {
await app.loadGraphData(videoInfo.workflow);
return
}
}
return await originalHandleFile.apply(this, arguments);
}
@@ -0,0 +1,437 @@
{
"sha": "8550981384301e9bc5bfea83e5c2c75258102593",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/8550981384301e9bc5bfea83e5c2c75258102593",
"tree": [
{
"path": ".github",
"mode": "040000",
"type": "tree",
"sha": "7a7002793ebbe7911dded77df496f4b141a46661",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/7a7002793ebbe7911dded77df496f4b141a46661"
},
{
"path": ".github/workflows",
"mode": "040000",
"type": "tree",
"sha": "a0920d307e4ff5f6199f39cf7cd22e853ed9c139",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/a0920d307e4ff5f6199f39cf7cd22e853ed9c139"
},
{
"path": ".github/workflows/publish.yml",
"mode": "100644",
"type": "blob",
"sha": "27bcdb11695ea19286da34cd5f36cf75155a4dbb",
"size": 640,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/27bcdb11695ea19286da34cd5f36cf75155a4dbb"
},
{
"path": ".gitignore",
"mode": "100644",
"type": "blob",
"sha": "9b5379e8f93da3909706b0a7d37f5c8ab5e2a2a5",
"size": 3101,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/9b5379e8f93da3909706b0a7d37f5c8ab5e2a2a5"
},
{
"path": "LICENSE",
"mode": "100644",
"type": "blob",
"sha": "f288702d2fa16d3cdf0035b15a9fcbc552cd88e7",
"size": 35149,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f288702d2fa16d3cdf0035b15a9fcbc552cd88e7"
},
{
"path": "README.md",
"mode": "100644",
"type": "blob",
"sha": "753fcecf9979b40b2427869c6ad5bed1b61df482",
"size": 8877,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/753fcecf9979b40b2427869c6ad5bed1b61df482"
},
{
"path": "__init__.py",
"mode": "100755",
"type": "blob",
"sha": "9fa995f0ac7e296a62bcba9df68b5250a0f7d041",
"size": 398,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/9fa995f0ac7e296a62bcba9df68b5250a0f7d041"
},
{
"path": "pyproject.toml",
"mode": "100644",
"type": "blob",
"sha": "110947257835ebab06e933d8ad6faf0016d20f62",
"size": 425,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/110947257835ebab06e933d8ad6faf0016d20f62"
},
{
"path": "requirements.txt",
"mode": "100644",
"type": "blob",
"sha": "4fa34aa21b85c4b974e2a2b6891eae5fd6dd4164",
"size": 29,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4fa34aa21b85c4b974e2a2b6891eae5fd6dd4164"
},
{
"path": "testframework",
"mode": "040000",
"type": "tree",
"sha": "cb29518c671c9b91a4c2799b026d19260d5dfc33",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/cb29518c671c9b91a4c2799b026d19260d5dfc33"
},
{
"path": "testframework/README.md",
"mode": "100644",
"type": "blob",
"sha": "93cd503563080c9c7d785d419bef7dddc4c11cd8",
"size": 466,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/93cd503563080c9c7d785d419bef7dddc4c11cd8"
},
{
"path": "testframework/__init__.py",
"mode": "100755",
"type": "blob",
"sha": "c75b11c164596ef873898dd843700c7164cc0932",
"size": 184,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/c75b11c164596ef873898dd843700c7164cc0932"
},
{
"path": "testframework/server.py",
"mode": "100644",
"type": "blob",
"sha": "a9c20ea3eab31bab288d6089a89410ff409d43ad",
"size": 2836,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/a9c20ea3eab31bab288d6089a89410ff409d43ad"
},
{
"path": "testframework/web",
"mode": "040000",
"type": "tree",
"sha": "5beb5445842a7c69a29942eadbd100ec0458556f",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/5beb5445842a7c69a29942eadbd100ec0458556f"
},
{
"path": "testframework/web/js",
"mode": "040000",
"type": "tree",
"sha": "a351c437f1cccb93448fb0140d8e0fc17ffab368",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/a351c437f1cccb93448fb0140d8e0fc17ffab368"
},
{
"path": "testframework/web/js/testRunner.js",
"mode": "100644",
"type": "blob",
"sha": "521a2204b9a2a3202441818461231872ea8a15c8",
"size": 3132,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/521a2204b9a2a3202441818461231872ea8a15c8"
},
{
"path": "tests",
"mode": "040000",
"type": "tree",
"sha": "6341d1c56315d281322b2d4dd4a9abd4ef3cb345",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/6341d1c56315d281322b2d4dd4a9abd4ef3cb345"
},
{
"path": "tests/README.md",
"mode": "100644",
"type": "blob",
"sha": "ec025a7d169c7783f34523c63a0a6ae9a2e00fdb",
"size": 140,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/ec025a7d169c7783f34523c63a0a6ae9a2e00fdb"
},
{
"path": "tests/audio.json",
"mode": "100644",
"type": "blob",
"sha": "cae3d766731f7fe3ae4866f6fa8c0cc86a2ca46d",
"size": 6092,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/cae3d766731f7fe3ae4866f6fa8c0cc86a2ca46d"
},
{
"path": "tests/batch4x4.json",
"mode": "100644",
"type": "blob",
"sha": "34b9647329642a9e5ca233a60b8bbf2ca8f72aca",
"size": 10236,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/34b9647329642a9e5ca233a60b8bbf2ca8f72aca"
},
{
"path": "tests/converted-format-input.json",
"mode": "100644",
"type": "blob",
"sha": "e9722580df540b89a4b9185260a8de180ddd63aa",
"size": 4514,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/e9722580df540b89a4b9185260a8de180ddd63aa"
},
{
"path": "tests/converted-input.json",
"mode": "100644",
"type": "blob",
"sha": "41a93a049ea95ea9ddda92ed3a5152b55581938f",
"size": 5917,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/41a93a049ea95ea9ddda92ed3a5152b55581938f"
},
{
"path": "tests/loop.json",
"mode": "100644",
"type": "blob",
"sha": "aa5dd4ecdaac29d04b71dbf3bbc8349f2d1210af",
"size": 3643,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/aa5dd4ecdaac29d04b71dbf3bbc8349f2d1210af"
},
{
"path": "tests/old-prores.json",
"mode": "100644",
"type": "blob",
"sha": "17e77c1547663d39b5356ac15d74f807c69dc671",
"size": 8694,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/17e77c1547663d39b5356ac15d74f807c69dc671"
},
{
"path": "tests/old-vae-conversion.json",
"mode": "100644",
"type": "blob",
"sha": "e751918b6473cae2f38536d8433bc40b2283a3f6",
"size": 4430,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/e751918b6473cae2f38536d8433bc40b2283a3f6"
},
{
"path": "tests/simple.json",
"mode": "100644",
"type": "blob",
"sha": "4d7f8ddd68a24cc90519ecd127daae9d8ab81b85",
"size": 2820,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/4d7f8ddd68a24cc90519ecd127daae9d8ab81b85"
},
{
"path": "video_formats",
"mode": "040000",
"type": "tree",
"sha": "c57d50f7b1ccbfe75f8b8785e661c3d9abe163dc",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/c57d50f7b1ccbfe75f8b8785e661c3d9abe163dc"
},
{
"path": "video_formats/16bit-png.json",
"mode": "100644",
"type": "blob",
"sha": "b768bdbcfe8950cb7bde37d02444f0191ad29f51",
"size": 139,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b768bdbcfe8950cb7bde37d02444f0191ad29f51"
},
{
"path": "video_formats/8bit-png.json",
"mode": "100644",
"type": "blob",
"sha": "88b27a75f9c979f18979ec46da8c8843a82e0759",
"size": 75,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/88b27a75f9c979f18979ec46da8c8843a82e0759"
},
{
"path": "video_formats/ProRes.json",
"mode": "100644",
"type": "blob",
"sha": "eddd3acf931c5ab3486197c18ba88a3959d3e1d6",
"size": 943,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/eddd3acf931c5ab3486197c18ba88a3959d3e1d6"
},
{
"path": "video_formats/av1-webm.json",
"mode": "100644",
"type": "blob",
"sha": "659ea166fb140e18109f09f3d5710363af9c2294",
"size": 625,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/659ea166fb140e18109f09f3d5710363af9c2294"
},
{
"path": "video_formats/ffmpeg-gif.json",
"mode": "100644",
"type": "blob",
"sha": "3ca0865033c7dabc06176c737652f375e7badb27",
"size": 366,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/3ca0865033c7dabc06176c737652f375e7badb27"
},
{
"path": "video_formats/ffv1-mkv.json",
"mode": "100644",
"type": "blob",
"sha": "549e727febfd1c0d662a2fc67ad90106841ebdcb",
"size": 1072,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/549e727febfd1c0d662a2fc67ad90106841ebdcb"
},
{
"path": "video_formats/gifski.json",
"mode": "100644",
"type": "blob",
"sha": "c96b358ab0ae59dbd97c52a699c8ee9825c5d351",
"size": 287,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/c96b358ab0ae59dbd97c52a699c8ee9825c5d351"
},
{
"path": "video_formats/h264-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "89d290c92cd44674e2fe6dca8d0a240d6bf9695b",
"size": 585,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/89d290c92cd44674e2fe6dca8d0a240d6bf9695b"
},
{
"path": "video_formats/h265-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "b5d0150bf9cdb21f396f026a0d7721626c698822",
"size": 611,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b5d0150bf9cdb21f396f026a0d7721626c698822"
},
{
"path": "video_formats/nvenc_av1-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "0996c65b3f586897a2b131997ff1faaa6a4b828e",
"size": 572,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/0996c65b3f586897a2b131997ff1faaa6a4b828e"
},
{
"path": "video_formats/nvenc_h264-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "1c39913ab6419fb2f7b1c0a6241b7fea1cc2cb11",
"size": 573,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/1c39913ab6419fb2f7b1c0a6241b7fea1cc2cb11"
},
{
"path": "video_formats/nvenc_hevc-mp4.json",
"mode": "100644",
"type": "blob",
"sha": "2ec6f4169d02466287026e4989b930ec3b64c200",
"size": 598,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/2ec6f4169d02466287026e4989b930ec3b64c200"
},
{
"path": "video_formats/webm.json",
"mode": "100644",
"type": "blob",
"sha": "6323f619ad2850ba60cd5e31b32cdfc060e030c9",
"size": 589,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/6323f619ad2850ba60cd5e31b32cdfc060e030c9"
},
{
"path": "videohelpersuite",
"mode": "040000",
"type": "tree",
"sha": "56435df2d248e35e4a2122c0724782fa5dd654fd",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/56435df2d248e35e4a2122c0724782fa5dd654fd"
},
{
"path": "videohelpersuite/batched_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "624bb84f73cce1d8e51abf4fef0b80367ad4b9a3",
"size": 1790,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/624bb84f73cce1d8e51abf4fef0b80367ad4b9a3"
},
{
"path": "videohelpersuite/documentation.py",
"mode": "100644",
"type": "blob",
"sha": "857de6c6a5b4a3917f49d0b1c5c142f274203f22",
"size": 43805,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/857de6c6a5b4a3917f49d0b1c5c142f274203f22"
},
{
"path": "videohelpersuite/image_latent_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "62b4e3e6452b51b42e3e49852d27a1bb9921edc2",
"size": 19039,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/62b4e3e6452b51b42e3e49852d27a1bb9921edc2"
},
{
"path": "videohelpersuite/latent_preview.py",
"mode": "100644",
"type": "blob",
"sha": "d30a97bb2078f44ff28542192052b370d7c9e2a7",
"size": 5282,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/d30a97bb2078f44ff28542192052b370d7c9e2a7"
},
{
"path": "videohelpersuite/load_images_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "43f3387c4f907d7372c207f7f1aeb626c27b836b",
"size": 8120,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/43f3387c4f907d7372c207f7f1aeb626c27b836b"
},
{
"path": "videohelpersuite/load_video_nodes.py",
"mode": "100644",
"type": "blob",
"sha": "409e59a48fca2632dc65d961d5ff08c2c517e36e",
"size": 29027,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/409e59a48fca2632dc65d961d5ff08c2c517e36e"
},
{
"path": "videohelpersuite/logger.py",
"mode": "100755",
"type": "blob",
"sha": "6e7b8d64bda275608ba6bf8ee28d2a2112e3e2be",
"size": 1057,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/6e7b8d64bda275608ba6bf8ee28d2a2112e3e2be"
},
{
"path": "videohelpersuite/nodes.py",
"mode": "100755",
"type": "blob",
"sha": "f40461e7b9b9e01a4d4eb1453f95aef26be9be97",
"size": 47770,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f40461e7b9b9e01a4d4eb1453f95aef26be9be97"
},
{
"path": "videohelpersuite/server.py",
"mode": "100755",
"type": "blob",
"sha": "f67e342400eb250b731245554bbd495864719f8f",
"size": 12178,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/f67e342400eb250b731245554bbd495864719f8f"
},
{
"path": "videohelpersuite/utils.py",
"mode": "100644",
"type": "blob",
"sha": "75431d5a9e151ae50257d3fd14c03ffbc7570d39",
"size": 16463,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/75431d5a9e151ae50257d3fd14c03ffbc7570d39"
},
{
"path": "web",
"mode": "040000",
"type": "tree",
"sha": "27ac8383e4b41ca011381b3e5a41b2da195f6352",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/27ac8383e4b41ca011381b3e5a41b2da195f6352"
},
{
"path": "web/js",
"mode": "040000",
"type": "tree",
"sha": "9e189d9cfaa88ff04af1012bc850d2ba552a5fae",
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/trees/9e189d9cfaa88ff04af1012bc850d2ba552a5fae"
},
{
"path": "web/js/VHS.core.js",
"mode": "100755",
"type": "blob",
"sha": "adcce3ecdfc1a4b98a246a2b84a141ed1278f7f6",
"size": 105302,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/adcce3ecdfc1a4b98a246a2b84a141ed1278f7f6"
},
{
"path": "web/js/videoinfo.js",
"mode": "100644",
"type": "blob",
"sha": "b1a9871067e07dc09b37a8dd666ce531c2c5f56b",
"size": 4313,
"url": "https://api.github.com/repos/Kosinkadink/ComfyUI-VideoHelperSuite/git/blobs/b1a9871067e07dc09b37a8dd666ce531c2c5f56b"
}
],
"truncated": false
}
+674
View File
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -0,0 +1,9 @@
from .videohelpersuite.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
import folder_paths
from .videohelpersuite.server import server
from .videohelpersuite import documentation
from .videohelpersuite import latent_preview
WEB_DIRECTORY = "./web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
documentation.format_descriptions(NODE_CLASS_MAPPINGS)
@@ -0,0 +1,15 @@
[project]
name = "comfyui-videohelpersuite"
description = "Nodes related to video workflows"
version = "1.7.7"
license = { file = "LICENSE" }
dependencies = ["opencv-python", "imageio-ffmpeg"]
[project.urls]
Repository = "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"
# Used by Comfy Registry https://comfyregistry.org
[tool.comfy]
PublisherId = "kosinkadink"
DisplayName = "ComfyUI-VideoHelperSuite"
Icon = ""
@@ -0,0 +1,9 @@
{
"main_pass":
[
"-n",
"-pix_fmt", "rgba64"
],
"input_color_depth": "16bit",
"extension": "%03d.png"
}
@@ -0,0 +1,7 @@
{
"main_pass":
[
"-n"
],
"extension": "%03d.png"
}
@@ -0,0 +1,22 @@
{
"main_pass":
[
"-n", "-c:v", "prores_ks",
"-profile:v", [["$profile"]],
["profile", {
"lt": [[]], "1": [[]], "standard": [[]], "2": [[]], "hq": [[]], "3": [[]],
"4": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}],
"4444": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}],
"4444xq": ["has_alpha", {"True": [["-pix_fmt", "yuva444p10le"]],
"False": [["-pix_fmt", "yuv444p10le"]]}]
}],
"-vf", "scale=out_color_matrix=bt709",
"-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "pcm_s16le"],
"extension": "mov",
"extra_widgets": [["profile", ["lt", "standard", "hq", "4444", "4444xq"], {"default": "hq"}]]
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n", "-c:v", "libsvtav1",
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
"-crf", ["crf","INT", {"default": 23, "min": 0, "max": 100, "step": 1}],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "libopus"],
"input_color_depth": ["input_color_depth", ["8bit", "16bit"]],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "webm",
"environment": {"SVT_LOG": "1"}
}
@@ -0,0 +1,8 @@
{
"main_pass":
[
"-n",
"-filter_complex", ["dither", ["bayer", "heckbert", "floyd_steinberg", "sierra2", "sierra2_4a", "sierra3", "burkes", "atkinson", "none"], {"default": "sierra2_4a"}, "[0:v] split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse=dither=$val"]
],
"extension": "gif"
}
@@ -0,0 +1,17 @@
{
"main_pass": [
"-n",
"-c:v", "ffv1",
"-level", ["level", ["0", "1", "3"], {"default": "3"}],
"-coder", ["coder", ["0", "1", "2"], {"default": "1"}],
"-context", ["context", ["0", "1"], {"default": "1"}],
"-g", ["gop_size", "INT", {"default": 1, "min": 1, "max": 300, "step": 1}],
"-slices", ["slices", ["4", "6", "9", "12", "16", "20", "24", "30"], {"default": "16"}],
"-slicecrc", ["slicecrc", ["0", "1"], {"default": "1"}],
"-pix_fmt", ["pix_fmt", ["bgra", "rgba64le", "yuv420p", "yuv422p", "yuv444p", "yuva420p", "yuva422p", "yuva444p", "yuv420p10le", "yuv422p10le", "yuv444p10le", "yuv420p12le", "yuv422p12le", "yuv444p12le", "yuv420p14le", "yuv422p14le", "yuv444p14le", "yuv420p16le", "yuv422p16le", "yuv444p16le", "gray", "gray10le", "gray12le", "gray16le"], {"default": "bgra"}]
],
"audio_pass": ["-c:a", "flac"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"extension": "mkv"
}
@@ -0,0 +1,12 @@
{
"main_pass":
[
"-pix_fmt", "yuv444p",
"-vf", "scale=out_color_matrix=bt709:out_range=pc",
"-color_range", "pc"
],
"extension": "gif",
"gifski_pass": [
"-Q", ["quality","INT", {"default": 90, "min": 1, "max": 100, "step": 1}]
]
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "libx264",
"-pix_fmt", ["pix_fmt", ["yuv420p", "yuv420p10le"]],
"-crf", ["crf","INT", {"default": 19, "min": 0, "max": 100, "step": 1}],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"extension": "mp4"
}
@@ -0,0 +1,17 @@
{
"main_pass":
[
"-n", "-c:v", "libx265",
"-vtag", "hvc1",
"-pix_fmt", ["pix_fmt", ["yuv420p10le", "yuv420p"]],
"-crf", ["crf","INT", {"default": 22, "min": 0, "max": 100, "step": 1}],
"-preset", "medium",
"-x265-params", "log-level=quiet",
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "av1_nvenc",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,15 @@
{
"main_pass":
[
"-n", "-c:v", "h264_nvenc",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n", "-c:v", "hevc_nvenc",
"-vtag", "hvc1",
"-pix_fmt", ["pix_fmt", ["yuv420p", "p010le"]],
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "aac"],
"bitrate": ["bitrate","INT", {"default": 10, "min": 1, "max": 999, "step": 1 }],
"megabit": ["megabit","BOOLEAN", {"default": true}],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"extension": "mp4"
}
@@ -0,0 +1,16 @@
{
"main_pass":
[
"-n",
"-pix_fmt", ["pix_fmt",["yuv420p","yuva420p"]],
"-crf", ["crf","INT", {"default": 20, "min": 0, "max": 100, "step": 1}],
"-b:v", "0",
"-vf", "scale=out_color_matrix=bt709",
"-color_range", "tv", "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709"
],
"fake_trc": "bt709",
"audio_pass": ["-c:a", "libvorbis"],
"save_metadata": ["save_metadata", "BOOLEAN", {"default": true}],
"trim_to_audio": ["trim_to_audio", "BOOLEAN", {"default": false}],
"extension": "webm"
}
@@ -0,0 +1,56 @@
import torch
from nodes import VAEEncode
from comfy.utils import ProgressBar
class VAEDecodeBatched:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"samples": ("LATENT", ),
"vae": ("VAE", ),
"per_batch": ("INT", {"default": 16, "min": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
RETURN_TYPES = ("IMAGE",)
FUNCTION = "decode"
def decode(self, vae, samples, per_batch):
decoded = []
pbar = ProgressBar(samples["samples"].shape[0])
for start_idx in range(0, samples["samples"].shape[0], per_batch):
decoded.append(vae.decode(samples["samples"][start_idx:start_idx+per_batch]))
pbar.update(per_batch)
return (torch.cat(decoded, dim=0), )
class VAEEncodeBatched:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"pixels": ("IMAGE", ), "vae": ("VAE", ),
"per_batch": ("INT", {"default": 16, "min": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/batched nodes"
RETURN_TYPES = ("LATENT",)
FUNCTION = "encode"
def encode(self, vae, pixels, per_batch):
t = []
pbar = ProgressBar(pixels.shape[0])
for start_idx in range(0, pixels.shape[0], per_batch):
try:
sub_pixels = vae.vae_encode_crop_pixels(pixels[start_idx:start_idx+per_batch])
except:
sub_pixels = VAEEncode.vae_encode_crop_pixels(pixels[start_idx:start_idx+per_batch])
t.append(vae.encode(sub_pixels[:,:,:,:3]))
pbar.update(per_batch)
return ({"samples": torch.cat(t, dim=0)}, )
@@ -0,0 +1,616 @@
from .logger import logger
def image(src):
return f'<img src={src} loading=lazy style="width: 0px; min-width: 100%">'
def video(src):
return f'<video preload="none" src={src} muted loop controls controlslist="nodownload noremoteplayback noplaybackrate" style="width: 0px; min-width: 100%" class="VHS_loopedvideo">'
def short_desc(desc):
return f'<div id=VHS_shortdesc>{desc}</div>'
def format_each(desc, **kwargs):
if isinstance(desc, dict):
res = {}
for k,v in desc.items():
res[format_each(k, **kwargs)] = format_each(v, **kwargs)
return res
if isinstance(desc, list):
res = []
for v in desc:
res.append(format_each(v, **kwargs))
return res
return desc.format(**kwargs)
def format_type(desc, lower, lowers=None, upper=None, uppers=None, cap=None):
"""Utility function for nodes with image/latent/mask variants"""
if lowers is None:
lowers = lower + 's'
if cap is None:
cap = lower.capitalize()
if upper is None:
upper = lower.upper()
if uppers is None:
uppers = lowers.upper()
return format_each(desc, lower=lower, lowers=lowers, upper=upper, uppers=uppers, cap=cap)
common_descriptions = {
'merge_strategy': [
'Determines what the output resolution will be if input resolutions don\'t match',
{'match A': 'Always use the resolution for A',
'match B': 'Always use the resolution for B',
'match smaller': 'Pick the smaller resolution by area',
'match larger': 'Pick the larger resolution by area',
}],
'scale_method': [
'Determines what method to use if scaling is required',
],
'crop_method': 'When sizes don\'t match, should the resized image have it\'s aspect ratio changed, or be cropped to maintain aspect ratio',
'VHS_PATH': [
'This is a VHS_PATH input. When edited, it provides a list of possible valid files or directories',
video('https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/assets/4284322/729b7185-1fca-41d8-bc8d-a770bb2a5ce6'),
'The current top-most completion may be selected with Tab',
'You can navigate up a directory by pressing Ctrl+B (or Ctrl+W if supported by browser)',
'The filter on suggested file types can be disabled by pressing Ctrl+G.',
'If converted to an input, this functions as a string',
],
"GetCount": ['Get {cap} Count 🎥🅥🅗🅢', short_desc('Return the number of {lowers} in an input as an INT'),
{'Inputs': {
'{lowers}': 'The input {lower}',
},
'Outputs': {
'count': 'The number of {lowers} in the input',
},
}],
"SelectEveryNth": ['Select Every Nth {cap} 🎥🅥🅗🅢', short_desc('Keep only 1 {lower} for every interval'),
{'Inputs': {
'{lowers}': 'The input {lower}',
},
'Outputs': {
'{upper}': 'The output {lowers}',
'count': 'The number of {lowers} in the input',
},
'Widgets':{
'select_every_nth': 'The interval from which one frame is kept. 1 means no frames are skipped.',
'skip_first_{lowers}': 'A number of frames which that is skipped from the start. This applies before select_every_nth. As a result, multiple copies of the node can each have a different skip_first_frames to divide the {lower} into groups'
},
}],
}
descriptions = {
'VHS_VideoCombine': ['Video Combine 🎥🅥🅗🅢', short_desc('Combine an image sequence into a video'), {
'Inputs': {
'images': 'The images to be turned into a video',
'audio':'(optional) audio to add to the video',
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long image sequences into sub batches. See the documentation for Meta Batch Manager',
'vae':['(optional) If provided, the node will take latents as input instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
"Unlike on Load Video, this isn't always a strict upgrade over using a standalone VAE Decode.",
"If you have multiple Video Combine outputs, then the VAE decode will be performed for each output node increasing execution time",
"If you make any change to output settings on the Video Combine (such as changing the output format), the VAE decode will be performed again as the decoded result is (by design) not cached",
]
},
'Widgets':{
'frame_rate': 'The frame rate which will be used for the output video. Consider converting this to an input and connecting this to a Load Video with Video Info(Loaded)->fps. When including audio, failure to properly set this will result in audio desync',
'loop_count': 'The number of additional times the video should repeat. Can cause performance issues when used with long (100+ frames) sequences',
'filename_prefix': 'A prefix to add to the name of the output filename. This can include subfolders or format strings.',
'format': 'The output format to use. Formats starting with, \'image\' are saved with PIL, but formats starting with \'video\' utilize the video_formats system. \'video\' options require ffmpeg and selecting one frequently adds additional options to the node.',
'pingpong': 'Play the video normally, then repeat the video in reverse so that it \'pingpongs\' back and forth. This is frequently used to minimize the appearance of skips on very short animations.',
'save_output': 'Specifies if output files should be saved to the output folder, or the temporary output folder',
'videopreview': 'Displays a preview for the processed result. If advanced previews is enabled, the output is always converted to a format viewable from the browser. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
},
'Common Format Widgets': {
'crf': 'Determines how much to prioritize quality over filesize. Numbers vary between formats, but on each format that includes it, the default value provides visually loss less output',
'pix_fmt': ['The pixel format to use for output. Alternative options will often have higher quality at the cost of increased file size and reduced compatibility with external software.', {
'yuv420p': 'The most common and default format',
'yuv420p10le': 'Use 10 bit color depth. This can improve color quality when combined with 16bit input color depth',
'yuva420p': 'Include transparency in the output video'
}],
'input_color_depth': 'VHS supports outputting 16bit images. While this produces higher quality output, the difference usually isn\'t visible without postprocessing and it significantly increases file size and processing time.',
'save_metadata': 'Determines if metadata for the workflow should be included in the output video file',
}
}],
'VHS_LoadVideo': ['Load Video 🎥🅥🅗🅢', short_desc('Loads a video from the input folder'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'frame_count': 'The length of images just returned',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': 'The video file to be loaded. Lists all files with a video extension in the ComfyUI/Input folder',
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'choose video to upload': 'An upload button is provided to upload local files to the input folder',
'videopreview': 'Displays a preview for the selected video input. If advanced previews is enabled, this preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoFFmpeg': ['Load Video FFmpeg 🎥🅥🅗🅢', short_desc('Loads a video from the input folder using ffmpeg instead of opencv'),
'Provides faster execution speed, transparency support, and allows specifying start time in seconds',
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'mask': 'Transparency data from the loaded video',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': 'The video file to be loaded. Lists all files with a video extension in the ComfyUI/Input folder',
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'start_time': 'A timestamp, in seconds from the start of the video, to start loading frames from. ',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'choose video to upload': 'An upload button is provided to upload local files to the input folder',
'videopreview': 'Displays a preview for the selected video input. If advanced previews is enabled, this preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoPath': ['Load Video (Path) 🎥🅥🅗🅢', short_desc('Loads a video from an arbitrary path'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'frame_count': 'The length of images just returned',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': ['The video file to be loaded.', 'You can also select an image to load it as a single frame'] + common_descriptions['VHS_PATH'],
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadVideoFFmpegPath': ['Load Video FFmpeg (Path) 🎥🅥🅗🅢', short_desc('Loads a video from an arbitrary path using ffmpeg instead of opencv'),
'Provides faster execution speed, transparency support, and allows specifying start time in seconds',
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
'vae': ['(optional) If provided the node will output latents instead of images. This drastically reduces the required RAM (not VRAM) when working with long (100+ frames) sequences',
'Using this is strongly encouraged unless connecting to a node that requires a blue image connection such as Apply Controllnet',
],
},
'Outputs': {
'IMAGE': 'The loaded images',
'mask': 'Transparency data from the loaded video',
'audio': 'The audio from the loaded video',
'video_info': 'Exposes additional info about the video such as the source frame rate, or the total length',
'LATENT': 'The loaded images pre-converted to latents. Only available when a vae is connected',
},
'Widgets': {
'video': ['The video file to be loaded.', 'You can also select an image to load it as a single frame'] + common_descriptions['VHS_PATH'],
'force_rate': 'Drops or duplicates frames so that the produced output has the target frame rate. Many motion models are trained on videos of a specific frame rate and will give better results if input matches that frame rate. If set to 0, all frames are returned. May give unusual results with inputs that have a variable frame rate like animated gifs. Reducing this value can also greatly reduce the execution time and memory requirements.',
'force_size': 'Previously was used to provide suggested resolutions. Instead, custom_width and custom_height can be disabled by setting to 0.',
'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set',
'frame_load_cap': 'The maximum number of frames to load. If 0, all frames are loaded.',
'skip_first_frames': 'A number of frames which are discarded before producing output.',
'select_every_nth': 'Similar to frame rate. Keeps only the first of every n frames and discard the rest. Has better compatibility with variable frame rate inputs such as gifs. When combined with force_rate, select_every_nth_applies after force_rate so the resulting output has a frame rate equivalent to force_rate/select_every_nth. select_every_nth does not apply to skip_first_frames',
'format': 'Updates other widgets so that only values supported by the given format can be entered and provides recommended defaults.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the frame_load_cap, force_rate, skip_first_frames, and select_every_nth values chosen. If the video has audio, it will also be previewed when moused over. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImages': ['Load Images 🎥🅥🅗🅢', short_desc('Loads a sequence of images from a subdirectory of the input folder'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
'frame_count': 'The length of images just returned',
},
'Widgets': {
'directory': 'The directory images will be loaded from. Filtered to process jpg, png, ppm, bmp, tif, and webp files',
'image_load_cap': 'The maximum number of images to load. If 0, all images are loaded.',
'start_time': 'A timestamp, in seconds from the start of the video, to start loading frames from. ',
'choose folder to upload': 'An upload button is provided to upload a local folder containing images to the input folder',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImagesPath': ['Load Images (Path) 🎥🅥🅗🅢', short_desc('Loads a sequence of images from an arbitrary path'),
{'Inputs': {
'meta_batch': '(optional) Connect to a Meta Batch manager to divide extremely long sequences into sub batches. See the documentation for Meta Batch Manager',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
'frame_count': 'The length of images just returned',
},
'Widgets': {
'directory': ['The directory images will be loaded from. Filtered to process jpg, png, ppm, bmp, tif, and webp files'] + common_descriptions['VHS_PATH'],
'image_load_cap': 'The maximum number of images to load. If 0, all images are loaded.',
'skip_first_images': 'A number of images which are discarded before producing output.',
'select_every_nth': 'Keeps only the first of every n frames and discard the rest.',
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
'VHS_LoadImagePath': ['Load Image (Path) 🎥🅥🅗🅢', short_desc('Load a single image from a given path'),
{'Inputs': {
'vae': '(optional) If provided the node will output latents instead of images.',
},
'Outputs': {
'IMAGE': 'The loaded images',
'MASK': 'The alpha channel of the loaded images.',
},
'Widgets': {
'image': ['The image file to be loaded.'] + common_descriptions['VHS_PATH'],
'force_size': ['Allows for conveniently scaling the input without requiring an additional node. Provides options to maintain aspect ratio or conveniently target common training formats for Animate Diff', {'custom_width': 'Allows for an arbitrary width to be entered, cropping to maintain aspect ratio if both are set',
'custom_height': 'Allows for an arbitrary height to be entered, cropping to maintain aspect ratio if both are set'}],
'videopreview': 'Displays a preview for the selected video input. Will only be shown if Advanced Previews is enabled. This preview will reflect the image_load_cap, skip_first_images, and select_every_nth values chosen. Additional preview options can be accessed with right click.',
}
}],
"VHS_LoadAudio": ['Load Audio (Path) 🎥🅥🅗🅢', short_desc('Loads an audio file from an arbitrary path'),
{'Outputs': {
'audio': 'The loaded audio',
},
'Widgets': {
'audio_file': ['The audio file to be loaded.'] + common_descriptions['VHS_PATH'],
'seek_seconds': 'An offset from the start of the sound file that the audio should start from',
}
}],
"VHS_LoadAudioUpload": ['Load Audio (Upload) 🎥🅥🅗🅢', short_desc('Loads an audio file from the input directory'),
"Very similar in functionality to the built-in LoadAudio. It was originally added before VHS swapped to use Comfy's internal AUDIO format, but provides the additional options for start time and duration",
{'Outputs': {
'audio': 'The loaded audio',
},
'Widgets': {
'audio': 'The audio file to be loaded.',
'start_time': 'An offset from the start of the sound file that the audio should start from',
'duration': 'A maximum limit for the audio. Disabled if 0',
'choose audio to upload': 'An upload button is provided to upload an audio file to the input folder',
}
}],
"VHS_AudioToVHSAudio": ['Audio to legacy VHS_AUDIO 🎥🅥🅗🅢', short_desc('utility function for compatibility with external nodes'),
"VHS used to use an internal VHS_AUDIO format for routing audio between inputs and outputs. This format was intended to only be used internally and was designed with a focus on performance over ease of use. Since ComfyUI now has an internal AUDIO format, VHS now uses this format. However, some custom node packs were made that are external to both ComfyUI and VHS that use VHS_AUDIO. This node was added so that those external nodes can still function",
{'Inputs': {
'audio': 'An input in the standardized AUDIO format',
},
'Outputs': {
'vhs_audio': 'An output in the legacy VHS_AUDIO format for use with external nodes',
},
}],
"VHS_VHSAudioToAudio": ['Legacy VHS_AUDIO to Audio 🎥🅥🅗🅢', short_desc('utility function for compatibility with external nodes'),
"VHS used to use an internal VHS_AUDIO format for routing audio between inputs and outputs. This format was intended to only be used internally and was designed with a focus on performance over ease of use. Since ComfyUI now has an internal AUDIO format, VHS now uses this format. However, some custom node packs were made that are external to both ComfyUI and VHS that use VHS_AUDIO. This node was added so that those external nodes can still function",
{'Inputs': {
'vhs_audio': 'An input in the legacy VHS_AUDIO format produced by an external node',
},
'Outputs': {
'vhs_audio': 'An output in the standardized AUDIO format',
},
}],
"VHS_PruneOutputs": ['Prune Outputs 🎥🅥🅗🅢', short_desc('Automates deletion of undesired outputs from a Video Combine node.'),
'Video Combine produces a number of file outputs in addition to the final output. Some of these, such as a video file without audio included, are implementation limitations and are not feasible to solve. As an alternative, the Prune Outputs node is added to automate the deletion of these file outputs if they are not desired',
{'Inputs': {
'filenames': 'A connection from a Video Combine node to indicate which outputs should be pruned',
},
'Widgets': {
'options': ['Which files should be deleted',
{'Intermediate': 'Delete any files that were required for intermediate processing but are not the final output, like the no-audio output file when audio is included',
'Intermediate and Utility': 'Delete all produced files that aren\'t the final output, including the first frame png',
}]}
}],
"VHS_BatchManager": ['Meta Batch Manager 🎥🅥🅗🅢', short_desc('Split the processing of a very long video into sets of smaller Meta Batches'),
"The Meta Batch Manager allows for extremely long input videos to be processed when all other methods for fitting the content in RAM fail. It does not effect VRAM usage.",
"It must be connected to at least one Input (a Load Video or Load Images) AND at least one Video Combine",
image("https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/assets/4284322/7cb3fb7e-59d8-4cb2-a09f-9c6698de8b1f"),
"It functions by holding both the inputs and ouputs open between executions, and automatically requeue's the workflow until one of the inputs is unable to provide additional images.",
"Because each sub execution only contains a subset of the total frames, each sub execution creates a hard window which temporal smoothing can not be applied across. This results in jumps in the output.",
{'Outputs': {
'meta_batch': 'Add all connected nodes to this Meta Batch',
},
'Widgets': {
'frames_per_batch': 'How many frames to process for each sub execution. If loading as image, each frame will use about 50MB of RAM (not VRAM), and this can safely be set in the 100-1000 range, depending on available memory. When loading and combining from latent space (no blue image noodles exist), this value can be much higher, around the 2,000 to 20,000 range',
}
}],
"VHS_VideoInfo": ['Video Info 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'source_fps🟨': 'The frame rate of the video',
'source_frame_count🟨': 'How many total frames the video contains before accounting for frame rate or select_every_nth',
'source_duration🟨': 'The length of images just returned in seconds',
'source_width🟨': 'The width',
'source_height🟨': 'The height',
'loaded_fps🟦': 'The frame rate after accounting for force_rate and select_every_nth. This output is of particular use as it can be connected to the converted frame_rate input of a Video Combine node to ensure audio remains synchronized.',
'loaded_frame_count🟦': 'The number of frames returned by the current execution. Identical to the frame_count returned by the node itself',
'loaded_duration🟦': 'The duration in seconds of returned images after accounting for frame_load_cap',
'loaded_width🟦': 'The width of the video after scaling. These coordinates are in image space even if loading to latent space',
'loaded_height🟦': 'The height of the video after scaling. These coordinates are in image space even if loading to latent space',
},
}],
"VHS_VideoInfoSource": ['Video Info Source 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs describing the file itself without accounting for load options'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'source_fps🟨': 'The frame rate of the video',
'source_frame_count🟨': 'How many total frames the video contains before accounting for frame rate or select_every_nth',
'source_duration🟨': 'The length of images just returned in seconds',
'source_width🟨': 'The original width',
'source_height🟨': 'The original height',
}
}],
"VHS_VideoInfoLoaded": ['Video Info Loaded 🎥🅥🅗🅢', short_desc('Splits information on a video into a numerous outputs describing the file itself after accounting for load options'),
{'Inputs': {
'video_info': 'A connection to a Load Video node',
},
'Outputs': {
'loaded_fps🟦': 'The frame rate after accounting for force_rate and select_every_nth. This output is of particular use as it can be connected to the converted frame_rate input of a Video Combine node to ensure audio remains synchronized.',
'loaded_frame_count🟦': 'The number of frames returned by the current execution. Identical to the frame_count returned by the node itself',
'loaded_duration🟦': 'The duration in seconds of returned images after accounting for frame_load_cap',
'loaded_width🟦': 'The width of the video after scaling. This is the dimension of the corresponding image even if loading as a latent directly',
'loaded_height🟦': 'The height of the video after scaling. This is the dimension of the corresponding image even if loading as a latent directly',
}
}],
"VHS_SelectFilename": ['VAE Select Filename 🎥🅥🅗🅢', short_desc('Select a single filename from the VHS_FILENAMES output by a Video Combine and return it as a string'),
'Take care when combining this node with Prune Outputs. The VHS_FILENAMES object is immutable and will always contain the full list of output files, but execution order is undefined behavior (currently, Prune Outputs will generally execute first) and SelectFilename may return a path to a file that no longer exists.',
{'Inputs': {
'filenames': 'A VHS_FILENAMES from a Video Combine node',
},
'Outputs': {
'filename': 'A string representation of the full output path for the chosen file',
},
'Widgets': {
'index': 'The index of which file should be selected. The default, -1, chooses the most complete output',
},
}],
# Batched Nodes
"VHS_VAEEncodeBatched": ['VAE Encode Batched 🎥🅥🅗🅢', short_desc('Encode images as latents with a manually specified batch size.'),
"Some people have ran into VRAM issues when encoding or decoding large batches of images. As a workaround, this node lets you manually set a batch size when encoding images.",
"Unless these issues have been encountered, it is simpler to use the native VAE Encode or to encode directly from a Load Video",
{'Inputs': {
'pixels': 'The images to be encoded.',
'vae': 'The VAE to use when encoding.',
},
'Outputs': {
'LATENT': 'The encoded latents.',
},
'Widgets': {
'per_batch': 'The maximum number of images to encode in each batch.',
},
}],
"VHS_VAEDecodeBatched": ['VAE Decode Batched 🎥🅥🅗🅢', short_desc('Decode latents to images with a manually specified batch size'),
"Some people have ran into VRAM issues when encoding or decoding large batches of images. As a workaround, this node lets you manually set a batch size when decoding latents.",
"Unless these issues have been encountered, it is simpler to use the native VAE Decode or to decode from a Video Combine directly",
{'Inputs': {
'samples': 'The latents to be decoded.',
'vae': 'The VAE to use when decoding.',
},
'Outputs': {
'IMAGE': 'The decoded images.',
},
'Widgets': {
'per_batch': 'The maximum number of images to decode in each batch.',
},
}],
# Latent and Image nodes
"VHS_SplitLatents": ['Split Latents 🎥🅥🅗🅢', short_desc('Split a set of latents into two groups'),
{'Inputs': {
'latents': 'The latents to be split.',
},
'Outputs': {
'LATENT_A': 'The first group of latents',
'A_count': 'The number of latents in group A. This will be equal to split_index unless the latents input has length less than split_index',
'LATENT_B': 'The second group of latents',
'B_count': 'The number of latents in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_SplitImages": ['Split Images 🎥🅥🅗🅢', short_desc('Split a set of images into two groups'),
{'Inputs': {
'images': 'The images to be split.',
},
'Outputs': {
'IMAGE_A': 'The first group of images',
'A_count': 'The number of images in group A. This will be equal to split_index unless the images input has length less than split_index',
'IMAGE_B': 'The second group of images',
'B_count': 'The number of images in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_SplitMasks": ['Split Masks 🎥🅥🅗🅢', short_desc('Split a set of masks into two groups'),
{'Inputs': {
'mask': 'The masks to be split.',
},
'Outputs': {
'MASK_A': 'The first group of masks',
'A_count': 'The number of masks in group A. This will be equal to split_index unless the mask input has length less than split_index',
'MASK_B': 'The second group of masks',
'B_count': 'The number of masks in group B'
},
'Widgets': {
'split_index': 'The index of the first latent that will be in the second output groups.',
},
}],
"VHS_MergeLatents": ['Merge Latents 🎥🅥🅗🅢', short_desc('Combine two groups of latents into a single group of latents'),
{'Inputs': {
'latents_A': 'The first group of latents',
'latents_B': 'The first group of latents',
},
'Outputs': {
'LATENT': 'The combined group of latents',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_MergeImages": ['Merge Images 🎥🅥🅗🅢', short_desc('Combine two groups of images into a single group of images'),
{'Inputs': {
'images_A': 'The first group of images',
'images_B': 'The first group of images',
},
'Outputs': {
'IMAGE': 'The combined group of images',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_MergeMasks": ['Merge Masks 🎥🅥🅗🅢', short_desc('Combine two groups of masks into a single group of masks'),
{'Inputs': {
'mask_A': 'The first group of masks',
'mask_B': 'The first group of masks',
},
'Outputs': {
'MASK': 'The combined group of masks',
'count': 'The length of the combined group',
},
'Widgets': {
'merge_strategy': common_descriptions['merge_strategy'],
'scale_method': common_descriptions['scale_method'],
'crop': common_descriptions['crop_method'],
},
}],
"VHS_GetLatentCount": format_type(common_descriptions['GetCount'], 'latent'),
"VHS_GetImageCount": format_type(common_descriptions['GetCount'], 'image'),
"VHS_GetMaskCount": format_type(common_descriptions['GetCount'], 'mask'),
"VHS_DuplicateLatents": ['Repeat Latents 🎥🅥🅗🅢', short_desc('Append copies of a latent to itself so it repeats'),
{'Inputs': {
'latents': 'The latents to be repeated',
},
'Outputs': {
'LATENT': 'The latent with repeats',
'count': 'The number of latents in the output. Equal to the length of the input latent * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the latent should repeat. 1, the default, means no change.',
},
}],
"VHS_DuplicateImages": ['Repeat Images 🎥🅥🅗🅢', short_desc('Append copies of a image to itself so it repeats'),
{'Inputs': {
'IMAGES': 'The image to be repeated',
},
'Outputs': {
'IMAGE': 'The image with repeats',
'count': 'The number of image in the output. Equal to the length of the input image * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the mask should repeat. 1, the default, means no change.',
},
}],
"VHS_DuplicateMasks": ['Repeat Masks 🎥🅥🅗🅢', short_desc('Append copies of a mask to itself so it repeats'),
{'Inputs': {
'masks': 'The masks to be repeated',
},
'Outputs': {
'LATENT': 'The mask with repeats',
'count': 'The number of mask in the output. Equal to the length of the input mask * multiply_by',
},
'Widgets': {
'multiply_by': 'Controls the number of times the mask should repeat. 1, the default, means no change.',
},
}],
"VHS_SelectEveryNthLatent": format_type(common_descriptions['SelectEveryNth'], 'latent'),
"VHS_SelectEveryNthImage": format_type(common_descriptions['SelectEveryNth'], 'image'),
#TODO: fix discrepency of input being mask instead of masks?
"VHS_SelectEveryNthMask": format_type(common_descriptions['SelectEveryNth'], 'mask', lowers='mask'),
#TODO: port documentation for select nodes to new system
#"VHS_SelectLatents": None,
#"VHS_SelectImages": None,
#"VHS_SelectMasks": None,
"VHS_Unbatch": ['Unbatch 🎥🅥🅗🅢', short_desc('Unbatch a list of items into a single concatenated item'),
"Useful for when you want a single video output from a complex workflow",
"Has no relation to the Meta Batch system of VHS",
{'Inputs': {
'batched': 'Any input which may or may not be batched',
},
'Outputs': {
'unbatched': 'A single output element. Torch tensors are concatenated across dim 0, all other types are added which functions as concatenation for strings and arrays, but may give undesired results for other types',
},
}],
"VHS_SelectLatest": ['Select Latest 🎥🅥🅗🅢', short_desc('Experimental virtual node to select the most recently modified file from a given folder'),
"Assists in the creation of workflows where outputs from one execution are used elsewhere in subsequent executions.",
{'Inputs': {
'filename_prefix': 'A path which can consist of a combination of folders and a prefix which candidate files must match',
'filename_postfix': 'A string which chich the selected file must end with. Useful for limiting to a target extension.',
},
'Outputs': {
'Filename': 'A string representing a file path to the most recently modified file.',
},
}],
}
def as_html(entry, depth=0):
if isinstance(entry, dict):
size = 0.8 if depth < 2 else 1
html = ''
for k in entry:
if k == "collapsed":
continue
collapse_single = k.endswith("_collapsed")
if collapse_single:
name = k[:-len("_collapsed")]
else:
name = k
collapse_flag = ' VHS_precollapse' if entry.get("collapsed", False) or collapse_single else ''
html += f'<div vhs_title=\"{name}\" style=\"display: flex; font-size: {size}em\" class=\"VHS_collapse{collapse_flag}\"><div style=\"color: #AAA; height: 1.5em;\">[<span style=\"font-family: monospace\">-</span>]</div><div style=\"width: 100%\">{name}: {as_html(entry[k], depth=depth+1)}</div></div>'
return html
if isinstance(entry, list):
if depth == 0:
depth += 1
size = .8
else:
size = 1
html = ''
html += entry[0]
for i in entry[1:]:
html += f'<div style=\"font-size: {size}em\">{as_html(i, depth=depth)}</div>'
return html
return str(entry)
def format_descriptions(nodes):
for k in descriptions:
if k.endswith("_collapsed"):
k = k[:-len("_collapsed")]
nodes[k].DESCRIPTION = as_html(descriptions[k])
undocumented_nodes = []
for k in nodes:
if not hasattr(nodes[k], "DESCRIPTION"):
undocumented_nodes.append(k)
if len(undocumented_nodes) > 0:
logger.warning('Some nodes have not been documented %s', undocumented_nodes)
@@ -0,0 +1,554 @@
from torch import Tensor
import torch
import comfy.utils
from .utils import BIGMIN, BIGMAX, select_indexes_from_str, convert_str_to_indexes, select_indexes
class MergeStrategies:
MATCH_A = "match A"
MATCH_B = "match B"
MATCH_SMALLER = "match smaller"
MATCH_LARGER = "match larger"
list_all = [MATCH_A, MATCH_B, MATCH_SMALLER, MATCH_LARGER]
class ScaleMethods:
NEAREST_EXACT = "nearest-exact"
BILINEAR = "bilinear"
AREA = "area"
BICUBIC = "bicubic"
BISLERP = "bislerp"
list_all = [NEAREST_EXACT, BILINEAR, AREA, BICUBIC, BISLERP]
class CropMethods:
DISABLED = "disabled"
CENTER = "center"
list_all = [DISABLED, CENTER]
class SplitLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT", "LATENT", "INT")
RETURN_NAMES = ("LATENT_A", "A_count", "LATENT_B", "B_count")
FUNCTION = "split_latents"
def split_latents(self, latents: dict[str, Tensor], split_index: int):
latents_len = len(latents["samples"])
group_a = latents.copy()
group_b = latents.copy()
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
group_a[key] = latents[key][:split_index]
group_b[key] = latents[key][split_index:]
return (group_a, group_a["samples"].size(0), group_b, group_b["samples"].size(0))
class SplitImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT", "IMAGE", "INT")
RETURN_NAMES = ("IMAGE_A", "A_count", "IMAGE_B", "B_count")
FUNCTION = "split_images"
def split_images(self, images: Tensor, split_index: int):
group_a = images[:split_index]
group_b = images[split_index:]
return (group_a, group_a.size(0), group_b, group_b.size(0))
class SplitMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"split_index": ("INT", {"default": 0, "step": 1, "min": BIGMIN, "max": BIGMAX}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT", "MASK", "INT")
RETURN_NAMES = ("MASK_A", "A_count", "MASK_B", "B_count")
FUNCTION = "split_masks"
def split_masks(self, mask: Tensor, split_index: int):
group_a = mask[:split_index]
group_b = mask[split_index:]
return (group_a, group_a.size(0), group_b, group_b.size(0))
class MergeLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents_A": ("LATENT",),
"latents_B": ("LATENT",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "merge"
def merge(self, latents_A: dict, latents_B: dict, merge_strategy: str, scale_method: str, crop: str):
latents = []
latents_A = latents_A.copy()["samples"]
latents_B = latents_B.copy()["samples"]
# TODO: handle other properties on latents besides just "samples"
# if not same dimensions, do scaling
if latents_A.shape[3] != latents_B.shape[3] or latents_A.shape[2] != latents_B.shape[2]:
A_size = latents_A.shape[3] * latents_A.shape[2]
B_size = latents_B.shape[3] * latents_B.shape[2]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# apply scaling
if use_A_as_template:
latents_B = comfy.utils.common_upscale(latents_B, latents_A.shape[3], latents_A.shape[2], scale_method, crop)
else:
latents_A = comfy.utils.common_upscale(latents_A, latents_B.shape[3], latents_B.shape[2], scale_method, crop)
latents.append(latents_A)
latents.append(latents_B)
merged = {"samples": torch.cat(latents, dim=0)}
return (merged, len(merged["samples"]),)
class MergeImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images_A": ("IMAGE",),
"images_B": ("IMAGE",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "merge"
def merge(self, images_A: Tensor, images_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
images = []
# if not same dimensions, do scaling
if images_A.shape[3] != images_B.shape[3] or images_A.shape[2] != images_B.shape[2]:
images_A = images_A.movedim(-1,1)
images_B = images_B.movedim(-1,1)
A_size = images_A.shape[3] * images_A.shape[2]
B_size = images_B.shape[3] * images_B.shape[2]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# apply scaling
if use_A_as_template:
images_B = comfy.utils.common_upscale(images_B, images_A.shape[3], images_A.shape[2], scale_method, crop)
else:
images_A = comfy.utils.common_upscale(images_A, images_B.shape[3], images_B.shape[2], scale_method, crop)
images_A = images_A.movedim(1,-1)
images_B = images_B.movedim(1,-1)
images.append(images_A)
images.append(images_B)
all_images = torch.cat(images, dim=0)
return (all_images, all_images.size(0),)
class MergeMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask_A": ("MASK",),
"mask_B": ("MASK",),
"merge_strategy": (MergeStrategies.list_all,),
"scale_method": (ScaleMethods.list_all,),
"crop": (CropMethods.list_all,),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "merge"
def merge(self, mask_A: Tensor, mask_B: Tensor, merge_strategy: str, scale_method: str, crop: str):
masks = []
# if not same dimensions, do scaling
if mask_A.shape[2] != mask_B.shape[2] or mask_A.shape[1] != mask_B.shape[1]:
A_size = mask_A.shape[2] * mask_A.shape[1]
B_size = mask_B.shape[2] * mask_B.shape[1]
# determine which to use
use_A_as_template = True
if merge_strategy == MergeStrategies.MATCH_A:
pass
elif merge_strategy == MergeStrategies.MATCH_B:
use_A_as_template = False
elif merge_strategy in (MergeStrategies.MATCH_SMALLER, MergeStrategies.MATCH_LARGER):
if A_size <= B_size:
use_A_as_template = True if merge_strategy == MergeStrategies.MATCH_SMALLER else False
# add dimension where image channels would be expected to work with common_upscale
mask_A = torch.unsqueeze(mask_A, 1)
mask_B = torch.unsqueeze(mask_B, 1)
# apply scaling
if use_A_as_template:
mask_B = comfy.utils.common_upscale(mask_B, mask_A.shape[3], mask_A.shape[2], scale_method, crop)
else:
mask_A = comfy.utils.common_upscale(mask_A, mask_B.shape[3], mask_B.shape[2], scale_method, crop)
# undo dimension increase
mask_A = torch.squeeze(mask_A, 1)
mask_B = torch.squeeze(mask_B, 1)
masks.append(mask_A)
masks.append(mask_B)
all_masks = torch.cat(masks, dim=0)
return (all_masks, all_masks.size(0),)
class SelectEveryNthLatent:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_latents": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "select_latents"
def select_latents(self, latents: dict[str, Tensor], select_every_nth: int, skip_first_latents: int):
latents = latents.copy()
latents_len = len(latents["samples"])
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
latents[key] = val[skip_first_latents::select_every_nth]
return (latents, latents["samples"].size(0))
class SelectEveryNthImage:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "select_images"
def select_images(self, images: Tensor, select_every_nth: int, skip_first_images: int):
sub_images = images[skip_first_images::select_every_nth]
return (sub_images, sub_images.size(0))
class SelectEveryNthMask:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"skip_first_masks": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "select_masks"
def select_masks(self, mask: Tensor, select_every_nth: int, skip_first_masks: int):
sub_mask = mask[skip_first_masks::select_every_nth]
return (sub_mask, sub_mask.size(0))
class GetLatentCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, latents: dict):
return (latents["samples"].size(0),)
class GetImageCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, images: Tensor):
return (images.size(0),)
class GetMaskCount:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("count",)
FUNCTION = "count_input"
def count_input(self, mask: Tensor):
return (mask.size(0),)
class RepeatLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latents": ("LATENT",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT", "INT",)
RETURN_NAMES = ("LATENT", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, latents: dict[str, Tensor], multiply_by: int):
latents = latents.copy()
latents_len = len(latents["samples"])
for key, val in latents.items():
if type(val) == Tensor and len(val) == latents_len:
full_latents = []
for _ in range(0, multiply_by):
full_latents.append(latents[key])
latents[key] = torch.cat(full_latents, dim=0)
return (latents, latents["samples"].size(0),)
class RepeatImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE", "INT",)
RETURN_NAMES = ("IMAGE", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, images: Tensor, multiply_by: int):
full_images = []
for n in range(0, multiply_by):
full_images.append(images)
new_images = torch.cat(full_images, dim=0)
return (new_images, new_images.size(0),)
class RepeatMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"multiply_by": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1})
}
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK", "INT",)
RETURN_NAMES = ("MASK", "count",)
FUNCTION = "duplicate_input"
def duplicate_input(self, mask: Tensor, multiply_by: int):
full_masks = []
for n in range(0, multiply_by):
full_masks.append(mask)
new_mask = torch.cat(full_masks, dim=0)
return (new_mask, new_mask.size(0),)
select_description = """Use comma-separated indexes to select items in the given order.
Supports negative indexes, python-style ranges (end index excluded),
as well as range step.
Acceptable entries (assuming 16 items provided, so idxs 0 to 15 exist):
0 -> Returns [0]
-1 -> Returns [15]
0, 1, 13 -> Returns [0, 1, 13]
0:5, 13 -> Returns [0, 1, 2, 3, 4, 13]
0:-1 -> Returns [0, 1, 2, ..., 13, 14]
0:5:-1 -> Returns [4, 3, 2, 1, 0]
0:5:2 -> Returns [0, 2, 4]
::-1 -> Returns [15, 14, 13, ..., 2, 1, 0]
"""
class SelectLatents:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"latent": ("LATENT",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/latent"
RETURN_TYPES = ("LATENT",)
FUNCTION = "select"
def select(self, latent: dict[str, Tensor], indexes: str, err_if_missing: bool, err_if_empty: bool):
# latents are a dict and may contain different stuff (like noise_mask), so need to account for it all
latent = latent.copy()
latents_len = len(latent["samples"])
real_idxs = convert_str_to_indexes(indexes, latents_len, allow_missing=not err_if_missing)
if err_if_empty and len(real_idxs) == 0:
raise Exception(f"Nothing was selected based on indexes found in '{indexes}'.")
for key, val in latent.items():
if type(val) == Tensor and len(val) == latents_len:
latent[key] = select_indexes(val, real_idxs)
return (latent,)
class SelectImages:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/image"
RETURN_TYPES = ("IMAGE",)
FUNCTION = "select"
def select(self, image: Tensor, indexes: str, err_if_missing: bool, err_if_empty: bool):
to_return = select_indexes_from_str(input_obj=image, indexes=indexes,
err_if_missing=err_if_missing, err_if_empty=err_if_empty)
to_return_type = type(to_return)
return (to_return,)
class SelectMasks:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask": ("MASK",),
"indexes": ("STRING", {"default": "0"}),
"err_if_missing": ("BOOLEAN", {"default": True}),
"err_if_empty": ("BOOLEAN", {"default": True}),
},
}
DESCRIPTION = select_description
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢/mask"
RETURN_TYPES = ("MASK",)
FUNCTION = "select"
def select(self, mask: Tensor, indexes: str, err_if_missing: bool, err_if_empty: bool):
return (select_indexes_from_str(input_obj=mask, indexes=indexes,
err_if_missing=err_if_missing, err_if_empty=err_if_empty),)
@@ -0,0 +1,111 @@
from PIL import Image
import time
import io
import struct
from threading import Thread
import torch.nn.functional as F
import torch
import latent_preview
import server
serv = server.PromptServer.instance
from .utils import hook
rates_table = {'Mochi': 24//6, 'LTXV': 24//8, 'HunyuanVideo': 24//4,
'Cosmos1CV8x8x8': 24//8, 'Wan21': 16//4, 'Wan22': 24//4}
class WrappedPreviewer(latent_preview.LatentPreviewer):
def __init__(self, previewer, rate=8):
self.first_preview = True
self.last_time = 0
self.c_index = 0
self.rate = rate
if hasattr(previewer, 'taesd'):
self.taesd = previewer.taesd
elif hasattr(previewer, 'latent_rgb_factors'):
self.latent_rgb_factors = previewer.latent_rgb_factors
self.latent_rgb_factors_bias = previewer.latent_rgb_factors_bias
else:
raise Exception('Unsupported preview type for VHS animated previews')
def decode_latent_to_preview_image(self, preview_format, x0):
if x0.ndim == 5:
#Keep batch major
x0 = x0.movedim(2,1)
x0 = x0.reshape((-1,)+x0.shape[-3:])
num_images = x0.size(0)
new_time = time.time()
num_previews = int((new_time - self.last_time) * self.rate)
self.last_time = self.last_time + num_previews/self.rate
if num_previews > num_images:
num_previews = num_images
elif num_previews <= 0:
return None
if self.first_preview:
self.first_preview = False
serv.send_sync('VHS_latentpreview', {'length':num_images, 'rate': self.rate, 'id': serv.last_node_id})
self.last_time = new_time + 1/self.rate
if self.c_index + num_previews > num_images:
x0 = x0.roll(-self.c_index, 0)[:num_previews]
else:
x0 = x0[self.c_index:self.c_index + num_previews]
Thread(target=self.process_previews, args=(x0, self.c_index,
num_images)).run()
self.c_index = (self.c_index + num_previews) % num_images
return None
def process_previews(self, image_tensor, ind, leng):
image_tensor = self.decode_latent_to_preview(image_tensor)
if image_tensor.size(1) > 512 or image_tensor.size(2) > 512:
image_tensor = image_tensor.movedim(-1,0)
if image_tensor.size(2) < image_tensor.size(3):
height = (512 * image_tensor.size(2)) // image_tensor.size(3)
image_tensor = F.interpolate(image_tensor, (height,512), mode='bilinear')
else:
width = (512 * image_tensor.size(3)) // image_tensor.size(2)
image_tensor = F.interpolate(image_tensor, (512, width), mode='bilinear')
image_tensor = image_tensor.movedim(0,-1)
previews_ubyte = (((image_tensor + 1.0) / 2.0).clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
).to(device="cpu", dtype=torch.uint8)
for preview in previews_ubyte:
i = Image.fromarray(preview.numpy())
message = io.BytesIO()
message.write((1).to_bytes(length=4, byteorder='big')*2)
message.write(ind.to_bytes(length=4, byteorder='big'))
message.write(struct.pack('16p', serv.last_node_id.encode('ascii')))
i.save(message, format="JPEG", quality=95, compress_level=1)
#NOTE: send sync already uses call_soon_threadsafe
serv.send_sync(server.BinaryEventTypes.PREVIEW_IMAGE,
message.getvalue(), serv.client_id)
ind = (ind + 1) % leng
def decode_latent_to_preview(self, x0):
if hasattr(self, 'taesd'):
x_sample = self.taesd.decode(x0).movedim(1, 3)
return x_sample
else:
self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device)
if self.latent_rgb_factors_bias is not None:
self.latent_rgb_factors_bias = self.latent_rgb_factors_bias.to(dtype=x0.dtype, device=x0.device)
latent_image = F.linear(x0.movedim(1, -1), self.latent_rgb_factors,
bias=self.latent_rgb_factors_bias)
return latent_image
@hook(latent_preview, 'get_previewer')
def get_latent_video_previewer(device, latent_format, *args, **kwargs):
node_id = serv.last_node_id
previewer = get_latent_video_previewer.__wrapped__(device, latent_format, *args, **kwargs)
try:
extra_info = next(serv.prompt_queue.currently_running.values().__iter__()) \
[3]['extra_pnginfo']['workflow']['extra']
prev_setting = extra_info.get('VHS_latentpreview', False)
if extra_info.get('VHS_latentpreviewrate', 0) != 0:
rate_setting = extra_info['VHS_latentpreviewrate']
else:
rate_setting = rates_table.get(latent_format.__class__.__name__, 8)
except:
#For safety since there's lots of keys, any of which can fail
prev_setting = False
if not prev_setting or not hasattr(previewer, "decode_latent_to_preview"):
return previewer
return WrappedPreviewer(previewer, rate_setting)
@@ -0,0 +1,206 @@
import os
import hashlib
import numpy as np
import torch
from PIL import Image, ImageOps
import itertools
import folder_paths
from comfy.k_diffusion.utils import FolderOfImages
from comfy.utils import common_upscale, ProgressBar
from .logger import logger
from .utils import BIGMAX, calculate_file_hash, get_sorted_dir_files_from_directory, validate_path, strip_path
def is_changed_load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, **kwargs):
if not os.path.isdir(directory):
return False
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if image_load_cap != 0:
dir_files = dir_files[:image_load_cap]
m = hashlib.sha256()
for filepath in dir_files:
m.update(calculate_file_hash(filepath).encode()) # strings must be encoded before hashing
return m.digest().hex()
def validate_load_images(directory: str):
if not os.path.isdir(directory):
return f"Directory '{directory}' cannot be found."
dir_files = os.listdir(directory)
if len(dir_files) == 0:
return f"No files in directory '{directory}'."
return True
def images_generator(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, meta_batch=None, unique_id=None):
if not os.path.isdir(directory):
raise FileNotFoundError(f"Directory '{directory} cannot be found.")
dir_files = get_sorted_dir_files_from_directory(directory, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if len(dir_files) == 0:
raise FileNotFoundError(f"No files in directory '{directory}'.")
if image_load_cap > 0:
dir_files = dir_files[:image_load_cap]
sizes = {}
has_alpha = False
for image_path in dir_files:
i = Image.open(image_path)
#exif_transpose can only ever rotate, but rotating can swap width/height
i = ImageOps.exif_transpose(i)
has_alpha |= 'A' in i.getbands()
count = sizes.get(i.size, 0)
sizes[i.size] = count +1
size = max(sizes.items(), key=lambda x: x[1])[0]
yield size[0], size[1], has_alpha
if meta_batch is not None:
yield min(image_load_cap, len(dir_files)) or len(dir_files)
iformat = "RGBA" if has_alpha else "RGB"
def load_image(file_path):
i = Image.open(file_path)
i = ImageOps.exif_transpose(i)
i = i.convert(iformat)
i = np.array(i, dtype=np.float32)
#This nonsense provides a nearly 50% speedup on my system
torch.from_numpy(i).div_(255)
if i.shape[0] != size[1] or i.shape[1] != size[0]:
i = torch.from_numpy(i).movedim(-1, 0).unsqueeze(0)
i = common_upscale(i, size[0], size[1], "lanczos", "center")
i = i.squeeze(0).movedim(0, -1).numpy()
if has_alpha:
i[:,:,-1] = 1 - i[:,:,-1]
return i
total_images = len(dir_files)
processed_images = 0
pbar = ProgressBar(total_images)
images = map(load_image, dir_files)
try:
prev_image = next(images)
while True:
next_image = next(images)
yield prev_image
processed_images += 1
pbar.update_absolute(processed_images, total_images)
prev_image = next_image
except StopIteration:
pass
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_image is not None:
yield prev_image
def load_images(directory: str, image_load_cap: int = 0, skip_first_images: int = 0, select_every_nth: int = 1, meta_batch=None, unique_id=None):
if meta_batch is None or unique_id not in meta_batch.inputs:
gen = images_generator(directory, image_load_cap, skip_first_images, select_every_nth, meta_batch, unique_id)
(width, height, has_alpha) = next(gen)
if meta_batch is not None:
meta_batch.inputs[unique_id] = (gen, width, height, has_alpha)
meta_batch.total_frames = min(meta_batch.total_frames, next(gen))
else:
gen, width, height, has_alpha = meta_batch.inputs[unique_id]
if meta_batch is not None:
gen = itertools.islice(gen, meta_batch.frames_per_batch)
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (height, width, 3 + has_alpha)))))
if has_alpha:
#tensors are not continuous. Rewrite will be required if this is an issue
masks = images[:,:,:,3]
images = images[:,:,:,:3]
else:
masks = torch.zeros((images.size(0), 64, 64), dtype=torch.float32, device="cpu")
if len(images) == 0:
raise FileNotFoundError(f"No images could be loaded from directory '{directory}'.")
return images, masks, images.size(0)
class LoadImagesFromDirectoryUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
directories = []
for item in os.listdir(input_dir):
if not os.path.isfile(os.path.join(input_dir, item)) and item != "clipspace":
directories.append(item)
return {
"required": {
"directory": (directories,),
},
"optional": {
"image_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"meta_batch": ("VHS_BatchManager",),
},
"hidden": {
"unique_id": "UNIQUE_ID"
},
}
RETURN_TYPES = ("IMAGE", "MASK", "INT")
RETURN_NAMES = ("IMAGE", "MASK", "frame_count")
FUNCTION = "load_images"
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
def load_images(self, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return load_images(directory, **kwargs)
@classmethod
def IS_CHANGED(s, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return is_changed_load_images(directory, **kwargs)
@classmethod
def VALIDATE_INPUTS(s, directory: str, **kwargs):
directory = folder_paths.get_annotated_filepath(strip_path(directory))
return validate_load_images(directory)
class LoadImagesFromDirectoryPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"directory": ("STRING", {"placeholder": "X://path/to/images", "vhs_path_extensions": []}),
},
"optional": {
"image_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"skip_first_images": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
"meta_batch": ("VHS_BatchManager",),
},
"hidden": {
"unique_id": "UNIQUE_ID"
},
}
RETURN_TYPES = ("IMAGE", "MASK", "INT")
RETURN_NAMES = ("IMAGE", "MASK", "frame_count")
FUNCTION = "load_images"
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
def load_images(self, directory: str, **kwargs):
directory = strip_path(directory)
if directory is None or validate_load_images(directory) != True:
raise Exception("directory is not valid: " + directory)
return load_images(directory, **kwargs)
@classmethod
def IS_CHANGED(s, directory: str, **kwargs):
if directory is None:
return "input"
return is_changed_load_images(directory, **kwargs)
@classmethod
def VALIDATE_INPUTS(s, directory: str, **kwargs):
if directory is None:
return True
return validate_load_images(strip_path(directory))
@@ -0,0 +1,671 @@
import os
import itertools
import numpy as np
import torch
from PIL import Image, ImageOps
import cv2
import psutil
import subprocess
import re
import time
import folder_paths
from comfy.utils import common_upscale, ProgressBar
import nodes
from comfy.k_diffusion.utils import FolderOfImages
from .logger import logger
from .utils import BIGMAX, DIMMAX, calculate_file_hash, get_sorted_dir_files_from_directory,\
lazy_get_audio, hash_path, validate_path, strip_path, try_download_video, \
is_url, imageOrLatent, ffmpeg_path, ENCODE_ARGS, floatOrInt
video_extensions = ['webm', 'mp4', 'mkv', 'gif', 'mov']
VHSLoadFormats = {
'None': {},
'AnimateDiff': {'target_rate': 8, 'dim': (8,0,512,512)},
'Mochi': {'target_rate': 24, 'dim': (16,0,848,480), 'frames':(6,1)},
'LTXV': {'target_rate': 24, 'dim': (32,0,768,512), 'frames':(8,1)},
'Hunyuan': {'target_rate': 24, 'dim': (16,0,848,480), 'frames':(4,1)},
'Cosmos': {'target_rate': 24, 'dim': (16,0,1280,704), 'frames':(8,1)},
'Wan': {'target_rate': 16, 'dim': (8,0,832,480), 'frames':(4,1)},
}
"""
External plugins may add additional formats to nodes.VHSLoadFormats
In addition to shorthand options, direct widget names will map a given dict to options.
Adding a third arguement to a frames tuple can enable strict checks on number
of loaded frames, i.e (8,1,True)
"""
if not hasattr(nodes, 'VHSLoadFormats'):
nodes.VHSLoadFormats = {}
def get_load_formats():
#TODO: check if {**extra_config.VHSLoafFormats, **VHSLoadFormats} has minimum version
formats = {}
formats.update(nodes.VHSLoadFormats)
formats.update(VHSLoadFormats)
return (list(formats.keys()),
{'default': 'AnimateDiff', 'formats': formats})
def get_format(format):
if format in VHSLoadFormats:
return VHSLoadFormats[format]
return nodes.VHSLoadFormats.get(format, {})
def is_gif(filename) -> bool:
file_parts = filename.split('.')
return len(file_parts) > 1 and file_parts[-1] == "gif"
def target_size(width, height, custom_width, custom_height, downscale_ratio=8) -> tuple[int, int]:
if downscale_ratio is None:
downscale_ratio = 8
if custom_width == 0 and custom_height == 0:
pass
elif custom_height == 0:
height *= custom_width/width
width = custom_width
elif custom_width == 0:
width *= custom_height/height
height = custom_height
else:
width = custom_width
height = custom_height
width = int(width/downscale_ratio + 0.5) * downscale_ratio
height = int(height/downscale_ratio + 0.5) * downscale_ratio
return (width, height)
def cv_frame_generator(video, force_rate, frame_load_cap, skip_first_frames,
select_every_nth, meta_batch=None, unique_id=None):
video_cap = cv2.VideoCapture(video)
if not video_cap.isOpened() or not video_cap.grab():
raise ValueError(f"{video} could not be loaded with cv.")
# extract video metadata
fps = video_cap.get(cv2.CAP_PROP_FPS)
width = int(video_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
total_frames = int(video_cap.get(cv2.CAP_PROP_FRAME_COUNT))
duration = total_frames / fps
width = 0
if width <=0 or height <=0:
_, frame = video_cap.retrieve()
height, width, _ = frame.shape
# set video_cap to look at start_index frame
total_frame_count = 0
total_frames_evaluated = -1
frames_added = 0
base_frame_time = 1 / fps
prev_frame = None
if force_rate == 0:
target_frame_time = base_frame_time
else:
target_frame_time = 1/force_rate
if total_frames > 0:
if force_rate != 0:
yieldable_frames = int(total_frames / fps * force_rate)
else:
yieldable_frames = total_frames
if select_every_nth:
yieldable_frames //= select_every_nth
if frame_load_cap != 0:
yieldable_frames = min(frame_load_cap, yieldable_frames)
else:
yieldable_frames = 0
yield (width, height, fps, duration, total_frames, target_frame_time, yieldable_frames)
pbar = ProgressBar(yieldable_frames)
time_offset=target_frame_time
while video_cap.isOpened():
if time_offset < target_frame_time:
is_returned = video_cap.grab()
# if didn't return frame, video has ended
if not is_returned:
break
time_offset += base_frame_time
if time_offset < target_frame_time:
continue
time_offset -= target_frame_time
# if not at start_index, skip doing anything with frame
total_frame_count += 1
if total_frame_count <= skip_first_frames:
continue
else:
total_frames_evaluated += 1
# if should not be selected, skip doing anything with frame
if total_frames_evaluated%select_every_nth != 0:
continue
# opencv loads images in BGR format (yuck), so need to convert to RGB for ComfyUI use
# follow up: can videos ever have an alpha channel?
# To my testing: No. opencv has no support for alpha
unused, frame = video_cap.retrieve()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# convert frame to comfyui's expected format
# TODO: frame contains no exif information. Check if opencv2 has already applied
frame = np.array(frame, dtype=np.float32)
torch.from_numpy(frame).div_(255)
if prev_frame is not None:
inp = yield prev_frame
if inp is not None:
#ensure the finally block is called
return
prev_frame = frame
frames_added += 1
if pbar is not None:
pbar.update_absolute(frames_added, yieldable_frames)
# if cap exists and we've reached it, stop processing frames
if frame_load_cap > 0 and frames_added >= frame_load_cap:
break
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_frame is not None:
yield prev_frame
def ffmpeg_frame_generator(video, force_rate, frame_load_cap, start_time,
custom_width, custom_height, downscale_ratio=8,
meta_batch=None, unique_id=None):
args_input = ["-i", video]
args_dummy = [ffmpeg_path] + args_input +['-c', 'copy', '-frames:v', '1', "-f", "null", "-"]
size_base = None
fps_base = None
try:
dummy_res = subprocess.run(args_dummy, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the ffmpeg subprocess:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
lines = dummy_res.stderr.decode(*ENCODE_ARGS)
if "Video: vp9 " in lines:
args_input = ["-c:v", "libvpx-vp9"] + args_input
args_dummy = [ffmpeg_path] + args_input +['-c', 'copy', '-frames:v', '1', "-f", "null", "-"]
try:
dummy_res = subprocess.run(args_dummy, stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE, check=True)
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the ffmpeg subprocess:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
lines = dummy_res.stderr.decode(*ENCODE_ARGS)
for line in lines.split('\n'):
match = re.search("^ *Stream .* Video.*, ([1-9]|\\d{2,})x(\\d+)", line)
if match is not None:
size_base = [int(match.group(1)), int(match.group(2))]
fps_match = re.search(", ([\\d\\.]+) fps", line)
if fps_match:
fps_base = float(fps_match.group(1))
else:
fps_base = 1
alpha = re.search("(yuva|rgba|bgra)", line) is not None
break
else:
raise Exception("Failed to parse video/image information. FFMPEG output:\n" + lines)
durs_match = re.search("Duration: (\\d+:\\d+:\\d+\\.\\d+),", lines)
if durs_match:
durs = durs_match.group(1).split(':')
duration = int(durs[0])*3600 + int(durs[1])*60 + float(durs[2])
else:
duration = 0
if start_time > 0:
if start_time > 4:
post_seek = ['-ss', '4']
args_input = ['-ss', str(start_time - 4)] + args_input
else:
post_seek = ['-ss', str(start_time)]
else:
post_seek = []
args_all_frames = [ffmpeg_path, "-v", "error", "-an"] + \
args_input + ["-pix_fmt", "rgba64le"] + post_seek
vfilters = []
if force_rate != 0:
vfilters.append("fps=fps="+str(force_rate))
if custom_width != 0 or custom_height != 0:
size = target_size(size_base[0], size_base[1], custom_width,
custom_height, downscale_ratio=downscale_ratio)
ar = float(size[0])/float(size[1])
if abs(size_base[0]*ar-size_base[1]) >= 1:
#Aspect ratio is changed. Crop to new aspect ratio before scale
vfilters.append(f"crop=if(gt({ar}\\,a)\\,iw\\,ih*{ar}):if(gt({ar}\\,a)\\,iw/{ar}\\,ih)")
size_arg = ':'.join(map(str,size))
vfilters.append(f"scale={size_arg}")
else:
size = size_base
if len(vfilters) > 0:
args_all_frames += ["-vf", ",".join(vfilters)]
yieldable_frames = (force_rate or fps_base)*duration
if frame_load_cap > 0:
args_all_frames += ["-frames:v", str(frame_load_cap)]
yieldable_frames = min(yieldable_frames, frame_load_cap)
yield (size_base[0], size_base[1], fps_base, duration, fps_base * duration,
1/(force_rate or fps_base), yieldable_frames, size[0], size[1], alpha)
args_all_frames += ["-f", "rawvideo", "-"]
pbar = ProgressBar(yieldable_frames)
try:
with subprocess.Popen(args_all_frames, stdout=subprocess.PIPE) as proc:
#Manually buffer enough bytes for an image
bpi = size[0] * size[1] * 8
current_bytes = bytearray(bpi)
current_offset=0
prev_frame = None
while True:
bytes_read = proc.stdout.read(bpi - current_offset)
if bytes_read is None:#sleep to wait for more data
time.sleep(.1)
continue
if len(bytes_read) == 0:#EOF
break
current_bytes[current_offset:len(bytes_read)] = bytes_read
current_offset+=len(bytes_read)
if current_offset == bpi:
if prev_frame is not None:
yield prev_frame
pbar.update(1)
prev_frame = np.frombuffer(current_bytes, dtype=np.dtype(np.uint16).newbyteorder("<")).reshape(size[1], size[0], 4) / (2**16-1)
if not alpha:
prev_frame = prev_frame[:, :, :-1]
current_offset = 0
except BrokenPipeError as e:
raise Exception("An error occured in the ffmpeg subprocess:\n" \
+ proc.stderr.read().decode(*ENCODE_ARGS))
if meta_batch is not None:
meta_batch.inputs.pop(unique_id)
meta_batch.has_closed_inputs = True
if prev_frame is not None:
yield prev_frame
#Python 3.12 adds an itertools.batched, but it's easily replicated for legacy support
def batched(it, n):
while batch := tuple(itertools.islice(it, n)):
yield batch
def batched_vae_encode(images, vae, frames_per_batch):
for batch in batched(images, frames_per_batch):
image_batch = torch.from_numpy(np.array(batch))
yield from vae.encode(image_batch).numpy()
def resized_cv_frame_gen(custom_width, custom_height, downscale_ratio, **kwargs):
gen = cv_frame_generator(**kwargs)
info = next(gen)
width, height = info[0], info[1]
frames_per_batch = (1920 * 1080 * 16) // (width * height) or 1
if kwargs.get('meta_batch', None) is not None:
frames_per_batch = min(frames_per_batch, kwargs['meta_batch'].frames_per_batch)
if custom_width != 0 or custom_height != 0 or downscale_ratio is not None:
new_size = target_size(width, height, custom_width, custom_height, downscale_ratio)
yield (*info, new_size[0], new_size[1], False)
if new_size[0] != width or new_size[1] != height:
def rescale(frame):
s = torch.from_numpy(np.fromiter(frame, np.dtype((np.float32, (height, width, 3)))))
s = s.movedim(-1,1)
s = common_upscale(s, new_size[0], new_size[1], "lanczos", "center")
return s.movedim(1,-1).numpy()
yield from itertools.chain.from_iterable(map(rescale, batched(gen, frames_per_batch)))
return
else:
yield (*info, info[0], info[1], False)
yield from gen
def load_video(meta_batch=None, unique_id=None, memory_limit_mb=None, vae=None,
generator=resized_cv_frame_gen, format='None', **kwargs):
if 'force_size' in kwargs:
kwargs.pop('force_size')
logger.warn("force_size has been removed. Did you reload the webpage after updating?")
format = get_format(format)
kwargs['video'] = strip_path(kwargs['video'])
if vae is not None:
downscale_ratio = getattr(vae, "downscale_ratio", 8)
else:
downscale_ratio = format.get('dim', (1,))[0]
if meta_batch is None or unique_id not in meta_batch.inputs:
gen = generator(meta_batch=meta_batch, unique_id=unique_id, downscale_ratio=downscale_ratio, **kwargs)
(width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha) = next(gen)
if meta_batch is not None:
meta_batch.inputs[unique_id] = (gen, width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha)
if yieldable_frames:
meta_batch.total_frames = min(meta_batch.total_frames, yieldable_frames)
else:
(gen, width, height, fps, duration, total_frames, target_frame_time, yieldable_frames, new_width, new_height, alpha) = meta_batch.inputs[unique_id]
memory_limit = None
if memory_limit_mb is not None:
memory_limit *= 2 ** 20
else:
#TODO: verify if garbage collection should be performed here.
#leaves ~128 MB unreserved for safety
try:
memory_limit = (psutil.virtual_memory().available + psutil.swap_memory().free) - 2 ** 27
except:
logger.warn("Failed to calculate available memory. Memory load limit has been disabled")
memory_limit = BIGMAX
if vae is not None:
#space required to load as f32, exist as latent with wiggle room, decode to f32
max_loadable_frames = int(memory_limit//(width*height*3*(4+4+1/10)))
else:
#TODO: use better estimate for when vae is not None
#Consider completely ignoring for load_latent case?
max_loadable_frames = int(memory_limit//(width*height*3*(.1)))
if meta_batch is not None:
if 'frames' in format:
if meta_batch.frames_per_batch % format['frames'][0] != format['frames'][1]:
error = (meta_batch.frames_per_batch - format['frames'][1]) % format['frames'][0]
suggested = meta_batch.frames_per_batch - error
if error > format['frames'][0] / 2:
suggested += format['frames'][0]
raise RuntimeError(f"The chosen frames per batch is incompatible with the selected format. Try {suggested}")
if meta_batch.frames_per_batch > max_loadable_frames:
raise RuntimeError(f"Meta Batch set to {meta_batch.frames_per_batch} frames but only {max_loadable_frames} can fit in memory")
gen = itertools.islice(gen, meta_batch.frames_per_batch)
else:
original_gen = gen
gen = itertools.islice(gen, max_loadable_frames)
frames_per_batch = (1920 * 1080 * 16) // (width * height) or 1
if vae is not None:
gen = batched_vae_encode(gen, vae, frames_per_batch)
vw,vh = new_width//downscale_ratio, new_height//downscale_ratio
channels = getattr(vae, 'latent_channels', 4)
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (channels,vh,vw)))))
else:
#Some minor wizardry to eliminate a copy and reduce max memory by a factor of ~2
images = torch.from_numpy(np.fromiter(gen, np.dtype((np.float32, (new_height, new_width, 4 if alpha else 3)))))
if meta_batch is None and memory_limit is not None:
try:
next(original_gen)
raise RuntimeError(f"Memory limit hit after loading {len(images)} frames. Stopping execution.")
except StopIteration:
pass
if len(images) == 0:
raise RuntimeError("No frames generated")
if 'frames' in format and len(images) % format['frames'][0] != format['frames'][1]:
err_msg = f"The number of frames loaded {len(images)}, does not match the requirements of the currently selected format."
if len(format['frames']) > 2 and format['frames'][2]:
raise RuntimeError(err_msg)
div, mod = format['frames'][:2]
frames = (len(images) - mod) // div * div + mod
images = images[:frames]
#Commenting out log message since it's displayed in UI. consider further
#logger.warn(err_msg + f" Output has been truncated to {len(images)} frames.")
if 'start_time' in kwargs:
start_time = kwargs['start_time']
else:
start_time = kwargs['skip_first_frames'] * target_frame_time
target_frame_time *= kwargs.get('select_every_nth', 1)
#Setup lambda for lazy audio capture
audio = lazy_get_audio(kwargs['video'], start_time, kwargs['frame_load_cap']*target_frame_time)
#Adjust target_frame_time for select_every_nth
video_info = {
"source_fps": fps,
"source_frame_count": total_frames,
"source_duration": duration,
"source_width": width,
"source_height": height,
"loaded_fps": 1/target_frame_time,
"loaded_frame_count": len(images),
"loaded_duration": len(images) * target_frame_time,
"loaded_width": new_width,
"loaded_height": new_height,
}
if vae is None:
return (images, len(images), audio, video_info)
else:
return ({"samples": images}, len(images), audio, video_info)
class LoadVideoUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = []
for f in os.listdir(input_dir):
if os.path.isfile(os.path.join(input_dir, f)):
file_parts = f.split('.')
if len(file_parts) > 1 and (file_parts[-1].lower() in video_extensions):
files.append(f)
return {"required": {
"video": (sorted(files),),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"skip_first_frames": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
kwargs['video'] = folder_paths.get_annotated_filepath(strip_path(kwargs['video']))
return load_video(**kwargs)
@classmethod
def IS_CHANGED(s, video, **kwargs):
image_path = folder_paths.get_annotated_filepath(video)
return calculate_file_hash(image_path)
@classmethod
def VALIDATE_INPUTS(s, video):
if not folder_paths.exists_annotated_filepath(video):
return "Invalid video file: {}".format(video)
return True
class LoadVideoPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"video": ("STRING", {"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"skip_first_frames": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
if kwargs['video'] is None or validate_path(kwargs['video']) != True:
raise Exception("video is not a valid path: " + kwargs['video'])
if is_url(kwargs['video']):
kwargs['video'] = try_download_video(kwargs['video']) or kwargs['video']
return load_video(**kwargs)
@classmethod
def IS_CHANGED(s, video, **kwargs):
return hash_path(video)
@classmethod
def VALIDATE_INPUTS(s, video):
return validate_path(video, allow_none=True)
class LoadVideoFFmpegUpload:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = []
for f in os.listdir(input_dir):
if os.path.isfile(os.path.join(input_dir, f)):
file_parts = f.split('.')
if len(file_parts) > 1 and (file_parts[-1].lower() in video_extensions):
files.append(f)
return {"required": {
"video": (sorted(files),),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"start_time": ("FLOAT", {"default": 0, "min": 0, "max": BIGMAX, "step": .001, "widgetType": "VHSTIMESTAMP"}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "mask", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
kwargs['video'] = folder_paths.get_annotated_filepath(strip_path(kwargs['video']))
image, _, audio, video_info = load_video(**kwargs, generator=ffmpeg_frame_generator)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3], audio, video_info)
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"), audio, video_info)
@classmethod
def IS_CHANGED(s, video, **kwargs):
image_path = folder_paths.get_annotated_filepath(video)
return calculate_file_hash(image_path)
@classmethod
def VALIDATE_INPUTS(s, video):
if not folder_paths.exists_annotated_filepath(video):
return "Invalid video file: {}".format(video)
return True
class LoadVideoFFmpegPath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"video": ("STRING", {"placeholder": "X://insert/path/here.mp4", "vhs_path_extensions": video_extensions}),
"force_rate": (floatOrInt, {"default": 0, "min": 0, "max": 60, "step": 1, "disable": 0}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, 'disable': 0}),
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1, "disable": 0}),
"start_time": ("FLOAT", {"default": 0, "min": 0, "max": BIGMAX, "step": .001, "widgetType": "VHSTIMESTAMP"}),
},
"optional": {
"meta_batch": ("VHS_BatchManager",),
"vae": ("VAE",),
"format": get_load_formats(),
},
"hidden": {
"force_size": "STRING",
"unique_id": "UNIQUE_ID"
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK", "AUDIO", "VHS_VIDEOINFO")
RETURN_NAMES = ("IMAGE", "mask", "audio", "video_info")
FUNCTION = "load_video"
def load_video(self, **kwargs):
if kwargs['video'] is None or validate_path(kwargs['video']) != True:
raise Exception("video is not a valid path: " + kwargs['video'])
if is_url(kwargs['video']):
kwargs['video'] = try_download_video(kwargs['video']) or kwargs['video']
image, _, audio, video_info = load_video(**kwargs, generator=ffmpeg_frame_generator)
if isinstance(image, dict):
return (image, None, audio, video_info)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3], audio, video_info)
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"), audio, video_info)
@classmethod
def IS_CHANGED(s, video, **kwargs):
return hash_path(video)
@classmethod
def VALIDATE_INPUTS(s, video):
return validate_path(video, allow_none=True)
class LoadImagePath:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("STRING", {"placeholder": "X://insert/path/here.png", "vhs_path_extensions": list(FolderOfImages.IMG_EXTENSIONS)}),
"custom_width": ("INT", {"default": 0, "min": 0, "max": DIMMAX, "step": 8, 'disable': 0}),
"custom_height": ("INT", {"default": 0, "min": 0, "max": DIMMAX, "step": 8, 'disable': 0}),
},
"optional": {
"vae": ("VAE",),
},
"hidden": {
"force_size": "STRING",
},
}
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
RETURN_TYPES = (imageOrLatent, "MASK")
RETURN_NAMES = ("IMAGE", "mask")
FUNCTION = "load_image"
def load_image(self, **kwargs):
if kwargs['image'] is None or validate_path(kwargs['image']) != True:
raise Exception("image is not a valid path: " + kwargs['image'])
kwargs.update({'video': kwargs['image'], 'force_rate': 0, 'frame_load_cap': 0,
'start_time': 0})
kwargs.pop('image')
image, _, _, _ = load_video(**kwargs, generator=ffmpeg_frame_generator)
if isinstance(image, dict):
return (image, None)
if image.size(3) == 4:
return (image[:,:,:,:3], 1-image[:,:,:,3])
return (image, torch.zeros(image.size(0), 64, 64, device="cpu"))
@classmethod
def IS_CHANGED(s, image, **kwargs):
return hash_path(image)
@classmethod
def VALIDATE_INPUTS(s, image):
return validate_path(image, allow_none=True)
@@ -0,0 +1,36 @@
import sys
import copy
import logging
class ColoredFormatter(logging.Formatter):
COLORS = {
"DEBUG": "\033[0;36m", # CYAN
"INFO": "\033[0;32m", # GREEN
"WARNING": "\033[0;33m", # YELLOW
"ERROR": "\033[0;31m", # RED
"CRITICAL": "\033[0;37;41m", # WHITE ON RED
"RESET": "\033[0m", # RESET COLOR
}
def format(self, record):
colored_record = copy.copy(record)
levelname = colored_record.levelname
seq = self.COLORS.get(levelname, self.COLORS["RESET"])
colored_record.levelname = f"{seq}{levelname}{self.COLORS['RESET']}"
return super().format(colored_record)
# Create a new logger
logger = logging.getLogger("VideoHelperSuite")
logger.propagate = False
# Add handler if we don't have one.
if not logger.handlers:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(ColoredFormatter("[%(name)s] - %(levelname)s - %(message)s"))
logger.addHandler(handler)
# Configure logger
loglevel = logging.INFO
logger.setLevel(loglevel)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,294 @@
import server
import folder_paths
import os
import subprocess
import re
import asyncio
import av
from .utils import is_url, get_sorted_dir_files_from_directory, ffmpeg_path, \
validate_sequence, is_safe_path, strip_path, try_download_video, ENCODE_ARGS
from comfy.k_diffusion.utils import FolderOfImages
web = server.web
@server.PromptServer.instance.routes.get("/vhs/viewvideo")
@server.PromptServer.instance.routes.get("/viewvideo")
async def view_video(request):
query = request.rel_url.query
path_res = await resolve_path(query)
if isinstance(path_res, web.Response):
return path_res
file, filename, output_dir = path_res
if ffmpeg_path is None:
#Don't just return file, that provides arbitrary read access to any file
if is_safe_path(output_dir, strict=True):
return web.FileResponse(path=file)
frame_rate = query.get('frame_rate', 8)
if query.get('format', 'video') == "folder":
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
concat_file = os.path.join(folder_paths.get_temp_directory(), "image_sequence_preview.txt")
skip_first_images = int(query.get('skip_first_images', 0))
select_every_nth = int(query.get('select_every_nth', 1)) or 1
valid_images = get_sorted_dir_files_from_directory(file, skip_first_images, select_every_nth, FolderOfImages.IMG_EXTENSIONS)
if len(valid_images) == 0:
return web.Response(status=204)
with open(concat_file, "w") as f:
f.write("ffconcat version 1.0\n")
for path in valid_images:
f.write("file '" + os.path.abspath(path) + "'\n")
f.write("duration 0.125\n")
in_args = ["-safe", "0", "-i", concat_file]
else:
in_args = ["-i", file]
if '%' in file:
in_args = ['-framerate', str(frame_rate)] + in_args
#Do prepass to pull info
#breaks skip_first frames if this default is ever actually needed
base_fps = 30
try:
proc = await asyncio.create_subprocess_exec(ffmpeg_path, *in_args, '-t',
'0','-f', 'null','-', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
_, res_stderr = await proc.communicate()
match = re.search(': Video: (\\w+) .+, (\\d+) fps,', res_stderr.decode(*ENCODE_ARGS))
if match:
base_fps = float(match.group(2))
if match.group(1) == 'vp9':
#force libvpx for transparency
in_args = ['-c:v', 'libvpx-vp9'] + in_args
except subprocess.CalledProcessError as e:
print("An error occurred in the ffmpeg prepass:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
return web.Response(status=500)
vfilters = []
target_rate = float(query.get('force_rate', 0)) or base_fps
modified_rate = target_rate / (float(query.get('select_every_nth',1)) or 1)
start_time = 0
if 'start_time' in query:
start_time = float(query['start_time'])
elif float(query.get('skip_first_frames', 0)) > 0:
start_time = float(query.get('skip_first_frames'))/target_rate
if start_time > 1/modified_rate:
start_time += 1/modified_rate
if start_time > 0:
if start_time > 4:
post_seek = ['-ss', '4']
pre_seek = ['-ss', str(start_time - 4)]
else:
post_seek = ['-ss', str(start_time)]
pre_seek = []
else:
pre_seek = []
post_seek = []
args = [ffmpeg_path, "-v", "error"] + pre_seek + in_args + post_seek
if target_rate != 0:
args += ['-r', str(modified_rate)]
if query.get('force_size','Disabled') != "Disabled":
size = query['force_size'].split('x')
if size[0] == '?' or size[1] == '?':
size[0] = "-2" if size[0] == '?' else f"'min({size[0]},iw)'"
size[1] = "-2" if size[1] == '?' else f"'min({size[1]},ih)'"
else:
#Aspect ratio is likely changed. A more complex command is required
#to crop the output to the new aspect ratio
ar = float(size[0])/float(size[1])
vfilters.append(f"crop=if(gt({ar}\\,a)\\,iw\\,ih*{ar}):if(gt({ar}\\,a)\\,iw/{ar}\\,ih)")
size = ':'.join(size)
vfilters.append(f"scale={size}")
if len(vfilters) > 0:
args += ["-vf", ",".join(vfilters)]
if float(query.get('frame_load_cap', 0)) > 0:
args += ["-frames:v", query['frame_load_cap'].split('.')[0]]
#TODO:reconsider adding high frame cap/setting default frame cap on node
if query.get('deadline', 'realtime') == 'good':
deadline = 'good'
else:
deadline = 'realtime'
args += ['-c:v', 'libvpx-vp9','-deadline', deadline, '-cpu-used', '8', '-f', 'webm', '-']
try:
proc = await asyncio.create_subprocess_exec(*args, stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL)
try:
resp = web.StreamResponse()
resp.content_type = 'video/webm'
resp.headers["Content-Disposition"] = f"filename=\"{filename}\""
await resp.prepare(request)
while len(bytes_read := await proc.stdout.read(2**20)) != 0:
await resp.write(bytes_read)
#Of dubious value given frequency of kill calls, but more correct
await proc.wait()
except (ConnectionResetError, ConnectionError) as e:
proc.kill()
except BrokenPipeError as e:
pass
return resp
@server.PromptServer.instance.routes.get("/vhs/viewaudio")
async def view_audio(request):
query = request.rel_url.query
path_res = await resolve_path(query)
if isinstance(path_res, web.Response):
return path_res
file, filename, output_dir = path_res
if ffmpeg_path is None:
#Don't just return file, that provides arbitrary read access to any file
if is_safe_path(output_dir, strict=True):
return web.FileResponse(path=file)
in_args = ["-i", file]
start_time = 0
if 'start_time' in query:
start_time = float(query['start_time'])
args = [ffmpeg_path, "-v", "error", '-vn'] + in_args + ['-ss', str(start_time)]
if float(query.get('duration', 0)) > 0:
args += ['-t', str(query['duration'])]
if query.get('deadline', 'realtime') == 'good':
deadline = 'good'
else:
deadline = 'realtime'
args += ['-c:a', 'libopus','-deadline', deadline, '-cpu-used', '8', '-f', 'webm', '-']
try:
proc = await asyncio.create_subprocess_exec(*args, stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL)
try:
resp = web.StreamResponse()
resp.content_type = 'audio/webm'
resp.headers["Content-Disposition"] = f"filename=\"{filename}\""
await resp.prepare(request)
while len(bytes_read := await proc.stdout.read(2**20)) != 0:
await resp.write(bytes_read)
#Of dubious value given frequency of kill calls, but more correct
await proc.wait()
except (ConnectionResetError, ConnectionError) as e:
proc.kill()
except BrokenPipeError as e:
pass
return resp
query_cache = {}
@server.PromptServer.instance.routes.get("/vhs/queryvideo")
async def query_video(request):
query = request.rel_url.query
filepath = await resolve_path(query)
#TODO: cache lookup
if isinstance(filepath, web.Response):
return filepath
filepath = filepath[0]
if filepath.endswith(".webp"):
# ffmpeg doesn't support decoding animated WebP https://trac.ffmpeg.org/ticket/4907
return web.json_response({})
if filepath in query_cache and query_cache[filepath][0] == os.stat(filepath).st_mtime:
source = query_cache[filepath][1]
else:
source = {}
try:
with av.open(filepath) as cont:
stream = cont.streams.video[0]
source['fps'] = float(stream.average_rate)
source['duration'] = float(cont.duration / av.time_base)
if stream.codec_context.name == 'vp9':
cc = av.Codec('libvpx-vp9', 'r').create()
else:
cc = stream
def fit():
for packet in cont.demux(video=0):
yield from cc.decode(packet)
frame = next(fit())
source['size'] = [frame.width, frame.height]
source['alpha'] = 'a' in frame.format.name
source['frames'] = stream.metadata.get('NUMBER_OF_FRAMES', round(source['duration'] * source['fps']))
query_cache[filepath] = (os.stat(filepath).st_mtime, source)
except Exception:
pass
if not 'frames' in source:
return web.json_response({})
loaded = {}
loaded['duration'] = source['duration']
loaded['duration'] -= float(query.get('start_time',0))
loaded['fps'] = float(query.get('force_rate', 0)) or source.get('fps',1)
loaded['duration'] -= int(query.get('skip_first_frames', 0)) / loaded['fps']
loaded['fps'] /= int(query.get('select_every_nth', 1)) or 1
loaded['frames'] = round(loaded['duration'] * loaded['fps'])
return web.json_response({'source': source, 'loaded': loaded})
async def resolve_path(query):
if "filename" not in query:
return web.Response(status=204)
filename = query["filename"]
#Path code misformats urls on windows and must be skipped
if is_url(filename):
file = await asyncio.to_thread(try_download_video, filename) or file
filname, output_dir = os.path.split(file)
return file, filename, output_dir
else:
filename, output_dir = folder_paths.annotated_filepath(filename)
type = query.get("type", "output")
if type == "path":
#special case for path_based nodes
#NOTE: output_dir may be empty, but non-None
output_dir, filename = os.path.split(strip_path(filename))
if output_dir is None:
output_dir = folder_paths.get_directory_by_type(type)
if output_dir is None:
return web.Response(status=204)
if not is_safe_path(output_dir):
return web.Response(status=204)
if "subfolder" in query:
output_dir = os.path.join(output_dir, query["subfolder"])
filename = os.path.basename(filename)
file = os.path.join(output_dir, filename)
if not os.path.exists(file):
return web.Response(status=204)
if query.get('format', 'video') == 'folder':
if not os.path.isdir(file):
return web.Response(status=204)
else:
if not os.path.isfile(file) and not validate_sequence(file):
return web.Response(status=204)
return file, filename, output_dir
@server.PromptServer.instance.routes.get("/vhs/getpath")
@server.PromptServer.instance.routes.get("/getpath")
async def get_path(request):
query = request.rel_url.query
if "path" not in query:
return web.Response(status=204)
#NOTE: path always ends in `/`, so this is functionally an lstrip
path = os.path.abspath(strip_path(query["path"]))
if not os.path.exists(path) or not is_safe_path(path):
return web.json_response([])
#Use get so None is default instead of keyerror
valid_extensions = query.get("extensions")
valid_items = []
for item in os.scandir(path):
try:
if item.is_dir():
valid_items.append(item.name + "/")
continue
if valid_extensions is None or item.name.split(".")[-1].lower() in valid_extensions:
valid_items.append(item.name)
except OSError:
#Broken symlinks can throw a very unhelpful "Invalid argument"
pass
valid_items.sort(key=lambda f: os.stat(os.path.join(path,f)).st_mtime)
return web.json_response(valid_items)
@@ -0,0 +1,426 @@
import hashlib
import os
from typing import Iterable
import shutil
import subprocess
import re
import time
from collections.abc import Mapping
from typing import Union
import functools
import torch
from torch import Tensor
import server
from .logger import logger
import folder_paths
BIGMIN = -(2**53-1)
BIGMAX = (2**53-1)
DIMMAX = 8192
ENCODE_ARGS = ("utf-8", 'backslashreplace')
def ffmpeg_suitability(path):
try:
version = subprocess.run([path, "-version"], check=True,
capture_output=True).stdout.decode(*ENCODE_ARGS)
except:
return 0
score = 0
#rough layout of the importance of various features
simple_criterion = [("libvpx", 20),("264",10), ("265",3),
("svtav1",5),("libopus", 1)]
for criterion in simple_criterion:
if version.find(criterion[0]) >= 0:
score += criterion[1]
#obtain rough compile year from copyright information
copyright_index = version.find('2000-2')
if copyright_index >= 0:
copyright_year = version[copyright_index+6:copyright_index+9]
if copyright_year.isnumeric():
score += int(copyright_year)
return score
class MultiInput(str):
def __new__(cls, string, allowed_types="*"):
res = super().__new__(cls, string)
res.allowed_types=allowed_types
return res
def __ne__(self, other):
if self.allowed_types == "*" or other == "*":
return False
return other not in self.allowed_types
imageOrLatent = MultiInput("IMAGE", ["IMAGE", "LATENT"])
floatOrInt = MultiInput("FLOAT", ["FLOAT", "INT"])
class ContainsAll(dict):
def __contains__(self, other):
return True
def __getitem__(self, key):
return super().get(key, (None, {}))
if "VHS_FORCE_FFMPEG_PATH" in os.environ:
ffmpeg_path = os.environ.get("VHS_FORCE_FFMPEG_PATH")
else:
ffmpeg_paths = []
try:
from imageio_ffmpeg import get_ffmpeg_exe
imageio_ffmpeg_path = get_ffmpeg_exe()
ffmpeg_paths.append(imageio_ffmpeg_path)
except:
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
raise
logger.warn("Failed to import imageio_ffmpeg")
if "VHS_USE_IMAGEIO_FFMPEG" in os.environ:
ffmpeg_path = imageio_ffmpeg_path
else:
system_ffmpeg = shutil.which("ffmpeg")
if system_ffmpeg is not None:
ffmpeg_paths.append(system_ffmpeg)
if os.path.isfile("ffmpeg"):
ffmpeg_paths.append(os.path.abspath("ffmpeg"))
if os.path.isfile("ffmpeg.exe"):
ffmpeg_paths.append(os.path.abspath("ffmpeg.exe"))
if len(ffmpeg_paths) == 0:
logger.error("No valid ffmpeg found.")
ffmpeg_path = None
elif len(ffmpeg_paths) == 1:
#Evaluation of suitability isn't required, can take sole option
#to reduce startup time
ffmpeg_path = ffmpeg_paths[0]
else:
ffmpeg_path = max(ffmpeg_paths, key=ffmpeg_suitability)
gifski_path = os.environ.get("VHS_GIFSKI", None)
if gifski_path is None:
gifski_path = os.environ.get("JOV_GIFSKI", None)
if gifski_path is None:
gifski_path = shutil.which("gifski")
ytdl_path = os.environ.get("VHS_YTDL", None) or shutil.which('yt-dlp') \
or shutil.which('youtube-dl')
download_history = {}
def try_download_video(url):
if ytdl_path is None:
return None
if url in download_history:
return download_history[url]
os.makedirs(folder_paths.get_temp_directory(), exist_ok=True)
#Format information could be added to only download audio for Load Audio,
#but this gets hairy if same url is also used for video.
#Best to just always keep defaults
#dl_format = ['-f', 'ba'] if is_audio else []
try:
res = subprocess.run([ytdl_path, "--print", "after_move:filepath",
"-P", folder_paths.get_temp_directory(), url],
capture_output=True, check=True)
#strip newline
file = res.stdout.decode(*ENCODE_ARGS)[:-1]
except subprocess.CalledProcessError as e:
raise Exception("An error occurred in the yt-dl process:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
file = None
download_history[url] = file
return file
def is_safe_path(path, strict=False):
if "VHS_STRICT_PATHS" not in os.environ and not strict:
return True
basedir = os.path.abspath('.')
try:
common_path = os.path.commonpath([basedir, path])
except:
#Different drive on windows
return False
return common_path == basedir
def get_sorted_dir_files_from_directory(directory: str, skip_first_images: int=0, select_every_nth: int=1, extensions: Iterable=None):
directory = strip_path(directory)
dir_files = os.listdir(directory)
dir_files = sorted(dir_files)
dir_files = [os.path.join(directory, x) for x in dir_files]
dir_files = list(filter(lambda filepath: os.path.isfile(filepath), dir_files))
# filter by extension, if needed
if extensions is not None:
extensions = list(extensions)
new_dir_files = []
for filepath in dir_files:
ext = "." + filepath.split(".")[-1]
if ext.lower() in extensions:
new_dir_files.append(filepath)
dir_files = new_dir_files
# start at skip_first_images
dir_files = dir_files[skip_first_images:]
dir_files = dir_files[0::select_every_nth]
return dir_files
# modified from https://stackoverflow.com/questions/22058048/hashing-a-file-in-python
def calculate_file_hash(filename: str, hash_every_n: int = 1):
#Larger video files were taking >.5 seconds to hash even when cached,
#so instead the modified time from the filesystem is used as a hash
h = hashlib.sha256()
h.update(filename.encode())
h.update(str(os.path.getmtime(filename)).encode())
return h.hexdigest()
prompt_queue = server.PromptServer.instance.prompt_queue
def requeue_workflow_unchecked():
"""Requeues the current workflow without checking for multiple requeues"""
currently_running = prompt_queue.currently_running
(_, _, prompt, extra_data, outputs_to_execute) = next(iter(currently_running.values()))
#Ensure batch_managers are marked stale
prompt = prompt.copy()
for uid in prompt:
if prompt[uid]['class_type'] == 'VHS_BatchManager':
prompt[uid]['inputs']['requeue'] = prompt[uid]['inputs'].get('requeue',0)+1
#execution.py has guards for concurrency, but server doesn't.
#TODO: Check that this won't be an issue
number = -server.PromptServer.instance.number
server.PromptServer.instance.number += 1
prompt_id = str(server.uuid.uuid4())
prompt_queue.put((number, prompt_id, prompt, extra_data, outputs_to_execute))
requeue_guard = [None, 0, 0, {}]
def requeue_workflow(requeue_required=(-1,True)):
assert(len(prompt_queue.currently_running) == 1)
global requeue_guard
(run_number, _, prompt, _, _) = next(iter(prompt_queue.currently_running.values()))
if requeue_guard[0] != run_number:
#Calculate a count of how many outputs are managed by a batch manager
managed_outputs=0
for bm_uid in prompt:
if prompt[bm_uid]['class_type'] == 'VHS_BatchManager':
for output_uid in prompt:
if prompt[output_uid]['class_type'] in ["VHS_VideoCombine"]:
for inp in prompt[output_uid]['inputs'].values():
if inp == [bm_uid, 0]:
managed_outputs+=1
requeue_guard = [run_number, 0, managed_outputs, {}]
requeue_guard[1] = requeue_guard[1]+1
requeue_guard[3][requeue_required[0]] = requeue_required[1]
if requeue_guard[1] == requeue_guard[2] and max(requeue_guard[3].values()):
requeue_workflow_unchecked()
def get_audio(file, start_time=0, duration=0):
args = [ffmpeg_path, "-i", file]
if start_time > 0:
args += ["-ss", str(start_time)]
if duration > 0:
args += ["-t", str(duration)]
try:
#TODO: scan for sample rate and maintain
res = subprocess.run(args + ["-f", "f32le", "-"],
capture_output=True, check=True)
audio = torch.frombuffer(bytearray(res.stdout), dtype=torch.float32)
match = re.search(', (\\d+) Hz, (\\w+), ',res.stderr.decode(*ENCODE_ARGS))
except subprocess.CalledProcessError as e:
raise Exception(f"VHS failed to extract audio from {file}:\n" \
+ e.stderr.decode(*ENCODE_ARGS))
if match:
ar = int(match.group(1))
#NOTE: Just throwing an error for other channel types right now
#Will deal with issues if they come
ac = {"mono": 1, "stereo": 2}[match.group(2)]
else:
ar = 44100
ac = 2
audio = audio.reshape((-1,ac)).transpose(0,1).unsqueeze(0)
return {'waveform': audio, 'sample_rate': ar}
class LazyAudioMap(Mapping):
def __init__(self, file, start_time, duration):
self.file = file
self.start_time=start_time
self.duration=duration
self._dict=None
def __getitem__(self, key):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return self._dict[key]
def __iter__(self):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return iter(self._dict)
def __len__(self):
if self._dict is None:
self._dict = get_audio(self.file, self.start_time, self.duration)
return len(self._dict)
def lazy_get_audio(file, start_time=0, duration=0, **kwargs):
return LazyAudioMap(file, start_time, duration)
def is_url(url):
return url.split("://")[0] in ["http", "https"]
def validate_sequence(path):
#Check if path is a valid ffmpeg sequence that points to at least one file
(path, file) = os.path.split(path)
if not os.path.isdir(path):
return False
match = re.search('%0?\\d+d', file)
if not match:
return False
seq = match.group()
if seq == '%d':
seq = '\\\\d+'
else:
seq = '\\\\d{%s}' % seq[1:-1]
file_matcher = re.compile(re.sub('%0?\\d+d', seq, file))
for file in os.listdir(path):
if file_matcher.fullmatch(file):
return True
return False
def strip_path(path):
#This leaves whitespace inside quotes and only a single "
#thus ' ""test"' -> '"test'
#consider path.strip(string.whitespace+"\"")
#or weightier re.fullmatch("[\\s\"]*(.+?)[\\s\"]*", path).group(1)
path = path.strip()
if path.startswith("\""):
path = path[1:]
if path.endswith("\""):
path = path[:-1]
return path
def hash_path(path):
if path is None:
return "input"
if is_url(path):
return "url"
if not os.path.isfile(path):
return "DNE"
return calculate_file_hash(strip_path(path))
def validate_path(path, allow_none=False, allow_url=True):
if path is None:
return allow_none
if is_url(path):
#Probably not feasible to check if url resolves here
if not allow_url:
return "URLs are unsupported for this path"
return is_safe_path(path)
if not os.path.isfile(strip_path(path)):
return "Invalid file path: {}".format(path)
return is_safe_path(path)
def validate_index(index: int, length: int=0, is_range: bool=False, allow_negative=False, allow_missing=False) -> int:
# if part of range, do nothing
if is_range:
return index
# otherwise, validate index
# validate not out of range - only when latent_count is passed in
if length > 0 and index > length-1 and not allow_missing:
raise IndexError(f"Index '{index}' out of range for {length} item(s).")
# if negative, validate not out of range
if index < 0:
if not allow_negative:
raise IndexError(f"Negative indeces not allowed, but was '{index}'.")
conv_index = length+index
if conv_index < 0 and not allow_missing:
raise IndexError(f"Index '{index}', converted to '{conv_index}' out of range for {length} item(s).")
index = conv_index
return index
def convert_to_index_int(raw_index: str, length: int=0, is_range: bool=False, allow_negative=False, allow_missing=False) -> int:
try:
return validate_index(int(raw_index), length=length, is_range=is_range, allow_negative=allow_negative, allow_missing=allow_missing)
except ValueError as e:
raise ValueError(f"Index '{raw_index}' must be an integer.", e)
def convert_str_to_indexes(indexes_str: str, length: int=0, allow_missing=False) -> list[int]:
if not indexes_str:
return []
int_indexes = list(range(0, length))
allow_negative = length > 0
chosen_indexes = []
# parse string - allow positive ints, negative ints, and ranges separated by ':'
groups = indexes_str.split(",")
groups = [g.strip() for g in groups]
for g in groups:
# parse range of indeces (e.g. 2:16)
if ':' in g:
index_range = g.split(":", 2)
index_range = [r.strip() for r in index_range]
start_index = index_range[0]
if len(start_index) > 0:
start_index = convert_to_index_int(start_index, length=length, is_range=True, allow_negative=allow_negative, allow_missing=allow_missing)
else:
start_index = 0
end_index = index_range[1]
if len(end_index) > 0:
end_index = convert_to_index_int(end_index, length=length, is_range=True, allow_negative=allow_negative, allow_missing=allow_missing)
else:
end_index = length
# support step as well, to allow things like reversing, every-other, etc.
step = 1
if len(index_range) > 2:
step = index_range[2]
if len(step) > 0:
step = convert_to_index_int(step, length=length, is_range=True, allow_negative=True, allow_missing=True)
else:
step = 1
# if latents were passed in, base indeces on known latent count
if len(int_indexes) > 0:
chosen_indexes.extend(int_indexes[start_index:end_index][::step])
# otherwise, assume indeces are valid
else:
chosen_indexes.extend(list(range(start_index, end_index, step)))
# parse individual indeces
else:
chosen_indexes.append(convert_to_index_int(g, length=length, allow_negative=allow_negative, allow_missing=allow_missing))
return chosen_indexes
def select_indexes(input_obj: Union[Tensor, list], idxs: list):
if type(input_obj) == Tensor:
return input_obj[idxs]
else:
return [input_obj[i] for i in idxs]
def merge_filter_args(args, ftype="-vf"):
#TODO This doesn't account for filter_complex
#Will likely need to convert all filters to filter complex in the future
#But that requires source/output deduplication
try:
start_index = args.index(ftype)+1
index = start_index
while True:
index = args.index(ftype, index)
args[start_index] += ',' + args[index+1]
args.pop(index)
args.pop(index)
except ValueError:
pass
def select_indexes_from_str(input_obj: Union[Tensor, list], indexes: str, err_if_missing=True, err_if_empty=True):
real_idxs = convert_str_to_indexes(indexes, len(input_obj), allow_missing=not err_if_missing)
if err_if_empty and len(real_idxs) == 0:
raise Exception(f"Nothing was selected based on indexes found in '{indexes}'.")
return select_indexes(input_obj, real_idxs)
def hook(obj, attr):
def dec(f):
f = functools.update_wrapper(f, getattr(obj,attr))
setattr(obj,attr,f)
return f
return dec
def cached(duration):
def dec(f):
cached_ret = None
cache_time = 0
def cached_func():
nonlocal cache_time, cached_ret
if time.time() > cache_time + duration or cached_ret is None:
cache_time = time.time()
cached_ret = f()
return cached_ret
return cached_func
return dec
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,101 @@
import { app } from '../../../scripts/app.js'
function getVideoMetadata(file) {
return new Promise((r) => {
const reader = new FileReader();
reader.onload = (event) => {
const videoData = new Uint8Array(event.target.result);
const dataView = new DataView(videoData.buffer);
let decoder = new TextDecoder();
// Check for known valid magic strings
if (dataView.getUint32(0) == 0x1A45DFA3) {
//webm/mkv (both use EBML/Matroska format)
//see http://wiki.webmproject.org/webm-metadata/global-metadata
//and https://www.matroska.org/technical/elements.html
//contrary to specs, tag seems consistently at start
//COMMENT + 0x4487 + packed length?
//length 0x8d8 becomes 0x48d8
//
//description for variable length ints https://github.com/ietf-wg-cellar/ebml-specification/blob/master/specification.markdown
let offset = 4 + 8; //COMMENT is 7 chars + 1 to realign
while(offset < videoData.length-16) {
//Check for text tags
if (dataView.getUint16(offset) == 0x4487) {
//check that name of tag is COMMENT
const name = String.fromCharCode(...videoData.slice(offset-7,offset));
if (name === "COMMENT") {
let vint = dataView.getUint32(offset+2);
let n_octets = Math.clz32(vint)+1;
if (n_octets < 4) {//250MB sanity cutoff
let length = (vint >> (8*(4-n_octets))) & ~(1 << (7*n_octets));
const content = decoder.decode(videoData.slice(offset+2+n_octets, offset+2+n_octets+length));
let json = JSON.parse(content);
r(json);
return;
}
}
}
offset+=1;
}
} else if (dataView.getUint32(4) == 0x66747970 && dataView.getUint32(8) == 0x69736F6D) {
//mp4
//see https://developer.apple.com/documentation/quicktime-file-format
//Seems to make no guarantee for alignment
let offset = videoData.length-4;
while (offset > 16) {//rough safe guess
if (dataView.getUint32(offset) == 0x64617461) {//any data tag
if (dataView.getUint32(offset - 8) == 0xa9636d74) {//cmt data tag
let type = dataView.getUint32(offset+4); //seemingly 1
let locale = dataView.getUint32(offset+8); //seemingly 0
let size = dataView.getUint32(offset-4) - 4*4;
const content = decoder.decode(videoData.slice(offset+12, offset+12+size));
const json = JSON.parse(content);
r(json);
return;
}
}
offset-=1;
}
} else {
console.error("Unknown magic: " + dataView.getUint32(0))
}
r();
return;
};
reader.readAsArrayBuffer(file);
});
}
function isVideoFile(file) {
if (file?.name?.endsWith(".webm")) {
return true;
}
if (file?.name?.endsWith(".mp4")) {
return true;
}
if (file?.name?.endsWith(".mkv")) {
return true;
}
return false;
}
let originalHandleFile = app.handleFile;
app.handleFile = handleFile;
let fileInput = document.getElementById("comfy-file-input")
//hijack comfy-file-input to allow webm/mp4/mkv
fileInput.accept += ",video/webm,video/mp4,video/x-matroska";
async function handleFile(file) {
if (file?.type?.startsWith("video/") || isVideoFile(file)) {
const videoInfo = await getVideoMetadata(file);
if (videoInfo?.workflow) {
await app.loadGraphData(videoInfo.workflow);
return
}
}
return await originalHandleFile.apply(this, arguments);
}
+87
View File
@@ -0,0 +1,87 @@
{
"authority": "pinned_public_reference_only_not_target_definition",
"classes": [
{
"class": "VideoCombine",
"source_file": "4ee72c06/videohelpersuite/nodes.py",
"definition_lines": [
244,
633
],
"schema_lines": [
246,
272
],
"schema_ast": "@classmethod\ndef INPUT_TYPES(s):\n ffmpeg_formats, format_widgets = get_video_formats()\n format_widgets['image/webp'] = [['lossless', 'BOOLEAN', {'default': True}]]\n return {'required': {'images': (imageOrLatent,), 'frame_rate': (floatOrInt, {'default': 8, 'min': 1, 'step': 1}), 'loop_count': ('INT', {'default': 0, 'min': 0, 'max': 100, 'step': 1}), 'filename_prefix': ('STRING', {'default': 'AnimateDiff'}), 'format': (['image/gif', 'image/webp'] + ffmpeg_formats, {'formats': format_widgets}), 'pingpong': ('BOOLEAN', {'default': False}), 'save_output': ('BOOLEAN', {'default': True})}, 'optional': {'audio': ('AUDIO',), 'meta_batch': ('VHS_BatchManager',), 'vae': ('VAE',)}, 'hidden': ContainsAll({'prompt': 'PROMPT', 'extra_pnginfo': 'EXTRA_PNGINFO', 'unique_id': 'UNIQUE_ID'})}",
"registration": {
"file": "4ee72c06/videohelpersuite/nodes.py",
"line": 1034
}
},
{
"class": "LoadVideoUpload",
"source_file": "85509813/videohelpersuite/load_video_nodes.py",
"definition_lines": [
423,
473
],
"schema_lines": [
425,
451
],
"schema_ast": "@classmethod\ndef INPUT_TYPES(s):\n input_dir = folder_paths.get_input_directory()\n files = []\n for f in os.listdir(input_dir):\n if os.path.isfile(os.path.join(input_dir, f)):\n file_parts = f.split('.')\n if len(file_parts) > 1 and file_parts[-1].lower() in video_extensions:\n files.append(f)\n return {'required': {'video': (sorted(files),), 'force_rate': (floatOrInt, {'default': 0, 'min': 0, 'max': 60, 'step': 1, 'disable': 0}), 'custom_width': ('INT', {'default': 0, 'min': 0, 'max': DIMMAX, 'disable': 0}), 'custom_height': ('INT', {'default': 0, 'min': 0, 'max': DIMMAX, 'disable': 0}), 'frame_load_cap': ('INT', {'default': 0, 'min': 0, 'max': BIGMAX, 'step': 1, 'disable': 0}), 'skip_first_frames': ('INT', {'default': 0, 'min': 0, 'max': BIGMAX, 'step': 1}), 'select_every_nth': ('INT', {'default': 1, 'min': 1, 'max': BIGMAX, 'step': 1})}, 'optional': {'meta_batch': ('VHS_BatchManager',), 'vae': ('VAE',), 'format': get_load_formats()}, 'hidden': {'force_size': 'STRING', 'unique_id': 'UNIQUE_ID'}}",
"registration": {
"file": "85509813/videohelpersuite/nodes.py",
"line": 1026
}
}
],
"frontend_versions": {
"1.37.11": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43",
"1.48.6": "7b4172a243e0d43f1679c0be1c307560cd83c00d"
},
"verified_facts": {
"provider": "comfyui-videohelpersuite",
"combine_commit": "4ee72c065db22c9d96c2427954dc69e7b908444b",
"load_commit": "8550981384301e9bc5bfea83e5c2c75258102593",
"combine_dynamic_fields": [
"pix_fmt",
"crf",
"save_metadata",
"trim_to_audio"
],
"combine_format_file": "4ee72c06/video_formats/h264-mp4.json",
"load_format": "AnimateDiff; built-in mapping shadows nodes.VHSLoadFormats same key",
"persisted_not_prompt": [
"videopreview",
"choose video to upload"
],
"serialize_flags": "VHS onSerialize writes all widgets; graphToPrompt checks options.serialize",
"numeric_restore": "useKVState invokes callbacks. Only identity fixed points accepted. AnimateDiff dimensions modulo 8; zero remains disabling. No callback/media execution.",
"legacy_arrays": "convDict six elements, save_image rename and force_size migration proven; rejected because dynamic fields/default fallbacks not covered",
"filename_prefix": "scripts/utils wrapper calls rootGraph search-and-replace; only literals without % or braces supported",
"extra_js": "videoinfo.js: getVideoMetadata and app.handleFile wrapper; no node serializers"
},
"explicit_reference_assumptions": {
"missing_frontend": "selected 1.37.11; explicit other versions rejected",
"named_mirror": "pinned core ignores widgets_values_named; typed equal mirror required; UE/custom overrides unproven",
"unmodified_pinned_files_and_no_other_extensions": true,
"image_without_vae_only": true,
"no_batch_manager": true
},
"unknown": [
"target installation/frontend/UE",
"input video file membership/access",
"ffmpeg/encoder availability",
"models/media",
"custom extension hooks",
"actual restored graph export equivalence/history"
],
"output_protocol": {
"combine_reference": "ui.gifs descriptors: filename,subfolder,type,format,frame_rate,workflow,fullpath; result has one VHS_FILENAMES value (save_output, full-path list). Unfinished batch has ui.unfinished_batch=[true] and empty result list.",
"downloadable": "gifs filename/subfolder/type is compatible reference shape. Internal full paths are not download descriptors; no target history generated.",
"load_reference": "4 node-to-node results: IMAGE (LATENT with vae), frame count, AUDIO, VHS_VIDEOINFO. No UI file descriptors. Lazy waveform/sample_rate is execution data.",
"existing_collection": "client.py collect_output_files handles gifs with file validation; output_map/registry/worker unchanged, no new global trust or shared-chain changes",
"limits": "other codecs/formats, encoding, history, target media and custom paths unproved"
}
}
@@ -0,0 +1,137 @@
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { useSettingStore } from '@/platform/settings/settingStore'
import { isStringInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { app } from '@/scripts/app'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
const TRACKPAD_DETECTION_THRESHOLD = 50
function addMultilineWidget(
node: LGraphNode,
name: string,
opts: { defaultVal: string; placeholder?: string }
) {
const inputEl = document.createElement('textarea')
inputEl.className = 'comfy-multiline-input'
inputEl.value = opts.defaultVal
inputEl.placeholder = opts.placeholder || name
inputEl.spellcheck = useSettingStore().get('Comfy.TextareaWidget.Spellcheck')
const widget = node.addDOMWidget(name, 'customtext', inputEl, {
getValue(): string {
return inputEl.value
},
setValue(v: string) {
inputEl.value = v
}
})
widget.inputEl = inputEl
widget.options.minNodeSize = [400, 200]
inputEl.addEventListener('input', () => {
widget.callback?.(widget.value)
})
// Allow middle mouse button panning
inputEl.addEventListener('pointerdown', (event: PointerEvent) => {
if (event.button === 1) {
app.canvas.processMouseDown(event)
}
})
inputEl.addEventListener('pointermove', (event: PointerEvent) => {
if ((event.buttons & 4) === 4) {
app.canvas.processMouseMove(event)
}
})
inputEl.addEventListener('pointerup', (event: PointerEvent) => {
if (event.button === 1) {
app.canvas.processMouseUp(event)
}
})
inputEl.addEventListener('wheel', (event: WheelEvent) => {
const gesturesEnabled = useSettingStore().get(
'LiteGraph.Pointer.TrackpadGestures'
)
const deltaX = event.deltaX
const deltaY = event.deltaY
const canScrollY = inputEl.scrollHeight > inputEl.clientHeight
const isHorizontal = Math.abs(deltaX) > Math.abs(deltaY)
// Prevent pinch zoom from zooming the page
if (event.ctrlKey) {
event.preventDefault()
event.stopPropagation()
app.canvas.processMouseWheel(event)
return
}
// Detect if this is likely a trackpad gesture vs mouse wheel
// Trackpads usually have deltaX or smaller deltaY values (< TRACKPAD_DETECTION_THRESHOLD)
// Mouse wheels typically have larger discrete deltaY values (>= TRACKPAD_DETECTION_THRESHOLD)
const isLikelyTrackpad =
Math.abs(deltaX) > 0 || Math.abs(deltaY) < TRACKPAD_DETECTION_THRESHOLD
// Trackpad gestures: when enabled, trackpad panning goes to canvas
if (gesturesEnabled && isLikelyTrackpad) {
event.preventDefault()
event.stopPropagation()
app.canvas.processMouseWheel(event)
return
}
// When gestures disabled: horizontal always goes to canvas (no horizontal scroll in textarea)
if (isHorizontal) {
event.preventDefault()
event.stopPropagation()
app.canvas.processMouseWheel(event)
return
}
// Vertical scrolling when gestures disabled: let textarea scroll if scrollable
if (canScrollY) {
event.stopPropagation()
return
}
// If textarea can't scroll vertically, pass to canvas
event.preventDefault()
app.canvas.processMouseWheel(event)
})
return widget
}
export const useStringWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isStringInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const defaultVal = inputSpec.default ?? ''
const multiline = inputSpec.multiline
const widget = multiline
? addMultilineWidget(node, inputSpec.name, {
defaultVal,
placeholder: inputSpec.placeholder
})
: node.addWidget('text', inputSpec.name, defaultVal, () => {}, {})
if (typeof inputSpec.dynamicPrompts === 'boolean') {
widget.dynamicPrompts = inputSpec.dynamicPrompts
}
return widget
}
return widgetConstructor
}
@@ -0,0 +1,110 @@
import { applyTextReplacements as _applyTextReplacements } from '@/utils/searchAndReplace'
import { api } from './api'
import type { ComfyApp } from './app'
import { $el } from './ui'
export function clone<T>(obj: T): T {
try {
if (typeof structuredClone !== 'undefined') {
return structuredClone(obj)
}
} catch (error) {
// structuredClone is stricter than using JSON.parse/stringify so fallback to that
}
return JSON.parse(JSON.stringify(obj))
}
/**
* @deprecated Use `applyTextReplacements` from `@/utils/searchAndReplace` instead
* There are external callers to this function, so we need to keep it for now
*/
export function applyTextReplacements(app: ComfyApp, value: string): string {
return _applyTextReplacements(app.rootGraph, value)
}
export async function addStylesheet(
urlOrFile: string,
relativeTo?: string
): Promise<void> {
return new Promise((res, rej) => {
let url
if (urlOrFile.endsWith('.js')) {
url = urlOrFile.substr(0, urlOrFile.length - 2) + 'css'
} else {
url = new URL(
urlOrFile,
relativeTo ?? `${window.location.protocol}//${window.location.host}`
).toString()
}
$el('link', {
parent: document.head,
rel: 'stylesheet',
type: 'text/css',
href: url,
onload: res,
onerror: rej
})
})
}
export { downloadBlob } from '@/base/common/downloadUtil'
export function uploadFile(accept: string) {
return new Promise<File>((resolve, reject) => {
const input = document.createElement('input')
input.type = 'file'
input.accept = accept
input.onchange = (e) => {
const file = (e.target as HTMLInputElement).files?.[0]
if (!file) return reject(new Error('No file selected'))
resolve(file)
}
input.click()
})
}
export function prop<T>(
target: object,
name: string,
defaultValue: T,
onChanged?: (
currentValue: T,
previousValue: T,
target: object,
name: string
) => void
): T {
// @ts-expect-error fixme ts strict error
let currentValue
Object.defineProperty(target, name, {
get() {
// @ts-expect-error fixme ts strict error
return currentValue
},
set(newValue) {
// @ts-expect-error fixme ts strict error
const prevValue = currentValue
currentValue = newValue
onChanged?.(currentValue, prevValue, target, name)
}
})
return defaultValue
}
export function getStorageValue(id: string) {
const clientId = api.clientId ?? api.initialClientId
return (
(clientId && sessionStorage.getItem(`${id}:${clientId}`)) ??
localStorage.getItem(id)
)
}
export function setStorageValue(id: string, value: string) {
const clientId = api.clientId ?? api.initialClientId
if (clientId) {
sessionStorage.setItem(`${id}:${clientId}`, value)
}
localStorage.setItem(id, value)
}
@@ -0,0 +1,57 @@
import type { LGraph, Subgraph } from '@/lib/litegraph/src/litegraph'
import { formatDate } from '@/utils/formatUtil'
import { collectAllNodes } from '@/utils/graphTraversalUtil'
export function applyTextReplacements(
graph: LGraph | Subgraph,
value: string
): string {
const allNodes = collectAllNodes(graph)
return value.replace(/%([^%]+)%/g, function (match, text) {
const split = text.split('.')
if (split.length !== 2) {
// Special handling for dates
if (split[0].startsWith('date:')) {
return formatDate(split[0].substring(5), new Date())
}
if (text !== 'width' && text !== 'height') {
// Dont warn on standard replacements
console.warn('Invalid replacement pattern', text)
}
return match
}
// Find node with matching S&R property name
let nodes = allNodes.filter(
(n) => n.properties?.['Node name for S&R'] === split[0]
)
// If we can't, see if there is a node with that title
if (!nodes.length) {
nodes = allNodes.filter((n) => n.title === split[0])
}
if (!nodes.length) {
console.warn('Unable to find node', split[0])
return match
}
if (nodes.length > 1) {
console.warn('Multiple nodes matched', split[0], 'using first match')
}
const node = nodes[0]
const widget = node.widgets?.find((w) => w.name === split[1])
if (!widget) {
console.warn('Unable to find widget', split[1], 'on node', split[0], node)
return match
}
return ((widget.value ?? '') + '').replaceAll(
// eslint-disable-next-line no-control-regex
/[/?<>\\:*|"\x00-\x1F\x7F]/g,
'_'
)
})
}
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
@@ -0,0 +1,225 @@
{
"name": "@comfyorg/comfyui-frontend",
"version": "1.48.6",
"private": true,
"description": "Official front-end implementation of ComfyUI",
"homepage": "https://comfy.org",
"license": "GPL-3.0-only",
"repository": "https://github.com/Comfy-Org/ComfyUI_frontend",
"type": "module",
"scripts": {
"build:cloud": "cross-env DISTRIBUTION=cloud vite build --config vite.config.mts",
"build:desktop": "pnpm --filter @comfyorg/desktop-ui run build",
"build-storybook": "storybook build",
"build:types": "vite build --config vite.types.config.mts && node scripts/prepare-types.js",
"build:analyze": "cross-env ANALYZE_BUNDLE=true pnpm build",
"build": "pnpm typecheck && vite build --config vite.config.mts",
"clean": "pnpm dlx rimraf dist dist-ssr coverage playwright-report blob-report test-results node_modules/.vite apps/desktop-ui/dist apps/website/dist",
"clean:all": "pnpm clean && pnpm dlx rimraf node_modules",
"size:collect": "node scripts/size-collect.js",
"size:report": "node scripts/size-report.js",
"collect-i18n": "pnpm exec playwright test --config=playwright.i18n.config.ts",
"dev:cloud": "pnpm dev:cloud:test",
"dev:cloud:test": "cross-env DEV_SERVER_COMFYUI_URL=https://testcloud.comfy.org/ vite --config vite.config.mts",
"dev:cloud:staging": "cross-env DEV_SERVER_COMFYUI_URL=https://stagingcloud.comfy.org/ vite --config vite.config.mts",
"dev:cloud:prod": "cross-env DEV_SERVER_COMFYUI_URL=https://cloud.comfy.org/ vite --config vite.config.mts",
"dev:desktop": "pnpm --filter @comfyorg/desktop-ui run dev",
"dev:electron": "cross-env DISTRIBUTION=desktop vite --config vite.electron.config.mts",
"dev:no-vue": "cross-env DISABLE_VUE_PLUGINS=true vite --config vite.config.mts",
"dev:test": "cross-env VITE_USE_LEGACY_DEFAULT_GRAPH=true vite --config vite.config.mts",
"dev": "vite --config vite.config.mts",
"devtools:pycheck": "python3 -m compileall -q tools/devtools",
"fallow": "fallow",
"fallow:audit": "fallow audit",
"format:check": "oxfmt --check",
"format": "oxfmt --write",
"json-schema": "tsx scripts/generate-json-schema.ts",
"knip:no-cache": "knip",
"knip": "knip --cache",
"lint:fix:no-cache": "oxlint src browser_tests --type-aware --fix && eslint src --fix",
"lint:fix": "oxlint src browser_tests --type-aware --fix && eslint src --cache --fix",
"lint:no-cache": "pnpm exec stylelint '{apps,packages,src}/**/*.{css,vue}' && oxlint src browser_tests --type-aware && eslint src",
"lint:unstaged:fix": "git diff --name-only HEAD | grep -E '\\.(js|ts|vue|mts)$' | xargs -r eslint --cache --fix",
"lint:unstaged": "git diff --name-only HEAD | grep -E '\\.(js|ts|vue|mts)$' | xargs -r eslint --cache",
"lint": "pnpm stylelint && oxlint src browser_tests --type-aware && eslint src --cache",
"lint:desktop": "pnpm --filter @comfyorg/desktop-ui run lint",
"locale": "lobe-i18n locale",
"oxlint": "oxlint src browser_tests --type-aware",
"prepare": "pnpm exec husky || true && git config blame.ignoreRevsFile .git-blame-ignore-revs || true",
"preview": "vite preview --config vite.config.mts",
"storybook": "storybook dev -p 6006",
"storybook:desktop": "pnpm --filter @comfyorg/desktop-ui run storybook",
"stylelint:fix": "stylelint --cache --fix '{apps,packages,src}/**/*.{css,vue}'",
"stylelint": "stylelint --cache '{apps,packages,src}/**/*.{css,vue}'",
"test:browser": "pnpm exec playwright test",
"test:browser:coverage": "cross-env COLLECT_COVERAGE=true pnpm test:browser",
"test:browser:local": "cross-env PLAYWRIGHT_LOCAL=1 PLAYWRIGHT_TEST_URL=http://localhost:5173 pnpm test:browser",
"test:coverage": "vitest run --coverage",
"test:unit": "vitest run",
"typecheck": "vue-tsc --noEmit",
"typecheck:browser": "vue-tsc --project browser_tests/tsconfig.json",
"typecheck:desktop": "pnpm --filter @comfyorg/desktop-ui run typecheck",
"typecheck:website": "pnpm --filter @comfyorg/website run typecheck",
"zipdist": "node scripts/zipdist.js"
},
"dependencies": {
"@alloc/quick-lru": "catalog:",
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@comfyorg/comfyui-desktop-bridge-types": "workspace:*",
"@comfyorg/comfyui-electron-types": "catalog:",
"@comfyorg/design-system": "workspace:*",
"@comfyorg/fbx-exporter-three": "^1.0.1",
"@comfyorg/object-info-parser": "workspace:*",
"@comfyorg/registry-types": "workspace:*",
"@comfyorg/shared-frontend-utils": "workspace:*",
"@comfyorg/tailwind-utils": "workspace:*",
"@customerio/cdp-analytics-browser": "catalog:",
"@datadog/browser-rum": "catalog:",
"@floating-ui/vue": "catalog:",
"@formkit/auto-animate": "catalog:",
"@iconify/json": "catalog:",
"@primeuix/forms": "catalog:",
"@primeuix/styled": "catalog:",
"@primeuix/utils": "catalog:",
"@primevue/core": "catalog:",
"@primevue/forms": "catalog:",
"@primevue/icons": "catalog:",
"@primevue/themes": "catalog:",
"@sentry/vue": "catalog:",
"@sparkjsdev/spark": "catalog:",
"@tanstack/vue-virtual": "catalog:",
"@tiptap/core": "catalog:",
"@tiptap/extension-link": "catalog:",
"@tiptap/extension-table": "catalog:",
"@tiptap/extension-table-cell": "catalog:",
"@tiptap/extension-table-header": "catalog:",
"@tiptap/extension-table-row": "catalog:",
"@tiptap/pm": "catalog:",
"@tiptap/starter-kit": "catalog:",
"@vee-validate/zod": "catalog:",
"@vueuse/core": "catalog:",
"@vueuse/integrations": "catalog:",
"@vueuse/router": "^14.3.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-serialize": "^0.13.0",
"@xterm/xterm": "^5.5.0",
"algoliasearch": "catalog:",
"axios": "catalog:",
"chart.js": "^4.5.0",
"cva": "catalog:",
"dompurify": "catalog:",
"dotenv": "catalog:",
"es-toolkit": "^1.39.9",
"extendable-media-recorder": "^9.2.27",
"extendable-media-recorder-wav-encoder": "^7.0.129",
"firebase": "catalog:",
"fuse.js": "7.0.0",
"glob": "catalog:",
"jsonata": "catalog:",
"loglevel": "^1.9.2",
"marked": "^15.0.11",
"minisearch": "catalog:",
"pinia": "catalog:",
"posthog-js": "catalog:",
"primeicons": "catalog:",
"primevue": "catalog:",
"reka-ui": "catalog:",
"semver": "^7.7.2",
"three": "catalog:",
"tiptap-markdown": "^0.8.10",
"typegpu": "catalog:",
"vee-validate": "catalog:",
"vue": "catalog:",
"vue-i18n": "catalog:",
"vue-router": "catalog:",
"vuefire": "catalog:",
"wwobjloader2": "catalog:",
"yjs": "catalog:",
"zod": "catalog:",
"zod-validation-error": "catalog:"
},
"devDependencies": {
"@comfyorg/ingest-types": "workspace:*",
"@eslint/js": "catalog:",
"@intlify/eslint-plugin-vue-i18n": "catalog:",
"@lobehub/i18n-cli": "catalog:",
"@pinia/testing": "catalog:",
"@playwright/test": "catalog:",
"@sentry/vite-plugin": "catalog:",
"@storybook/addon-docs": "catalog:",
"@storybook/addon-mcp": "catalog:",
"@storybook/vue3": "catalog:",
"@storybook/vue3-vite": "catalog:",
"@tailwindcss/vite": "catalog:",
"@testing-library/jest-dom": "catalog:",
"@testing-library/user-event": "catalog:",
"@testing-library/vue": "catalog:",
"@total-typescript/shoehorn": "catalog:",
"@types/fs-extra": "catalog:",
"@types/jsdom": "catalog:",
"@types/node": "catalog:",
"@types/semver": "catalog:",
"@types/three": "catalog:",
"@vitejs/plugin-vue": "catalog:",
"@vitest/coverage-v8": "catalog:",
"@vitest/ui": "catalog:",
"@webgpu/types": "catalog:",
"cross-env": "catalog:",
"eslint": "catalog:",
"eslint-config-prettier": "catalog:",
"eslint-import-resolver-typescript": "catalog:",
"eslint-plugin-better-tailwindcss": "catalog:",
"eslint-plugin-import-x": "catalog:",
"eslint-plugin-oxlint": "catalog:",
"eslint-plugin-playwright": "catalog:",
"eslint-plugin-storybook": "catalog:",
"eslint-plugin-testing-library": "catalog:",
"eslint-plugin-unused-imports": "catalog:",
"eslint-plugin-vue": "catalog:",
"fallow": "catalog:",
"fast-check": "catalog:",
"fs-extra": "^11.2.0",
"globals": "catalog:",
"happy-dom": "catalog:",
"husky": "catalog:",
"jiti": "catalog:",
"jsdom": "catalog:",
"knip": "catalog:",
"lint-staged": "catalog:",
"markdown-table": "catalog:",
"mixpanel-browser": "catalog:",
"monocart-coverage-reports": "catalog:",
"oxfmt": "catalog:",
"oxlint": "catalog:",
"oxlint-tsgolint": "catalog:",
"picocolors": "catalog:",
"postcss-html": "catalog:",
"pretty-bytes": "catalog:",
"rollup-plugin-visualizer": "catalog:",
"storybook": "catalog:",
"stylelint": "catalog:",
"tailwindcss": "catalog:",
"tsx": "catalog:",
"typescript": "catalog:",
"typescript-eslint": "catalog:",
"unplugin-icons": "catalog:",
"unplugin-typegpu": "catalog:",
"unplugin-vue-components": "catalog:",
"uuid": "catalog:",
"vite": "catalog:",
"vite-plugin-dts": "catalog:",
"vite-plugin-html": "catalog:",
"vite-plugin-vue-devtools": "catalog:",
"vitest": "catalog:",
"vue-component-type-helpers": "catalog:",
"vue-eslint-parser": "catalog:",
"vue-tsc": "catalog:",
"zip-dir": "^2.0.0",
"zod-to-json-schema": "catalog:"
},
"engines": {
"node": ">=25 <26",
"pnpm": ">=11.3"
},
"packageManager": "pnpm@11.13.1"
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,31 @@
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { isBooleanInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
export const useBooleanWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isBooleanInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const defaultVal = inputSpec.default ?? false
const options = {
on: inputSpec.label_on,
off: inputSpec.label_off
}
return node.addWidget(
'toggle',
inputSpec.name,
defaultVal,
() => {},
options
)
}
return widgetConstructor
}
@@ -0,0 +1,326 @@
import { ref } from 'vue'
import MultiSelectWidget from '@/components/graph/widgets/MultiSelectWidget.vue'
import { t } from '@/i18n'
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { isComboWidget } from '@/lib/litegraph/src/litegraph'
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
import { assetService } from '@/platform/assets/services/assetService'
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
import { getAssetFilename } from '@/platform/assets/utils/assetMetadataUtils'
import { createAssetWidget } from '@/platform/assets/utils/createAssetWidget'
import { isCloud } from '@/platform/distribution/types'
import type {
ComboInputSpec,
InputSpec
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import { isComboInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
import { ComponentWidgetImpl, addWidget } from '@/scripts/domWidget'
import type { BaseDOMWidget } from '@/scripts/domWidget'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { addValueControlWidgets } from '@/scripts/widgets'
import { useAssetsStore } from '@/stores/assetsStore'
import { getMediaTypeFromFilename } from '@/utils/formatUtil'
import { useRemoteWidget } from './useRemoteWidget'
const getDefaultValue = (inputSpec: ComboInputSpec) => {
if (inputSpec.default) return inputSpec.default
if (inputSpec.options?.length) return inputSpec.options[0]
if (inputSpec.remote) return 'Loading...'
return undefined
}
// Map node types to expected media types
const NODE_MEDIA_TYPE_MAP: Record<string, 'image' | 'video' | 'audio'> = {
LoadImage: 'image',
LoadVideo: 'video',
LoadAudio: 'audio'
}
// Map node types to placeholder i18n keys
const NODE_PLACEHOLDER_MAP: Record<string, string> = {
LoadImage: 'widgets.uploadSelect.placeholderImage',
LoadVideo: 'widgets.uploadSelect.placeholderVideo',
LoadAudio: 'widgets.uploadSelect.placeholderAudio'
}
const bindDynamicValuesOption = (
widget: IBaseWidget,
getValues: () => unknown
) => {
const options = widget.options
let fallbackValues = Array.isArray(options.values)
? options.values
: ([] as unknown[])
Object.defineProperty(options, 'values', {
configurable: true,
enumerable: true,
get: () => {
const values = getValues()
if (values === undefined || values === null) return fallbackValues
return values
},
set: (values: unknown[]) => {
fallbackValues = Array.isArray(values) ? values : fallbackValues
}
})
}
const addMultiSelectWidget = (
node: LGraphNode,
inputSpec: ComboInputSpec
): IBaseWidget => {
const widgetValue = ref<string[]>([])
const widget = new ComponentWidgetImpl({
node,
name: inputSpec.name,
component: MultiSelectWidget,
inputSpec,
options: {
getValue: () => widgetValue.value,
setValue: (value: string[]) => {
widgetValue.value = value
}
}
})
addWidget(node, widget as BaseDOMWidget<object | string>)
// TODO: Add remote support to multi-select widget
// https://github.com/Comfy-Org/ComfyUI_frontend/issues/3003
if (inputSpec.control_after_generate) {
const defaultType =
typeof inputSpec.control_after_generate === 'string'
? inputSpec.control_after_generate
: 'fixed'
widget.linkedWidgets = addValueControlWidgets(
node,
widget,
defaultType,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
}
return widget
}
/**
* Resolve the default value for a cloud asset widget.
* Priority: inputSpec.default (if present in cloud assets) → first cloud
* asset → undefined (shows placeholder).
*/
function resolveCloudDefault(
nodeType: string,
specDefault: string | undefined
): string | undefined {
const assets = useAssetsStore().getAssets(nodeType)
if (specDefault != null) {
const inAssets = assets.some((a) => getAssetFilename(a) === specDefault)
if (inAssets) return specDefault
}
// empty filename → undefined (shows placeholder)
const filename = assets.length ? getAssetFilename(assets[0]) : undefined
return filename || undefined
}
function getCloudInputAssets(nodeType: string | undefined): AssetItem[] {
const mediaType = NODE_MEDIA_TYPE_MAP[nodeType ?? '']
if (!mediaType) return []
return useAssetsStore().inputAssets.filter(
(asset) =>
getCloudInputAssetValue(asset) &&
getMediaTypeFromFilename(asset.name) === mediaType
)
}
function getCloudInputAssetValue(asset: AssetItem): string | undefined {
return asset.hash ?? undefined
}
function getCloudInputAssetValues(nodeType: string | undefined): string[] {
return getCloudInputAssets(nodeType)
.map(getCloudInputAssetValue)
.filter((value): value is string => !!value)
}
function resolveCloudInputDefault(
nodeType: string | undefined,
specDefault: string | undefined
): string | undefined {
const assets = getCloudInputAssets(nodeType)
if (specDefault != null) {
const matchingAsset =
assets.find((asset) => getCloudInputAssetValue(asset) === specDefault) ??
assets.find((asset) => asset.name === specDefault)
if (matchingAsset) return getCloudInputAssetValue(matchingAsset)
}
return assets[0] ? getCloudInputAssetValue(assets[0]) : undefined
}
function createAssetBrowserWidget(
node: LGraphNode,
inputSpec: ComboInputSpec,
defaultValue: string | undefined
): IBaseWidget {
return createAssetWidget({
node,
widgetName: inputSpec.name,
nodeTypeForBrowser: node.comfyClass ?? '',
inputNameForBrowser: inputSpec.name,
defaultValue
})
}
const createInputMappingWidget = (
node: LGraphNode,
inputSpec: ComboInputSpec,
defaultValue: string | undefined
): IBaseWidget => {
const assetsStore = useAssetsStore()
const widget = node.addWidget(
'combo',
inputSpec.name,
defaultValue ?? '',
() => {},
{
values: [],
getOptionLabel: (value?: string | null) => {
if (!value) {
const placeholderKey =
NODE_PLACEHOLDER_MAP[node.comfyClass ?? ''] ??
'widgets.uploadSelect.placeholder'
return t(placeholderKey)
}
return assetsStore.getInputName(value)
}
}
)
if (assetsStore.inputAssets.length === 0 && !assetsStore.inputLoading) {
void assetsStore.updateInputs().then(() => {
// edge for users using nodes with 0 prior inputs
// force canvas refresh the first time they add an asset
// so they see filenames instead of hashes.
node.setDirtyCanvas(true, false)
})
}
bindDynamicValuesOption(widget, () =>
getCloudInputAssetValues(node.comfyClass)
)
if (inputSpec.control_after_generate) {
if (!isComboWidget(widget)) {
throw new Error(`Expected combo widget but received ${widget.type}`)
}
const defaultType =
typeof inputSpec.control_after_generate === 'string'
? inputSpec.control_after_generate
: 'randomize'
widget.linkedWidgets = addValueControlWidgets(
node,
widget,
defaultType,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
}
return widget
}
const addComboWidget = (
node: LGraphNode,
inputSpec: ComboInputSpec
): IBaseWidget => {
const defaultValue = getDefaultValue(inputSpec)
if (isCloud) {
if (assetService.shouldUseAssetBrowser(node.comfyClass, inputSpec.name)) {
// Default from cloud assets, not from server combo options.
// Server options list local files that may not exist in the user's
// cloud asset library, leading to missing-model errors on undo/reload.
const cloudDefault = resolveCloudDefault(
node.comfyClass ?? '',
inputSpec.default
)
return createAssetBrowserWidget(node, inputSpec, cloudDefault)
}
if (NODE_MEDIA_TYPE_MAP[node.comfyClass ?? '']) {
return createInputMappingWidget(
node,
inputSpec,
resolveCloudInputDefault(node.comfyClass, inputSpec.default)
)
}
}
// Standard combo widget
const widget = node.addWidget(
'combo',
inputSpec.name,
defaultValue,
() => {},
{
values: inputSpec.options ?? []
}
)
if (inputSpec.remote) {
if (!isComboWidget(widget)) {
throw new Error(`Expected combo widget but received ${widget.type}`)
}
const remoteWidget = useRemoteWidget({
remoteConfig: inputSpec.remote,
defaultValue,
node,
widget
})
if (inputSpec.remote.refresh_button) remoteWidget.addRefreshButton()
bindDynamicValuesOption(widget, () => remoteWidget.getValue())
}
if (inputSpec.control_after_generate) {
if (!isComboWidget(widget)) {
throw new Error(`Expected combo widget but received ${widget.type}`)
}
const defaultType =
typeof inputSpec.control_after_generate === 'string'
? inputSpec.control_after_generate
: 'randomize'
widget.linkedWidgets = addValueControlWidgets(
node,
widget,
defaultType,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
}
return widget
}
export const useComboWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isComboInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
return inputSpec.multi_select
? addMultiSelectWidget(node, inputSpec)
: addComboWidget(node, inputSpec)
}
return widgetConstructor
}
@@ -0,0 +1,100 @@
import { clamp } from 'es-toolkit/compat'
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { INumericWidget } from '@/lib/litegraph/src/types/widgets'
import { useSettingStore } from '@/platform/settings/settingStore'
import { isFloatInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { addValueControlWidget } from '@/scripts/widgets'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
function onFloatValueChange(this: INumericWidget, v: number) {
const round = this.options.round
if (round) {
const precision =
this.options.precision ?? Math.max(0, -Math.floor(Math.log10(round)))
const rounded = Math.round(v / round) * round
this.value = clamp(
Number(rounded.toFixed(precision)),
this.options.min ?? -Infinity,
this.options.max ?? Infinity
)
} else {
this.value = v
}
}
export const _for_testing = {
onFloatValueChange
}
export const useFloatWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isFloatInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const settingStore = useSettingStore()
const sliderEnabled = !settingStore.get('Comfy.DisableSliders')
const display_type = inputSpec.display
const widgetType =
display_type == 'gradientslider'
? 'gradientslider'
: sliderEnabled && display_type == 'slider'
? 'slider'
: display_type == 'knob'
? 'knob'
: 'number'
const step = inputSpec.step ?? 0.5
const precision =
settingStore.get('Comfy.FloatRoundingPrecision') ||
Math.max(0, -Math.floor(Math.log10(step)))
const enableRounding = !settingStore.get('Comfy.DisableFloatRounding')
/** Assertion {@link inputSpec.default} */
const defaultValue = (inputSpec.default as number | undefined) ?? 0
const widget = node.addWidget(
widgetType,
inputSpec.name,
defaultValue,
onFloatValueChange,
{
min: inputSpec.min ?? 0,
max: inputSpec.max ?? 2048,
round:
enableRounding && precision && !inputSpec.round
? Math.pow(10, -precision)
: (inputSpec.round as number),
/** @deprecated Use step2 instead. The 10x value is a legacy implementation. */
step: step * 10.0,
step2: step,
precision,
...(inputSpec.gradient_stops
? { gradient_stops: inputSpec.gradient_stops }
: {})
}
)
if (inputSpec.control_after_generate) {
const controlWidget = addValueControlWidget(
node,
widget,
'fixed',
undefined,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
widget.linkedWidgets = [controlWidget]
}
return widget
}
return widgetConstructor
}
@@ -0,0 +1,93 @@
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { INumericWidget } from '@/lib/litegraph/src/types/widgets'
import { useSettingStore } from '@/platform/settings/settingStore'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { isIntInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { addValueControlWidget } from '@/scripts/widgets'
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
function onValueChange(this: INumericWidget, v: number) {
// For integers, always round to the nearest step
// step === 0 is invalid, assign 1 if options.step is 0
const step = this.options.step2 || 1
if (step === 1) {
// Simple case: round to nearest integer
this.value = Math.round(v)
} else {
// Round to nearest multiple of step
// First, determine if min value creates an offset
const min = this.options.min ?? 0
const offset = min % step
// Round to nearest step, accounting for offset
this.value = Math.round((v - offset) / step) * step + offset
}
}
export const _for_testing = {
onValueChange
}
export const useIntWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isIntInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const settingStore = useSettingStore()
const sliderEnabled = !settingStore.get('Comfy.DisableSliders')
const display_type = inputSpec.display
const widgetType =
sliderEnabled && display_type == 'slider'
? 'slider'
: display_type == 'knob'
? 'knob'
: 'number'
const step = inputSpec.step ?? 1
/** Assertion {@link inputSpec.default} */
const defaultValue = (inputSpec.default as number | undefined) ?? 0
const widget = node.addWidget(
widgetType,
inputSpec.name,
defaultValue,
onValueChange,
{
min: inputSpec.min ?? 0,
max: inputSpec.max ?? 2048,
/** @deprecated Use step2 instead. The 10x value is a legacy implementation. */
step: step * 10,
step2: step,
precision: 0
}
)
const controlAfterGenerate =
inputSpec.control_after_generate ??
['seed', 'noise_seed'].includes(inputSpec.name)
if (controlAfterGenerate) {
const defaultType =
typeof inputSpec.control_after_generate === 'string'
? inputSpec.control_after_generate
: 'randomize'
const controlWidget = addValueControlWidget(
node,
widget,
defaultType,
undefined,
undefined,
transformInputSpecV2ToV1(inputSpec)
)
widget.linkedWidgets = [controlWidget]
}
return widget
}
return widgetConstructor
}
@@ -0,0 +1,95 @@
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { resolveNodeRootGraphId } from '@/lib/litegraph/src/litegraph'
import { defineDeprecatedProperty } from '@/lib/litegraph/src/utils/feedback'
import {
bindMultilineTextareaWidget,
createMultilineInputElement
} from '@/renderer/extensions/vueNodes/widgets/utils/multilineTextarea'
import { isStringInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { app } from '@/scripts/app'
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
import { useWidgetValueStore } from '@/stores/widgetValueStore'
import { widgetId } from '@/types/widgetId'
function addMultilineWidget(
node: LGraphNode,
name: string,
opts: { defaultVal: string; placeholder?: string }
) {
const widgetStore = useWidgetValueStore()
const inputEl = createMultilineInputElement(
opts.defaultVal,
opts.placeholder || name
)
const widget = node.addDOMWidget(name, 'customtext', inputEl, {
getValue(): string {
const graphId = resolveNodeRootGraphId(node, app.rootGraph.id)
const widgetState = widgetStore.getWidget(
widgetId(graphId, node.id, name)
)
return (widgetState?.value as string) ?? inputEl.value
},
setValue(v: string) {
inputEl.value = v
const graphId = resolveNodeRootGraphId(node, app.rootGraph.id)
const id = widgetId(graphId, node.id, name)
const widgetState = widgetStore.getWidget(id)
if (widgetState) {
widgetState.value = v
return
}
widgetStore.registerWidget(id, {
type: 'customtext',
value: v,
options: widget.options ?? {}
})
}
})
widget.element = inputEl
/** @deprecated Use {@link widget.element} instead (renamed in PR #8594). */
defineDeprecatedProperty(
widget,
'inputEl',
'element',
'widget.inputEl is deprecated. Use widget.element instead.'
)
widget.options.minNodeSize = [400, 200]
bindMultilineTextareaWidget(widget, inputEl)
return widget
}
export const useStringWidget = () => {
const widgetConstructor: ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpec
) => {
if (!isStringInputSpec(inputSpec)) {
throw new Error(`Invalid input data: ${inputSpec}`)
}
const defaultVal = inputSpec.default ?? ''
const multiline = inputSpec.multiline
const widget = multiline
? addMultilineWidget(node, inputSpec.name, {
defaultVal,
placeholder: inputSpec.placeholder
})
: node.addWidget('text', inputSpec.name, defaultVal, () => {}, {})
if (typeof inputSpec.dynamicPrompts === 'boolean') {
widget.dynamicPrompts = inputSpec.dynamicPrompts
}
return widget
}
return widgetConstructor
}
@@ -0,0 +1,143 @@
import type {
ComfyNodeDef as ComfyNodeDefV2,
InputSpec as InputSpecV2,
OutputSpec as OutputSpecV2
} from '@/schemas/nodeDef/nodeDefSchemaV2'
import type {
ComfyNodeDef as ComfyNodeDefV1,
InputSpec as InputSpecV1
} from '@/schemas/nodeDefSchema'
import {
getComboSpecComboOptions,
isComboInputSpec,
isComboInputSpecV1
} from '@/schemas/nodeDefSchema'
/**
* Transforms a V1 node definition to V2 format
* @param nodeDefV1 The V1 node definition to transform
* @returns The transformed V2 node definition
*/
export function transformNodeDefV1ToV2(
nodeDefV1: ComfyNodeDefV1
): ComfyNodeDefV2 {
// Transform inputs
const inputs: Record<string, InputSpecV2> = {}
// Process required inputs
if (nodeDefV1.input?.required) {
Object.entries(nodeDefV1.input.required).forEach(([name, inputSpecV1]) => {
inputs[name] = transformInputSpecV1ToV2(inputSpecV1, {
name,
isOptional: false
})
})
}
// Process optional inputs
if (nodeDefV1.input?.optional) {
Object.entries(nodeDefV1.input.optional).forEach(([name, inputSpecV1]) => {
inputs[name] = transformInputSpecV1ToV2(inputSpecV1, {
name,
isOptional: true
})
})
}
// Transform outputs
const outputs: OutputSpecV2[] = []
if (nodeDefV1.output) {
if (Array.isArray(nodeDefV1.output)) {
nodeDefV1.output.forEach((outputType, index) => {
const outputSpec: OutputSpecV2 = {
index,
name: nodeDefV1.output_name?.[index] || `output_${index}`,
type: Array.isArray(outputType) ? 'COMBO' : outputType,
is_list: nodeDefV1.output_is_list?.[index] || false,
tooltip: nodeDefV1.output_tooltips?.[index]
}
// Add options for combo outputs
if (Array.isArray(outputType)) {
outputSpec.options = outputType
}
outputs.push(outputSpec)
})
} else {
console.warn('nodeDefV1.output is not an array:', nodeDefV1.output)
}
}
// Create the V2 node definition
return {
inputs,
outputs,
hidden: nodeDefV1.input?.hidden,
name: nodeDefV1.name,
display_name: nodeDefV1.display_name,
description: nodeDefV1.description,
category: nodeDefV1.category,
output_node: nodeDefV1.output_node,
python_module: nodeDefV1.python_module,
deprecated: nodeDefV1.deprecated,
experimental: nodeDefV1.experimental
}
}
/**
* Transforms a V1 input specification to V2 format
* @param inputSpecV1 The V1 input specification to transform
* @param name The name of the input
* @param isOptional Whether the input is optional
* @returns The transformed V2 input specification
*/
export function transformInputSpecV1ToV2(
inputSpecV1: InputSpecV1,
kwargs: {
name: string
isOptional?: boolean
}
): InputSpecV2 {
const { name, isOptional = false } = kwargs
// Extract options from the input spec
const options = inputSpecV1[1] || {}
// Base properties for all input types
const baseProps = {
name,
isOptional,
...options
}
// Handle different input types
if (isComboInputSpec(inputSpecV1)) {
return {
type: 'COMBO',
...baseProps,
options: isComboInputSpecV1(inputSpecV1)
? inputSpecV1[0]
: getComboSpecComboOptions(inputSpecV1)
}
} else if (typeof inputSpecV1[0] === 'string') {
// Handle standard types (INT, FLOAT, BOOLEAN, STRING) and custom types
return {
type: inputSpecV1[0],
...baseProps
}
}
// Fallback for any unhandled cases
return {
type: 'UNKNOWN',
...baseProps
}
}
export function transformInputSpecV2ToV1(
inputSpecV2: InputSpecV2
): InputSpecV1 {
return [inputSpecV2.type, inputSpecV2]
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,392 @@
import _ from 'es-toolkit/compat'
import { type Component, toRaw } from 'vue'
import { useChainCallback } from '@/composables/functional/useChainCallback'
// LegacyWidget is imported from its own module, not the barrel: the barrel
// exports it after SubgraphNode, so a litegraph-internal importer of this file
// would hit its TDZ. LGraphNode/LiteGraph must stay barrel-sourced — a direct
// LGraphNode import re-triggers the LGraph<->Subgraph cycle.
import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph'
import type {
IBaseWidget,
IWidgetOptions
} from '@/lib/litegraph/src/types/widgets'
import { LegacyWidget } from '@/lib/litegraph/src/widgets/LegacyWidget'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { useDomWidgetStore } from '@/stores/domWidgetStore'
import { generateUUID } from '@/utils/formatUtil'
export interface BaseDOMWidget<
V extends object | string = object | string
> extends IBaseWidget<V, string, DOMWidgetOptions<V>> {
// ICustomWidget properties
type: string
options: DOMWidgetOptions<V>
value: V
callback?: (value: V) => void
// BaseDOMWidget properties
/** The unique ID of the widget. */
readonly id: string
/** The node that the widget belongs to. */
readonly node: LGraphNode
/** Whether the widget is visible. */
isVisible(): boolean
/** The margin of the widget. */
margin: number
}
/**
* A DOM widget that wraps a custom HTML element as a litegraph widget.
*/
export interface DOMWidget<
T extends HTMLElement,
V extends object | string
> extends BaseDOMWidget<V> {
element: T
/**
* @deprecated Legacy property used by some extensions for customtext
* (textarea) widgets. Use {@link element} instead as it provides the same
* functionality and works for all DOMWidget types.
*/
inputEl?: T
}
/**
* Additional props that can be passed to component widgets.
* These are in addition to the standard props that are always provided:
* - modelValue: The widget's value (handled by v-model)
* - widget: Reference to the widget instance
* - onUpdate:modelValue: The update handler for v-model
*/
type ComponentWidgetCustomProps = Record<string, unknown>
/**
* Standard props that are handled separately by DomWidget.vue and should be
* omitted when defining custom props for component widgets
*/
export type ComponentWidgetStandardProps =
| 'modelValue'
| 'widget'
| 'onUpdate:modelValue'
/**
* A DOM widget that wraps a Vue component as a litegraph widget.
*/
export interface ComponentWidget<
V extends object | string,
P extends ComponentWidgetCustomProps = ComponentWidgetCustomProps
> extends BaseDOMWidget<V> {
readonly component: Component
readonly inputSpec: InputSpec
readonly props?: P
}
export interface DOMWidgetOptions<
V extends object | string
> extends IWidgetOptions {
/**
* Whether to render a placeholder rectangle when zoomed out.
*/
hideOnZoom?: boolean
selectOn?: string[]
onHide?: (widget: BaseDOMWidget<V>) => void
getValue?: () => V
setValue?: (value: V) => void
getMinHeight?: () => number
getMaxHeight?: () => number
getHeight?: () => string | number
onDraw?: (widget: BaseDOMWidget<V>) => void
margin?: number
/**
* @deprecated Use `afterResize` instead. This callback is a legacy API
* that fires before resize happens, but it is no longer supported. Now it
* fires after resize happens.
* The resize logic has been upstreamed to litegraph in
* https://github.com/Comfy-Org/ComfyUI_frontend/pull/2557
*/
beforeResize?: (this: BaseDOMWidget<V>, node: LGraphNode) => void
afterResize?: (this: BaseDOMWidget<V>, node: LGraphNode) => void
}
export const isDOMWidget = <T extends HTMLElement, V extends object | string>(
widget: IBaseWidget
): widget is DOMWidget<T, V> => 'element' in widget && !!widget.element
export const isComponentWidget = <V extends object | string>(
widget: IBaseWidget
): widget is ComponentWidget<V> => 'component' in widget && !!widget.component
abstract class BaseDOMWidgetImpl<V extends object | string>
extends LegacyWidget<IBaseWidget<V, string, DOMWidgetOptions<V>>>
implements BaseDOMWidget<V>
{
static readonly DEFAULT_MARGIN = 10
declare readonly name: string
declare readonly options: DOMWidgetOptions<V>
declare callback?: (value: V) => void
readonly id: string
constructor(obj: {
node: LGraphNode
name: string
type: string
options: DOMWidgetOptions<V>
}) {
const { node, name, type, options } = obj
super({ y: 0, name, type, options }, node)
this.id = generateUUID()
}
override get value(): V {
return this.options.getValue?.() ?? ('' as V)
}
override set value(v: V) {
this.options.setValue?.(v)
this.callback?.(this.value)
}
get margin(): number {
return this.options.margin ?? BaseDOMWidgetImpl.DEFAULT_MARGIN
}
isVisible(): boolean {
return (
!this.hidden && !this.computedDisabled && this.node.isWidgetVisible(this)
)
}
override draw(
ctx: CanvasRenderingContext2D,
_node: LGraphNode,
widget_width: number,
y: number,
widget_height: number,
lowQuality?: boolean
): void {
const isVisible = this.isVisible()
if (this.options.hideOnZoom && lowQuality && isVisible) {
// Draw a placeholder rectangle
const originalFillStyle = ctx.fillStyle
ctx.beginPath()
ctx.fillStyle = LiteGraph.WIDGET_BGCOLOR
ctx.rect(
this.margin,
y + this.margin,
widget_width - this.margin * 2,
(this.computedHeight ?? widget_height) - 2 * this.margin
)
ctx.fill()
ctx.fillStyle = originalFillStyle
} else {
if (!isVisible) {
this.options.onDraw?.(this)
return
}
}
this.options.onDraw?.(this)
}
override onRemove(): void {
useDomWidgetStore().unregisterWidget(this.id)
}
override createCopyForNode(node: LGraphNode): this {
// @ts-expect-error
const cloned: this = new (this.constructor as typeof this)({
node: node,
name: this.name,
type: this.type,
options: this.options
})
cloned.value = this.value
// Preserve the Y position from the original widget to maintain proper positioning
// when widgets are promoted through subgraph nesting
cloned.y = this.y
return cloned
}
}
export class DOMWidgetImpl<T extends HTMLElement, V extends object | string>
extends BaseDOMWidgetImpl<V>
implements DOMWidget<T, V>
{
override readonly element: T
constructor(obj: {
node: LGraphNode
name: string
type: string
element: T
options: DOMWidgetOptions<V>
}) {
super(obj)
this.element = obj.element
}
override createCopyForNode(node: LGraphNode): this {
// @ts-expect-error
const cloned: this = new (this.constructor as typeof this)({
node: node,
name: this.name,
type: this.type,
element: this.element, // Include the element!
options: this.options
})
cloned.value = this.value
// Preserve the Y position from the original widget to maintain proper positioning
// when widgets are promoted through subgraph nesting
cloned.y = this.y
return cloned
}
/** Extract DOM widget size info */
override computeLayoutSize(node: LGraphNode) {
if (this.type === 'hidden') {
return {
minHeight: 0,
maxHeight: 0,
minWidth: 0
}
}
const styles = getComputedStyle(this.element)
let minHeight =
this.options.getMinHeight?.() ??
parseInt(styles.getPropertyValue('--comfy-widget-min-height'))
let maxHeight =
this.options.getMaxHeight?.() ??
parseInt(styles.getPropertyValue('--comfy-widget-max-height'))
let prefHeight: string | number =
this.options.getHeight?.() ??
styles.getPropertyValue('--comfy-widget-height')
if (typeof prefHeight === 'string' && prefHeight.endsWith?.('%')) {
prefHeight =
node.size[1] *
(parseFloat(prefHeight.substring(0, prefHeight.length - 1)) / 100)
} else {
prefHeight =
typeof prefHeight === 'number' ? prefHeight : parseInt(prefHeight)
if (isNaN(minHeight)) {
minHeight = prefHeight
}
}
return {
minHeight: isNaN(minHeight) ? 50 : minHeight,
maxHeight: isNaN(maxHeight) ? undefined : maxHeight,
minWidth: 0
}
}
}
export class ComponentWidgetImpl<
V extends object | string,
P extends ComponentWidgetCustomProps = ComponentWidgetCustomProps
>
extends BaseDOMWidgetImpl<V>
implements ComponentWidget<V, P>
{
readonly component: Component
readonly inputSpec: InputSpec
readonly props?: P
constructor(obj: {
node: LGraphNode
name: string
component: Component
inputSpec: InputSpec
props?: P
options: DOMWidgetOptions<V>
type?: string
}) {
super({
type: 'custom',
...obj
})
this.component = obj.component
this.inputSpec = obj.inputSpec
this.props = obj.props
}
override computeLayoutSize() {
const minHeight = this.options.getMinHeight?.() ?? 50
const maxHeight = this.options.getMaxHeight?.()
return {
minHeight,
maxHeight,
minWidth: 0
}
}
override serializeValue(): V {
return toRaw(this.value)
}
}
export const addWidget = <W extends BaseDOMWidget<object | string>>(
node: LGraphNode,
widget: W
) => {
node.addCustomWidget(widget)
if (node.graph) {
useDomWidgetStore().registerWidget(widget)
}
node.onAdded = useChainCallback(node.onAdded, () => {
useDomWidgetStore().registerWidget(widget)
})
node.onRemoved = useChainCallback(node.onRemoved, () => {
widget.onRemove?.()
})
node.onResize = useChainCallback(node.onResize, () => {
widget.options.beforeResize?.call(widget, node)
widget.options.afterResize?.call(widget, node)
})
}
LGraphNode.prototype.addDOMWidget = function <
T extends HTMLElement,
V extends object | string
>(
this: LGraphNode,
name: string,
type: string,
element: T,
options: DOMWidgetOptions<V> = {}
): DOMWidget<T, V> {
const widget = new DOMWidgetImpl({
node: this,
name,
type,
element,
options: { hideOnZoom: true, ...options }
})
// Note: Before `LGraphNode.configure` is called, `this.id` is always `-1`.
addWidget(this, widget as unknown as BaseDOMWidget<object | string>)
// Workaround for https://github.com/Comfy-Org/ComfyUI_frontend/issues/2493
// Some custom nodes are explicitly expecting getter and setter of `value`
// property to be on instance instead of prototype.
Object.defineProperty(widget, 'value', {
get(this: DOMWidgetImpl<T, V>): V {
return this.options.getValue?.() ?? ('' as V)
},
set(this: DOMWidgetImpl<T, V>, v: V) {
this.options.setValue?.(v)
this.callback?.(this.value)
}
})
return widget
}
@@ -0,0 +1,110 @@
import { applyTextReplacements as _applyTextReplacements } from '@/utils/searchAndReplace'
import { api } from './api'
import type { ComfyApp } from './app'
import { $el } from './ui'
export function clone<T>(obj: T): T {
try {
if (typeof structuredClone !== 'undefined') {
return structuredClone(obj)
}
} catch (error) {
// structuredClone is stricter than using JSON.parse/stringify so fallback to that
}
return JSON.parse(JSON.stringify(obj))
}
/**
* @deprecated Use `applyTextReplacements` from `@/utils/searchAndReplace` instead
* There are external callers to this function, so we need to keep it for now
*/
export function applyTextReplacements(app: ComfyApp, value: string): string {
return _applyTextReplacements(app.rootGraph, value)
}
export async function addStylesheet(
urlOrFile: string,
relativeTo?: string
): Promise<void> {
return new Promise((res, rej) => {
let url
if (urlOrFile.endsWith('.js')) {
url = urlOrFile.substr(0, urlOrFile.length - 2) + 'css'
} else {
url = new URL(
urlOrFile,
relativeTo ?? `${window.location.protocol}//${window.location.host}`
).toString()
}
$el('link', {
parent: document.head,
rel: 'stylesheet',
type: 'text/css',
href: url,
onload: res,
onerror: rej
})
})
}
export { downloadBlob } from '@/base/common/downloadUtil'
export function uploadFile(accept: string) {
return new Promise<File>((resolve, reject) => {
const input = document.createElement('input')
input.type = 'file'
input.accept = accept
input.onchange = (e) => {
const file = (e.target as HTMLInputElement).files?.[0]
if (!file) return reject(new Error('No file selected'))
resolve(file)
}
input.click()
})
}
export function prop<T>(
target: object,
name: string,
defaultValue: T,
onChanged?: (
currentValue: T,
previousValue: T,
target: object,
name: string
) => void
): T {
// @ts-expect-error fixme ts strict error
let currentValue
Object.defineProperty(target, name, {
get() {
// @ts-expect-error fixme ts strict error
return currentValue
},
set(newValue) {
// @ts-expect-error fixme ts strict error
const prevValue = currentValue
currentValue = newValue
onChanged?.(currentValue, prevValue, target, name)
}
})
return defaultValue
}
export function getStorageValue(id: string) {
const clientId = api.clientId ?? api.initialClientId
return (
(clientId && sessionStorage.getItem(`${id}:${clientId}`)) ??
localStorage.getItem(id)
)
}
export function setStorageValue(id: string, value: string) {
const clientId = api.clientId ?? api.initialClientId
if (clientId) {
sessionStorage.setItem(`${id}:${clientId}`, value)
}
localStorage.setItem(id, value)
}
@@ -0,0 +1,248 @@
import { t } from '@/i18n'
import { type LGraphNode, isComboWidget } from '@/lib/litegraph/src/litegraph'
import type {
IBaseWidget,
IComboWidget,
IStringWidget
} from '@/lib/litegraph/src/types/widgets'
import { nextValueForLinkedTarget } from './valueControl'
import { useSettingStore } from '@/platform/settings/settingStore'
import { dynamicWidgets } from '@/core/graph/widgets/dynamicWidgets'
import { useBooleanWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget'
import { useBoundingBoxWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useBoundingBoxWidget'
import { useCurveWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useCurveWidget'
import { useChartWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useChartWidget'
import { useColorWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useColorWidget'
import { useComboWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useComboWidget'
import { useFloatWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useFloatWidget'
import { useGalleriaWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useGalleriaWidget'
import { useBoundingBoxesWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useBoundingBoxesWidget'
import { useColorsWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useColorsWidget'
import { useImageCompareWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useImageCompareWidget'
import { useImageUploadWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useImageUploadWidget'
import { useIntWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useIntWidget'
import { useMarkdownWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useMarkdownWidget'
import { usePainterWidget } from '@/renderer/extensions/vueNodes/widgets/composables/usePainterWidget'
import { useRangeWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useRangeWidget'
import { useStringWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useStringWidget'
import { useTextareaWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useTextareaWidget'
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
import type { InputSpec as InputSpecV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import type { ComfyApp } from './app'
import { IS_CONTROL_WIDGET } from './controlWidgetMarker'
import './domWidget'
import './errorNodeWidgets'
export { IS_CONTROL_WIDGET }
export type ComfyWidgetConstructorV2 = (
node: LGraphNode,
inputSpec: InputSpecV2
) => IBaseWidget
export type ComfyWidgetConstructor = (
node: LGraphNode,
inputName: string,
inputData: InputSpec,
app: ComfyApp,
widgetName?: string
) => { widget: IBaseWidget; minWidth?: number; minHeight?: number }
/**
* Transforms a V2 widget constructor to a V1 widget constructor.
* @param widgetConstructorV2 The V2 widget constructor to transform.
* @returns The transformed V1 widget constructor.
*/
const transformWidgetConstructorV2ToV1 = (
widgetConstructorV2: ComfyWidgetConstructorV2
): ComfyWidgetConstructor => {
return (node, inputName, inputData) => {
const inputSpec = transformInputSpecV1ToV2(inputData, {
name: inputName
})
const widget = widgetConstructorV2(node, inputSpec)
return {
widget,
minWidth: widget.options.minNodeSize?.[0],
minHeight: widget.options.minNodeSize?.[1]
}
}
}
function controlValueRunBefore() {
return useSettingStore().get('Comfy.WidgetControlMode') === 'before'
}
export function updateControlWidgetLabel(widget: IBaseWidget) {
if (controlValueRunBefore()) {
widget.label = t('g.control_before_generate')
} else {
widget.label = t('g.control_after_generate')
}
}
const HAS_EXECUTED = Symbol()
export function addValueControlWidget(
node: LGraphNode,
targetWidget: IBaseWidget,
defaultValue?: string,
_values?: unknown,
widgetName?: string,
inputData?: InputSpec
): IComboWidget {
let name = inputData?.[1]?.control_after_generate
if (typeof name !== 'string') {
name = widgetName
}
const widgets = addValueControlWidgets(
node,
targetWidget,
defaultValue ?? 'randomize',
{
addFilterList: false,
controlAfterGenerateName: name
},
inputData
)
return widgets[0]
}
export function addValueControlWidgets(
node: LGraphNode,
targetWidget: IBaseWidget,
defaultValue?: string,
options?: Record<string, any>,
inputData?: InputSpec
): [IComboWidget, ...IStringWidget[]] {
if (!defaultValue) defaultValue = 'randomize'
if (!options) options = {}
const getName = (defaultName: string, optionName: string) => {
let name = defaultName
if (options[optionName]) {
name = options[optionName]
} else if (typeof inputData?.[1]?.[defaultName] === 'string') {
name = inputData?.[1]?.[defaultName]
} else if (inputData?.[1]?.control_prefix) {
name = inputData?.[1]?.control_prefix + ' ' + name
}
return name
}
const valueControl = node.addWidget(
'combo',
getName('control_after_generate', 'controlAfterGenerateName'),
defaultValue,
function () {},
{
values: ['fixed', 'increment', 'decrement', 'randomize'],
serialize: false, // Don't include this in prompt.
canvasOnly: true
}
) as IComboWidget
valueControl.tooltip =
'Allows the linked widget to be changed automatically, for example randomizing the noise seed.'
valueControl[IS_CONTROL_WIDGET] = true
updateControlWidgetLabel(valueControl)
Object.defineProperty(valueControl, 'disabled', {
get: () => targetWidget.computedDisabled
})
const widgets: [IComboWidget, ...IStringWidget[]] = [valueControl]
const isCombo = isComboWidget(targetWidget)
let comboFilter: IStringWidget
if (isCombo && valueControl.options.values) {
// @ts-expect-error Combo widget values may be a dictionary or legacy function type
valueControl.options.values.push('increment-wrap')
}
if (isCombo && options.addFilterList !== false) {
comboFilter = node.addWidget(
'string',
getName('control_filter_list', 'controlFilterListName'),
'',
function () {},
{
serialize: false // Don't include this in prompt.
}
) as IStringWidget
updateControlWidgetLabel(comboFilter)
comboFilter.tooltip =
"Allows for filtering the list of values when changing the value via the control generate mode. Allows for RegEx matches in the format /abc/ to only filter to values containing 'abc'."
Object.defineProperty(comboFilter, 'disabled', {
get: () => targetWidget.computedDisabled
})
widgets.push(comboFilter)
}
function applyWidgetControl(isPartialExecution: boolean | undefined) {
if (
node.inputs?.some(
(input) =>
input.widget?.name === targetWidget.name && input.link != null
)
)
return
const next = nextValueForLinkedTarget({
target: targetWidget,
linkedWidgets: targetWidget.linkedWidgets,
nodeId: node.id,
isPartialExecution
})
if (next === undefined) return
targetWidget.value = next
targetWidget.callback?.(next)
}
valueControl.beforeQueued = ({ isPartialExecution } = {}) => {
if (controlValueRunBefore()) {
// Don't run on first execution
if (valueControl[HAS_EXECUTED]) {
applyWidgetControl(isPartialExecution)
}
}
valueControl[HAS_EXECUTED] = true
}
valueControl.afterQueued = ({ isPartialExecution } = {}) => {
if (!controlValueRunBefore()) {
applyWidgetControl(isPartialExecution)
}
}
return widgets
}
export const ComfyWidgets = {
INT: transformWidgetConstructorV2ToV1(useIntWidget()),
FLOAT: transformWidgetConstructorV2ToV1(useFloatWidget()),
BOOLEAN: transformWidgetConstructorV2ToV1(useBooleanWidget()),
STRING: transformWidgetConstructorV2ToV1(useStringWidget()),
MARKDOWN: transformWidgetConstructorV2ToV1(useMarkdownWidget()),
COMBO: transformWidgetConstructorV2ToV1(useComboWidget()),
IMAGEUPLOAD: useImageUploadWidget(),
COLOR: transformWidgetConstructorV2ToV1(useColorWidget()),
IMAGECOMPARE: transformWidgetConstructorV2ToV1(useImageCompareWidget()),
BOUNDING_BOX: transformWidgetConstructorV2ToV1(useBoundingBoxWidget()),
CHART: transformWidgetConstructorV2ToV1(useChartWidget()),
GALLERIA: transformWidgetConstructorV2ToV1(useGalleriaWidget()),
PAINTER: transformWidgetConstructorV2ToV1(usePainterWidget()),
TEXTAREA: transformWidgetConstructorV2ToV1(useTextareaWidget()),
CURVE: transformWidgetConstructorV2ToV1(useCurveWidget()),
RANGE: transformWidgetConstructorV2ToV1(useRangeWidget()),
BOUNDING_BOXES: transformWidgetConstructorV2ToV1(useBoundingBoxesWidget()),
COLORS: transformWidgetConstructorV2ToV1(useColorsWidget()),
...dynamicWidgets
} as const
export function isValidWidgetType(
key: unknown
): key is keyof typeof ComfyWidgets {
return ComfyWidgets[key as keyof typeof ComfyWidgets] !== undefined
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,160 @@
import type {
ExecutableLGraphNode,
ExecutionId,
LGraph
} from '@/lib/litegraph/src/litegraph'
import {
ExecutableNodeDTO,
LGraphEventMode
} from '@/lib/litegraph/src/litegraph'
import type {
ComfyApiWorkflow,
ComfyWorkflowJSON
} from '@/platform/workflow/validation/schemas/workflowSchema'
import { compressWidgetInputSlots } from './litegraphUtil'
/**
* Converts the current graph workflow for sending to the API.
* @note Node widgets are updated before serialization to prepare queueing.
*
* @param graph The graph to convert.
* @param options The options for the conversion.
* - `sortNodes`: Whether to sort the nodes by execution order.
* @returns The workflow and node links
*/
export const graphToPrompt = async (
graph: LGraph,
options: { sortNodes?: boolean } = {}
): Promise<{ workflow: ComfyWorkflowJSON; output: ComfyApiWorkflow }> => {
const { sortNodes = false } = options
for (const node of graph.computeExecutionOrder(false)) {
const innerNodes = node.getInnerNodes
? node.getInnerNodes(new Map())
: [node]
for (const innerNode of innerNodes) {
if (innerNode.isVirtualNode) {
innerNode.applyToGraph?.()
}
}
}
const workflow = graph.serialize({ sortNodes })
// Remove localized_name from the workflow
for (const node of workflow.nodes) {
for (const slot of node.inputs ?? []) {
delete slot.localized_name
}
for (const slot of node.outputs ?? []) {
delete slot.localized_name
}
}
compressWidgetInputSlots(workflow)
workflow.extra ??= {}
workflow.extra.frontendVersion = __COMFYUI_FRONTEND_VERSION__
const nodeDtoMap = new Map<ExecutionId, ExecutableLGraphNode>()
for (const node of graph.computeExecutionOrder(false)) {
const dto: ExecutableLGraphNode = new ExecutableNodeDTO(
node,
[],
nodeDtoMap
)
nodeDtoMap.set(dto.id, dto)
if (
node.mode === LGraphEventMode.NEVER ||
node.mode === LGraphEventMode.BYPASS
) {
continue
}
for (const innerNode of dto.getInnerNodes()) {
nodeDtoMap.set(innerNode.id, innerNode)
}
}
const output: ComfyApiWorkflow = {}
// Process nodes in order of execution
for (const node of nodeDtoMap.values()) {
// Don't serialize muted nodes
if (
node.isVirtualNode ||
node.mode === LGraphEventMode.NEVER ||
node.mode === LGraphEventMode.BYPASS
) {
continue
}
const inputs: ComfyApiWorkflow[string]['inputs'] = {}
const { widgets } = node
// Store all widget values in the API prompt.
// Note: widget.options.serialize controls prompt inclusion (checked here).
// widget.serialize controls workflow persistence (checked by LGraphNode).
if (widgets) {
for (const [i, widget] of widgets.entries()) {
if (!widget.name || widget.options?.serialize === false) continue
const widgetValue = widget.serializeValue
? await widget.serializeValue(node, i)
: widget.value
// By default, Array values are reserved to represent node connections.
// We need to wrap the array as an object to avoid the misinterpretation
// of the array as a node connection.
// The backend automatically unwraps the object to an array during
// execution.
inputs[widget.name] = Array.isArray(widgetValue)
? widget.type === 'curve'
? { __type__: 'CURVE', __value__: widgetValue }
: { __value__: widgetValue }
: widgetValue
}
}
// Store all node links
for (const [i, input] of node.inputs.entries()) {
const resolvedInput = node.resolveInput(i)
if (!resolvedInput) continue
// Resolved to an actual widget value rather than a node connection
if (resolvedInput.widgetInfo) {
const { value } = resolvedInput.widgetInfo
inputs[input.name] = Array.isArray(value) ? { __value__: value } : value
continue
}
inputs[input.name] = [
String(resolvedInput.origin_id),
// @ts-expect-error link.origin_slot is already number.
parseInt(resolvedInput.origin_slot)
]
}
output[String(node.id)] = {
inputs,
// TODO(huchenlei): Filter out all nodes that cannot be mapped to a
// comfyClass.
class_type: node.comfyClass!,
// Ignored by the backend.
_meta: {
title: node.title
}
}
}
// Remove inputs connected to removed nodes
for (const { inputs } of Object.values(output)) {
for (const [i, input] of Object.entries(inputs)) {
if (Array.isArray(input) && input.length === 2 && !output[input[0]]) {
delete inputs[i]
}
}
}
return { workflow: workflow as ComfyWorkflowJSON, output }
}
@@ -0,0 +1,388 @@
import _ from 'es-toolkit/compat'
import type { ColorOption, LGraph } from '@/lib/litegraph/src/litegraph'
import type { ExecutedWsMessage } from '@/schemas/apiSchema'
import {
LGraphCanvas,
LGraphGroup,
LGraphNode,
LiteGraph,
Reroute,
isColorable
} from '@/lib/litegraph/src/litegraph'
import type {
ExportedSubgraph,
ISerialisableNodeInput,
ISerialisedGraph
} from '@/lib/litegraph/src/types/serialisation'
import type {
IBaseWidget,
IComboWidget,
WidgetCallbackOptions
} from '@/lib/litegraph/src/types/widgets'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { useNodeZIndex } from '@/renderer/extensions/vueNodes/composables/useNodeZIndex'
import { app } from '@/scripts/app'
import { t } from '@/i18n'
import { parseNodeLocatorId } from '@/types/nodeIdentification'
import type { SerializedNodeId } from '@/types/nodeId'
import { UNASSIGNED_NODE_ID, parseNodeId } from '@/types/nodeId'
import type { WidgetId } from '@/types/widgetId'
import { widgetId } from '@/types/widgetId'
type ImageNode = LGraphNode & { imgs: HTMLImageElement[] | undefined }
type VideoNode = LGraphNode & {
videoContainer: HTMLElement | undefined
imgs: HTMLVideoElement[] | undefined
}
/**
* Extract & Promisify Litegraph.createNode to allow for positioning
* @param canvas
* @param name
*/
export async function createNode(
canvas: LGraphCanvas,
name: string
): Promise<LGraphNode | null> {
if (!name) {
return null
}
const {
graph,
graph_mouse: [posX, posY]
} = canvas
const newNode = LiteGraph.createNode(name)
await new Promise((r) => setTimeout(r, 0))
if (newNode && graph) {
newNode.pos = [posX, posY]
const addedNode = graph.add(newNode) ?? null
if (addedNode) {
useNodeZIndex().bringNodeToFront(addedNode.id)
graph.change()
}
return addedNode
} else {
useToastStore().addAlert(t('assetBrowser.failedToCreateNode'))
return null
}
}
export function isImageNode(node: LGraphNode | undefined): node is ImageNode {
if (!node) return false
return (
node.previewMediaType === 'image' ||
(node.previewMediaType !== 'video' && !!node.imgs?.length)
)
}
export function isVideoNode(node: LGraphNode | undefined): node is VideoNode {
if (!node) return false
return node.previewMediaType === 'video' || !!node.videoContainer
}
/**
* Check if output data indicates animated content (animated webp/png or video).
*/
export function isAnimatedOutput(
output: ExecutedWsMessage['output'] | undefined
): boolean {
return !!output?.animated?.find(Boolean)
}
/**
* Check if output data indicates video content (animated but not webp/png).
*/
export function isVideoOutput(
output: ExecutedWsMessage['output'] | undefined
): boolean {
if (!isAnimatedOutput(output)) return false
const isAnimatedWebp = output?.images?.some((img) =>
img.filename?.endsWith('.webp')
)
const isAnimatedPng = output?.images?.some((img) =>
img.filename?.endsWith('.png')
)
return !isAnimatedWebp && !isAnimatedPng
}
export function isAudioNode(node: LGraphNode | undefined): boolean {
return !!node && node.previewMediaType === 'audio'
}
export function resolveComboValues(widget: IComboWidget): string[] {
const values = widget.options?.values
if (!values) return []
if (typeof values === 'function') return values(widget)
if (Array.isArray(values)) return values
return Object.keys(values)
}
export function addToComboValues(widget: IComboWidget, value: string) {
if (!widget.options) widget.options = { values: [] }
if (!widget.options.values) widget.options.values = []
// @ts-expect-error Combo widget values may be a dictionary or legacy function type
if (!widget.options.values.includes(value)) {
// @ts-expect-error Combo widget values may be a dictionary or legacy function type
widget.options.values.push(value)
}
}
export const isLGraphNode = (item: unknown): item is LGraphNode => {
return item instanceof LGraphNode
}
export const isLGraphGroup = (item: unknown): item is LGraphGroup => {
return item instanceof LGraphGroup
}
export const isReroute = (item: unknown): item is Reroute => {
return item instanceof Reroute
}
/**
* Get the color option of all canvas items if they are all the same.
* @param items - The items to get the color option of.
* @returns The color option of the item.
*/
export const getItemsColorOption = (items: unknown[]): ColorOption | null => {
const validItems = _.filter(items, isColorable)
if (_.isEmpty(validItems)) return null
const colorOptions = _.map(validItems, (item) => item.getColorOption())
return _.every(colorOptions, (option) =>
_.isEqual(option, _.head(colorOptions))
)
? _.head(colorOptions)!
: null
}
export function executeWidgetsCallback(
nodes: LGraphNode[],
callbackName: 'onRemove' | 'beforeQueued' | 'afterQueued',
options?: WidgetCallbackOptions
) {
for (const node of nodes) {
for (const widget of node.widgets ?? []) {
widget[callbackName]?.(options)
}
}
}
/**
* Since frontend version 1.16, forceInput input is no longer treated
* as widget. So we need to remove the dummy widget value serialized
* from workflows prior to v1.16.
* Ref: https://github.com/Comfy-Org/ComfyUI_frontend/pull/3326
*
* @param nodeDef the node definition
* @param widgets the widgets on the node instance (from node definition)
* @param widgetsValues the widgets values to populate the node during configuration
* @returns the widgets values without the dummy widget values
*/
export function migrateWidgetsValues<TWidgetValue>(
inputDefs: Record<string, InputSpec>,
widgets: IBaseWidget[],
widgetsValues: TWidgetValue[]
): TWidgetValue[] {
const widgetNames = new Set(widgets.map((w) => w.name))
const originalWidgetsInputs = Object.values(inputDefs).filter(
(input) => widgetNames.has(input.name) || input.forceInput
)
const widgetIndexHasForceInput = originalWidgetsInputs.flatMap((input) =>
input.control_after_generate
? [!!input.forceInput, false]
: [!!input.forceInput]
)
if (widgetIndexHasForceInput.length !== widgetsValues?.length)
return widgetsValues
return widgetsValues.filter((_, index) => !widgetIndexHasForceInput[index])
}
/**
* Fix link input slots after loading a graph. Because the node inputs follows
* the node definition after 1.16, the node inputs array from previous versions,
* might get added items in the middle, which can cause shift to link's slot index.
* For example, the node inputs definition is:
* "required": {
* "input1": ["INT", { forceInput: true }],
* "input2": ["MODEL", { forceInput: false }],
* "input3": ["MODEL", { forceInput: false }]
* }
*
* previously node inputs array was:
* [{name: 'input2'}, {name: 'input3'}, {name: 'input1'}]
* because input1 is created as widget first, then convert to input socket after
* input 2 and 3.
*
* Now, the node inputs array just follows the definition order:
* [{name: 'input1'}, {name: 'input2'}, {name: 'input3'}]
*
* We need to update the slot index of corresponding links to match the new
* node inputs array order.
*
* Ref: https://github.com/Comfy-Org/ComfyUI_frontend/issues/3348
*
* @param graph - The graph to fix links for.
*/
export function fixLinkInputSlots(graph: LGraph) {
// Note: We can't use forEachNode here because we need access to the graph's
// links map at each level. Links are stored in their respective graph/subgraph.
for (const node of graph.nodes) {
// Fix links for the current node
for (const [inputIndex, input] of node.inputs.entries()) {
const linkId = input.link
if (!linkId) continue
const link = graph.links.get(linkId)
if (!link) continue
link.target_slot = inputIndex
}
// Recursively fix links in subgraphs
if (node.isSubgraphNode?.() && node.subgraph) {
fixLinkInputSlots(node.subgraph)
}
}
}
/**
* Compress widget input slots by removing all unconnected widget input slots.
* This should match the serialization format of legacy widget conversion.
*
* @param graph - The graph to compress widget input slots for.
* @throws If an infinite loop is detected.
*/
export function compressWidgetInputSlots(graph: ISerialisedGraph) {
for (const node of graph.nodes) {
node.inputs = node.inputs?.filter(matchesLegacyApi)
for (const [inputIndex, input] of node.inputs?.entries() ?? []) {
if (input.link) {
const link = graph.links.find((link) => link[0] === input.link)
if (link) {
link[4] = inputIndex
}
}
}
}
compressSubgraphWidgetInputSlots(graph.definitions?.subgraphs)
}
function matchesLegacyApi(input: ISerialisableNodeInput) {
return !(input.widget && input.link === null && !input.label)
}
/**
* Duplication to handle the legacy link arrays in the root workflow.
* @see compressWidgetInputSlots
* @param subgraph The subgraph to compress widget input slots for.
*/
function compressSubgraphWidgetInputSlots(
subgraphs: ExportedSubgraph[] | undefined,
visited = new WeakSet<ExportedSubgraph>()
) {
if (!subgraphs) return
for (const subgraph of subgraphs) {
if (visited.has(subgraph)) throw new Error('Infinite loop detected')
visited.add(subgraph)
if (subgraph.nodes) {
for (const node of subgraph.nodes) {
node.inputs = node.inputs?.filter(matchesLegacyApi)
if (!subgraph.links) continue
for (const [inputIndex, input] of node.inputs?.entries() ?? []) {
if (input.link) {
const link = subgraph.links.find((link) => link.id === input.link)
if (link) link.target_slot = inputIndex
}
}
}
}
compressSubgraphWidgetInputSlots(subgraph.definitions?.subgraphs, visited)
}
}
export function getLinkTypeColor(typeName: string): string {
return LGraphCanvas.link_type_colors[typeName] ?? LiteGraph.LINK_COLOR
}
export function resolveNode(
nodeId: SerializedNodeId,
graph: LGraph | null | undefined = app.rootGraph
): LGraphNode | undefined {
const parsedNodeId = parseNodeId(nodeId)
if (!graph || !parsedNodeId) return undefined
const found = graph.getNodeById(parsedNodeId)
if (found) return found
for (const sg of graph.subgraphs.values()) {
const node = sg.getNodeById(parsedNodeId)
if (node) return node
}
return undefined
}
export function resolveNodeWidget(
nodeId: SerializedNodeId,
widgetName?: string,
graph: LGraph = app.rootGraph
): [LGraphNode, IBaseWidget] | [LGraphNode] | [] {
if (widgetName && typeof nodeId === 'string') {
const locator = parseNodeLocatorId(nodeId)
if (locator?.subgraphUuid) {
const host = graph.getNodeById(locator.localNodeId)
if (host?.isSubgraphNode()) {
const widget = host.widgets?.find((w) => w.name === widgetName)
return widget ? [host, widget] : []
}
}
}
const parsedNodeId = parseNodeId(nodeId)
if (!parsedNodeId) return []
const node = graph.getNodeById(parsedNodeId)
if (!widgetName) return node ? [node] : []
if (node) {
const widget = node.widgets?.find((w) => w.name === widgetName)
return widget ? [node, widget] : []
}
return []
}
export function getWidgetIdForNode(
node: LGraphNode,
widget: Pick<IBaseWidget, 'name' | 'widgetId'>,
duplicateIndex = 0
): WidgetId | undefined {
if (widget.widgetId) return widget.widgetId
const graphId = node.graph?.rootGraph.id
const nodeId = parseNodeId(node.id)
if (!graphId || !nodeId || nodeId === UNASSIGNED_NODE_ID) return undefined
const name =
duplicateIndex > 0 ? `${widget.name}#${duplicateIndex}` : widget.name
return widgetId(graphId, nodeId, name)
}
export function isLoad3dNode(node: LGraphNode) {
return (
node &&
node.type &&
(node.type === 'Load3D' || node.type === 'Load3DAnimation')
)
}
@@ -0,0 +1,57 @@
import type { LGraph, Subgraph } from '@/lib/litegraph/src/litegraph'
import { formatDate } from '@/utils/formatUtil'
import { collectAllNodes } from '@/utils/graphTraversalUtil'
export function applyTextReplacements(
graph: LGraph | Subgraph,
value: string
): string {
const allNodes = collectAllNodes(graph)
return value.replace(/%([^%]+)%/g, function (match, text) {
const split = text.split('.')
if (split.length !== 2) {
// Special handling for dates
if (split[0].startsWith('date:')) {
return formatDate(split[0].substring(5), new Date())
}
if (text !== 'width' && text !== 'height') {
// Dont warn on standard replacements
console.warn('Invalid replacement pattern', text)
}
return match
}
// Find node with matching S&R property name
let nodes = allNodes.filter(
(n) => n.properties?.['Node name for S&R'] === split[0]
)
// If we can't, see if there is a node with that title
if (!nodes.length) {
nodes = allNodes.filter((n) => n.title === split[0])
}
if (!nodes.length) {
console.warn('Unable to find node', split[0])
return match
}
if (nodes.length > 1) {
console.warn('Multiple nodes matched', split[0], 'using first match')
}
const node = nodes[0]
const widget = node.widgets?.find((w) => w.name === split[1])
if (!widget) {
console.warn('Unable to find widget', split[1], 'on node', split[0], node)
return match
}
return ((widget.value ?? '') + '').replaceAll(
// eslint-disable-next-line no-control-regex
/[/?<>\\:*|"\x00-\x1F\x7F]/g,
'_'
)
})
}
@@ -0,0 +1,108 @@
import type { TWidgetValue } from '@/lib/litegraph/src/litegraph'
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
/**
* Gets an ordered array of InputSpec objects based on input_order.
* This is designed to work with V2 format used by litegraphService.
*
* @param nodeDefImpl - The ComfyNodeDefImpl containing both V1 and V2 formats
* @param inputs - The V2 format inputs (flat Record<string, InputSpec>)
* @returns Array of InputSpec objects in the correct order
*/
export function getOrderedInputSpecs(
nodeDefImpl: ComfyNodeDefImpl,
inputs: Record<string, InputSpec>
): InputSpec[] {
const orderedInputSpecs: InputSpec[] = []
// If no input_order, return default Object.values order
if (!nodeDefImpl.input_order) {
return Object.values(inputs)
}
// Process required inputs in specified order
if (nodeDefImpl.input_order.required) {
for (const name of nodeDefImpl.input_order.required) {
const inputSpec = inputs[name]
if (inputSpec && !inputSpec.isOptional) {
orderedInputSpecs.push(inputSpec)
}
}
}
// Process optional inputs in specified order
if (nodeDefImpl.input_order.optional) {
for (const name of nodeDefImpl.input_order.optional) {
const inputSpec = inputs[name]
if (inputSpec && inputSpec.isOptional) {
orderedInputSpecs.push(inputSpec)
}
}
}
// Add any remaining inputs not specified in input_order
const processedNames = new Set(orderedInputSpecs.map((spec) => spec.name))
for (const inputSpec of Object.values(inputs)) {
if (!processedNames.has(inputSpec.name)) {
orderedInputSpecs.push(inputSpec)
}
}
return orderedInputSpecs
}
/**
* Reorders widget values based on the input_order to match expected widget order.
* This is used when widgets were created in a different order than input_order specifies.
*
* @param widgetValues - The current widget values array
* @param currentWidgetOrder - The current order of widget names
* @param inputOrder - The desired order from input_order
* @returns Reordered widget values array
*/
export function sortWidgetValuesByInputOrder(
widgetValues: TWidgetValue[],
currentWidgetOrder: string[],
inputOrder: string[]
): TWidgetValue[] {
if (!inputOrder || inputOrder.length === 0) {
return widgetValues
}
// Create a map of widget name to value
const valueMap = new Map<string, TWidgetValue>()
currentWidgetOrder.forEach((name, index) => {
if (index < widgetValues.length) {
valueMap.set(name, widgetValues[index])
}
})
// Reorder based on input_order
const reordered: TWidgetValue[] = []
const usedNames = new Set<string>()
// First, add values in the order specified by input_order
for (const name of inputOrder) {
if (valueMap.has(name)) {
reordered.push(valueMap.get(name))
usedNames.add(name)
}
}
// Then add any remaining values not in input_order
for (const [name, value] of valueMap.entries()) {
if (!usedNames.has(name)) {
reordered.push(value)
}
}
// If there are extra values not in the map, append them
if (widgetValues.length > currentWidgetOrder.length) {
for (let i = currentWidgetOrder.length; i < widgetValues.length; i++) {
reordered.push(widgetValues[i])
}
}
return reordered
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff