From 0a26e2defdb7b95bf9ffe09fdf4630fa5ef222f8 Mon Sep 17 00:00:00 2001 From: Austin Mroz Date: Fri, 16 Aug 2024 14:46:45 -0500 Subject: [PATCH] Fix I/O as latent At some point recently, likely the execution inversion update, the conditional toggles to load or save as latent stopped working. While I don't have a full grasp of the entire system yet, included in the new documentation is a recommended way of creating a node which produce or consume multiple types of input and output. The code has been rewritten to follow this method. As a result: - Things function again - Shady link swapping on queue is no longer performed - The image input on Video Combine is once again required --- videohelpersuite/load_video_nodes.py | 15 ++++++++------- videohelpersuite/nodes.py | 5 ++--- videohelpersuite/utils.py | 4 ++++ web/js/VHS.core.js | 22 ---------------------- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/videohelpersuite/load_video_nodes.py b/videohelpersuite/load_video_nodes.py index c9377ee..fcedefb 100644 --- a/videohelpersuite/load_video_nodes.py +++ b/videohelpersuite/load_video_nodes.py @@ -9,7 +9,8 @@ import psutil import folder_paths from comfy.utils import common_upscale, ProgressBar 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 +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 video_extensions = ['webm', 'mp4', 'mkv', 'gif'] @@ -222,9 +223,9 @@ def load_video_cv(video: str, force_rate: int, force_size: str, "loaded_height": new_size[1], } if vae is None: - return (images, len(images), audio, video_info, None) + return (images, len(images), audio, video_info) else: - return (None, len(images), audio, video_info, {"samples": images}) + return ({"samples": images}, len(images), audio, video_info) @@ -259,8 +260,8 @@ class LoadVideoUpload: CATEGORY = "Video Helper Suite 🎥🅥🅗🅢" - RETURN_TYPES = ("IMAGE", "INT", "AUDIO", "VHS_VIDEOINFO", "LATENT") - RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info", "LATENT") + RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO") + RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info") FUNCTION = "load_video" @@ -305,8 +306,8 @@ class LoadVideoPath: CATEGORY = "Video Helper Suite 🎥🅥🅗🅢" - RETURN_TYPES = ("IMAGE", "INT", "AUDIO", "VHS_VIDEOINFO", "LATENT") - RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info", "LATENT") + RETURN_TYPES = (imageOrLatent, "INT", "AUDIO", "VHS_VIDEOINFO") + RETURN_NAMES = ("IMAGE", "frame_count", "audio", "video_info") FUNCTION = "load_video" diff --git a/videohelpersuite/nodes.py b/videohelpersuite/nodes.py index 688c8ff..2e968b8 100755 --- a/videohelpersuite/nodes.py +++ b/videohelpersuite/nodes.py @@ -19,7 +19,7 @@ from .image_latent_nodes import * from .load_video_nodes import LoadVideoUpload, LoadVideoPath from .load_images_nodes import LoadImagesFromDirectoryUpload, LoadImagesFromDirectoryPath from .batched_nodes import VAEEncodeBatched, VAEDecodeBatched -from .utils import ffmpeg_path, get_audio, hash_path, validate_path, requeue_workflow, gifski_path, calculate_file_hash, strip_path, try_download_video, is_url +from .utils import ffmpeg_path, get_audio, hash_path, validate_path, requeue_workflow, gifski_path, calculate_file_hash, strip_path, try_download_video, is_url, imageOrLatent from comfy.utils import ProgressBar folder_paths.folder_names_and_paths["VHS_video_formats"] = ( @@ -207,6 +207,7 @@ class VideoCombine: ffmpeg_formats = get_video_formats() return { "required": { + "images": (imageOrLatent,), "frame_rate": ( "FLOAT", {"default": 8, "min": 1, "step": 1}, @@ -218,11 +219,9 @@ class VideoCombine: "save_output": ("BOOLEAN", {"default": True}), }, "optional": { - "images": ("IMAGE",), "audio": ("AUDIO",), "meta_batch": ("VHS_BatchManager",), "vae": ("VAE",), - "latents": ("LATENT",), }, "hidden": { "prompt": "PROMPT", diff --git a/videohelpersuite/utils.py b/videohelpersuite/utils.py index 1a5b1e8..9bc58c1 100644 --- a/videohelpersuite/utils.py +++ b/videohelpersuite/utils.py @@ -39,6 +39,10 @@ def ffmpeg_suitability(path): score += int(copyright_year) return score +class ImageOrLatent(str): + def __ne__(self, other): + return not (other == "IMAGE" or other == "LATENT") +imageOrLatent = ImageOrLatent("IMAGE") if "VHS_FORCE_FFMPEG_PATH" in os.environ: ffmpeg_path = os.environ.get("VHS_FORCE_FFMPEG_PATH") diff --git a/web/js/VHS.core.js b/web/js/VHS.core.js index fb3dec9..a8a420c 100755 --- a/web/js/VHS.core.js +++ b/web/js/VHS.core.js @@ -489,16 +489,6 @@ function addVAEOutputToggle(nodeType, nodeData) { } } }); - chainCallback(nodeType.prototype, "onNodeCreated", function(contype, slot, iscon, linf) { - this.updateLink = function(link) { - if (link.origin_slot == 0 && this.outputs[0].type=="LATENT") { - return {'origin_id': link.origin_id, - 'origin_slot': 4} - } - return link - } - }); - } function addVAEInputToggle(nodeType, nodeData) { delete nodeData.input.optional["latents"] @@ -526,18 +516,6 @@ function addVAEInputToggle(nodeType, nodeData) { } } }); - chainCallback(nodeType.prototype, "onNodeCreated", function(contype, slot, iscon, linf) { - this.original_getInputLink = this.getInputLink - this.getInputLink = function(slot) { - let link = this.original_getInputLink(slot) - if (slot == 0 && this.inputs[0].type=="LATENT") { - return {'origin_id': link.origin_id, - 'origin_slot': link.origin_slot, - 'target_slot': 4} - } - return link - } - }); } function addDateFormatting(nodeType, field, timestamp_widget = false) {