代码拉取完成,页面将自动刷新
同步操作将从 yanlang0123/ComfyUI_Lam 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import folder_paths
import cv2
import os
import torch
import numpy as np
import imageio
class Image2Video:
def __init__(self):
self.output_dir = os.path.join(folder_paths.get_output_directory(), 'video')
if not os.path.exists(self.output_dir):
os .makedirs(self.output_dir)
@classmethod
def INPUT_TYPES(s):
return {"required":
{"images": ("IMAGE", ),
"fps": ("INT", {"default": 20, "min": 1, "max": 100000}),
"img_frame_size": ("INT", {"default": 1, "min": 1, "max": 100000}),
"filename_prefix": ("STRING", {"default": "comfyUI"})},
}
CATEGORY = "lam"
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("视频文件名",)
FUNCTION = "img2video"
OUTPUT_NODE = True
#OUTPUT_IS_LIST = (True,)
def img2video(self, images,fps,img_frame_size,filename_prefix):
imaget_np=images.numpy()
imgt_shape=imaget_np.shape
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0])
file = f"{filename}_{counter:05}_.mp4"
with imageio.get_writer(os.path.join(full_output_folder, file), fps=fps) as video:
for i in range(imgt_shape[0]):
imaget=np.uint8(imaget_np[i]*255)
for n in range(img_frame_size):
video.append_data(imaget)# 写入视频
return {"ui": {"text": "视频保存成功文件地址:"+os.path.join(full_output_folder, file),
'videos':[{'filename':file,'type':'output','subfolder':'video'}]}, "result": (os.path.join(full_output_folder, file),)}
NODE_CLASS_MAPPINGS = {
"Image2Video": Image2Video
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"Image2Video": "图片转视频"
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。