Update run_generator.py
Browse files- run_generator.py +135 -28
run_generator.py
CHANGED
|
@@ -11,20 +11,17 @@ import subprocess
|
|
| 11 |
import random
|
| 12 |
import argparse
|
| 13 |
from typing import Sequence, Mapping, Any, Union
|
| 14 |
-
import shutil
|
| 15 |
|
| 16 |
-
# --- 0. κΈ°λ³Έ μ€μ λ° μΈμ νμ±
|
| 17 |
def parse_args():
|
| 18 |
parser = argparse.ArgumentParser(description="ComfyUI Video Generation Script with All Controls from 1.py")
|
| 19 |
parser.add_argument("--positive_prompt", type=str, required=True); parser.add_argument("--negative_prompt", type=str, required=True)
|
| 20 |
parser.add_argument("--width", type=int, required=True); parser.add_argument("--height", type=int, required=True)
|
| 21 |
parser.add_argument("--length", type=int, required=True); parser.add_argument("--upscale_ratio", type=float, required=True)
|
| 22 |
-
|
| 23 |
-
# β¨ μμ : CFG μΈμ λΆλ¦¬
|
| 24 |
parser.add_argument("--steps", type=int, default=4)
|
| 25 |
-
parser.add_argument("--cfg_high", type=float, default=1.0)
|
| 26 |
-
parser.add_argument("--cfg_low", type=float, default=1.0)
|
| 27 |
-
|
| 28 |
parser.add_argument("--sampler_name_high", type=str, default="euler"); parser.add_argument("--scheduler_high", type=str, default="simple")
|
| 29 |
parser.add_argument("--sampler_name_low", type=str, default="euler"); parser.add_argument("--scheduler_low", type=str, default="simple")
|
| 30 |
parser.add_argument("--noise_seed", type=int, default=-1); parser.add_argument("--split_point_percent", type=float, default=50.0)
|
|
@@ -103,10 +100,41 @@ def import_custom_nodes() -> None:
|
|
| 103 |
def main():
|
| 104 |
args = parse_args()
|
| 105 |
print("π λμμ μμ±μ μμν©λλ€ (Full Control Mode, VRAM Optimized)...\n")
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
os.makedirs(f"{COMFYUI_BASE_PATH}/output/interpolated", exist_ok=True)
|
|
|
|
| 110 |
add_comfyui_directory_to_sys_path()
|
| 111 |
try: from utils.extra_config import load_extra_path_config
|
| 112 |
except ImportError: print("β οΈ ComfyUIμ extra_model_paths.yaml λ‘λ© μ€ν¨ (무μνκ³ μ§ν)"); load_extra_path_config = lambda x: None
|
|
@@ -126,10 +154,9 @@ def main():
|
|
| 126 |
clipvisionencode=NODE_CLASS_MAPPINGS["CLIPVisionEncode"]()
|
| 127 |
pathchsageattentionkj=NODE_CLASS_MAPPINGS["PathchSageAttentionKJ"]()
|
| 128 |
|
| 129 |
-
# --- β¨ 1λ¨κ³: CLIP Vision λ‘μ§ μΆκ° λ° λ©λͺ¨λ¦¬ ν΄μ
|
| 130 |
print("\n1λ¨κ³: λ°μ΄ν° λ‘λ© λ° μ΄κΈ° Latent μμ± μ€...");
|
| 131 |
print(f" - CLIP λ‘λ©: {args.clip_name}");
|
| 132 |
-
# β¨ SyntaxError μμ : λΆνμν \ μ κ±°
|
| 133 |
cliploader_460 = cliploader.load_clip(clip_name=args.clip_name, type="wan", device="default");
|
| 134 |
cliptextencode_462 = cliptextencode.encode(text=args.positive_prompt, clip=get_value_at_index(cliploader_460, 0));
|
| 135 |
cliptextencode_463 = cliptextencode.encode(text=args.negative_prompt, clip=get_value_at_index(cliploader_460, 0));
|
|
@@ -137,7 +164,7 @@ def main():
|
|
| 137 |
|
| 138 |
imageresizekjv2_401 = imageresizekjv2.resize(
|
| 139 |
width=args.width, height=args.height,
|
| 140 |
-
upscale_method=args.input_resize_algo,
|
| 141 |
image=get_value_at_index(loadimage_88, 0), keep_proportion="crop",
|
| 142 |
pad_color="0, 0, 0", crop_position="center", divisible_by=2,
|
| 143 |
unique_id=random.randint(1, 2**64)
|
|
@@ -149,7 +176,7 @@ def main():
|
|
| 149 |
clipvisionencode_cv = clipvisionencode.encode(
|
| 150 |
crop="none",
|
| 151 |
clip_vision=get_value_at_index(clipvisionloader_cv, 0),
|
| 152 |
-
image=get_value_at_index(imageresizekjv2_401, 0)
|
| 153 |
);
|
| 154 |
clip_vision_output = get_value_at_index(clipvisionencode_cv, 0)
|
| 155 |
|
|
@@ -164,7 +191,7 @@ def main():
|
|
| 164 |
positive=get_value_at_index(cliptextencode_462, 0),
|
| 165 |
negative=get_value_at_index(cliptextencode_463, 0),
|
| 166 |
vae=get_value_at_index(vaeloader_temp, 0),
|
| 167 |
-
clip_vision_output=clip_vision_output,
|
| 168 |
start_image=get_value_at_index(imageresizekjv2_401, 0)
|
| 169 |
);
|
| 170 |
|
|
@@ -183,7 +210,7 @@ def main():
|
|
| 183 |
if args.lora_high_2_name != "None": print(f" - H LoRA 2: {args.lora_high_2_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_high_2_name, strength_model=args.lora_high_2_strength_model, strength_clip=args.lora_high_2_strength_clip, model=model_for_patching, clip=clip)
|
| 184 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 185 |
|
| 186 |
-
#
|
| 187 |
ksampleradvanced_466 = ksampleradvanced.sample(add_noise="enable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_high, sampler_name=args.sampler_name_high, scheduler=args.scheduler_high, start_at_step=0, end_at_step=split_step, return_with_leftover_noise="enable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(wanimagetovideo_464, 2));
|
| 188 |
|
| 189 |
if to_bool(args.sageattention): del pathchsageattentionkj_124
|
|
@@ -195,7 +222,7 @@ def main():
|
|
| 195 |
if args.lora_low_2_name != "None": print(f" - L LoRA 2: {args.lora_low_2_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_low_2_name, strength_model=args.lora_low_2_strength_model, strength_clip=args.lora_low_2_strength_clip, model=model_for_patching, clip=clip)
|
| 196 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 197 |
|
| 198 |
-
#
|
| 199 |
ksampleradvanced_465 = ksampleradvanced.sample(add_noise="disable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_low, sampler_name=args.sampler_name_low, scheduler=args.scheduler_low, start_at_step=split_step, end_at_step=10000, return_with_leftover_noise="disable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(ksampleradvanced_466, 0));
|
| 200 |
|
| 201 |
if to_bool(args.sageattention): del pathchsageattentionkj_129
|
|
@@ -228,7 +255,7 @@ def main():
|
|
| 228 |
if loaded_images is None: print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό 건λλλλ€."); continue
|
| 229 |
imageupscale_chunk = imageupscalewithmodel.upscale(upscale_model=get_value_at_index(upscalemodelloader_384, 0), image=loaded_images);
|
| 230 |
imagescale_chunk = imagescaleby.upscale(
|
| 231 |
-
upscale_method=args.output_resize_algo,
|
| 232 |
scale_by=scale_by_ratio,
|
| 233 |
image=get_value_at_index(imageupscale_chunk, 0)
|
| 234 |
);
|
|
@@ -237,7 +264,7 @@ def main():
|
|
| 237 |
del upscalemodelloader_384; clear_memory(); combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/up"; print("5λ¨κ³ μλ£.")
|
| 238 |
else: print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λλ (λΉμ¨ 1.0).")
|
| 239 |
|
| 240 |
-
# --- β¨ 6λ¨κ³: RIFE μ²ν¬ λ‘μ§ μμ (Overlap μ μ©)
|
| 241 |
print("\n6λ¨κ³: λΉλμ€ κ²°ν© μ€λΉ μ€..."); final_frame_rate = float(args.frame_rate); ffmpeg_input_dir = combine_input_dir_for_ffmpeg
|
| 242 |
if to_bool(args.interpolation):
|
| 243 |
print(" - νλ μ λ³΄κ° (RIFE)μ νμ±νν©λλ€."); interpolated_dir = f"{COMFYUI_BASE_PATH}/output/interpolated"; source_dir = combine_input_dir_for_ffmpeg
|
|
@@ -277,7 +304,7 @@ def main():
|
|
| 277 |
|
| 278 |
if loaded_images is None:
|
| 279 |
print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό οΏ½οΏ½οΏ½λλλλ€.");
|
| 280 |
-
current_frame_idx += chunk_size
|
| 281 |
is_first_chunk = False
|
| 282 |
continue
|
| 283 |
|
|
@@ -291,7 +318,7 @@ def main():
|
|
| 291 |
|
| 292 |
images_to_save = rife_chunk_result_tensor
|
| 293 |
if not is_first_chunk:
|
| 294 |
-
#
|
| 295 |
print(f" - (Overlap) μ€λ³΅ νλ μ 1κ° μ κ±° ν μ μ₯")
|
| 296 |
images_to_save = rife_chunk_result_tensor[1:]
|
| 297 |
|
|
@@ -307,7 +334,7 @@ def main():
|
|
| 307 |
# --- 6λ¨κ³ μμ μλ£ ---
|
| 308 |
|
| 309 |
print(f" - μ΅μ’
λΉλμ€λ₯Ό FFmpeg ({args.video_encoder})λ‘ κ²°ν©ν©λλ€..."); print(f" - μ
λ ₯ ν΄λ: '{ffmpeg_input_dir}'")
|
| 310 |
-
input_pattern = os.path.join(ffmpeg_input_dir, "example_%05d_.png")
|
| 311 |
timestamp = time.strftime("%Y%m%d-%H%M%S"); output_filename = f"AnimateDiff_{timestamp}.mp4"; output_path = os.path.join(COMFYUI_BASE_PATH, "output", output_filename)
|
| 312 |
ffmpeg_cmd = ["ffmpeg", "-framerate", str(final_frame_rate), "-i", input_pattern]
|
| 313 |
encoder_choice = args.video_encoder
|
|
@@ -328,12 +355,12 @@ def main():
|
|
| 328 |
except Exception as e: print(f" β μ€λ₯: FFmpeg μ€ν μ€ μμμΉ λͺ»ν μ€λ₯ λ°μ: {e}"); raise
|
| 329 |
print("β
λͺ¨λ λ¨κ³ μλ£.")
|
| 330 |
|
| 331 |
-
# --- β¨
|
| 332 |
latest_video = None
|
| 333 |
|
| 334 |
if os.path.exists(output_path):
|
| 335 |
latest_video = output_path
|
| 336 |
-
print(f"LATEST_VIDEO_PATH:{latest_video}")
|
| 337 |
else:
|
| 338 |
output_dir = os.path.join(COMFYUI_BASE_PATH, "output");
|
| 339 |
video_files = glob.glob(os.path.join(output_dir, '**', '*.mp4'), recursive=True) + \
|
|
@@ -343,7 +370,7 @@ def main():
|
|
| 343 |
raise FileNotFoundError("μμ±λ λμμ νμΌμ μ°Ύμ μ μμ΅λλ€!")
|
| 344 |
|
| 345 |
latest_video = max(video_files, key=os.path.getctime)
|
| 346 |
-
print(f"LATEST_VIDEO_PATH:{latest_video}")
|
| 347 |
|
| 348 |
if latest_video is None:
|
| 349 |
raise FileNotFoundError("μ΅μ’
λΉλμ€ κ²½λ‘λ₯Ό νμ ν μ μμ΅λλ€. μ€ν¬λ¦½νΈλ₯Ό νμΈνμΈμ.")
|
|
@@ -353,10 +380,90 @@ def main():
|
|
| 353 |
try:
|
| 354 |
shutil.copy2(latest_video, original_copy_path)
|
| 355 |
print(f"β
μλ³Έ 볡μ¬λ³Έ μμ± μλ£: {original_copy_path}")
|
| 356 |
-
print(f"ORIGINAL_COPY_PATH:{original_copy_path}")
|
| 357 |
except Exception as e:
|
| 358 |
print(f"β μλ³Έ 볡μ¬λ³Έ μμ± μ€ν¨: {e}")
|
| 359 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
if __name__ == "__main__":
|
| 362 |
-
main()
|
|
|
|
| 11 |
import random
|
| 12 |
import argparse
|
| 13 |
from typing import Sequence, Mapping, Any, Union
|
| 14 |
+
import shutil
|
| 15 |
|
| 16 |
+
# --- 0. κΈ°λ³Έ μ€μ λ° μΈμ νμ± ---
|
| 17 |
def parse_args():
|
| 18 |
parser = argparse.ArgumentParser(description="ComfyUI Video Generation Script with All Controls from 1.py")
|
| 19 |
parser.add_argument("--positive_prompt", type=str, required=True); parser.add_argument("--negative_prompt", type=str, required=True)
|
| 20 |
parser.add_argument("--width", type=int, required=True); parser.add_argument("--height", type=int, required=True)
|
| 21 |
parser.add_argument("--length", type=int, required=True); parser.add_argument("--upscale_ratio", type=float, required=True)
|
|
|
|
|
|
|
| 22 |
parser.add_argument("--steps", type=int, default=4)
|
| 23 |
+
parser.add_argument("--cfg_high", type=float, default=1.0)
|
| 24 |
+
parser.add_argument("--cfg_low", type=float, default=1.0)
|
|
|
|
| 25 |
parser.add_argument("--sampler_name_high", type=str, default="euler"); parser.add_argument("--scheduler_high", type=str, default="simple")
|
| 26 |
parser.add_argument("--sampler_name_low", type=str, default="euler"); parser.add_argument("--scheduler_low", type=str, default="simple")
|
| 27 |
parser.add_argument("--noise_seed", type=int, default=-1); parser.add_argument("--split_point_percent", type=float, default=50.0)
|
|
|
|
| 100 |
def main():
|
| 101 |
args = parse_args()
|
| 102 |
print("π λμμ μμ±μ μμν©λλ€ (Full Control Mode, VRAM Optimized)...\n")
|
| 103 |
+
|
| 104 |
+
# π¨π¨π¨ μμ λ λΆλΆ μμ: .mp4, .mkv, .webm νμΌμ μ μΈνκ³ output ν΄λ μ 리 π¨π¨π¨
|
| 105 |
+
output_dir = os.path.join(COMFYUI_BASE_PATH, 'output')
|
| 106 |
+
print(f" - μ΄μ μΆλ ₯λ¬Ό μ 리 μ€... (Output: {output_dir})")
|
| 107 |
+
|
| 108 |
+
deleted_count = 0
|
| 109 |
+
try:
|
| 110 |
+
# output ν΄λ λ΄μ λͺ¨λ νμΌκ³Ό ν΄λ λͺ©λ‘μ κ°μ Έμ΅λλ€.
|
| 111 |
+
for item_name in os.listdir(output_dir):
|
| 112 |
+
item_path = os.path.join(output_dir, item_name)
|
| 113 |
+
|
| 114 |
+
# π‘ 쑰건: λΉλμ€ νμΌ νμ₯μ(.mp4, .mkv, .webm)λ μμ νμ§ μκ³ λ³΄μ‘΄ν©λλ€.
|
| 115 |
+
if item_name.lower().endswith(('.mp4', '.mkv', '.webm')):
|
| 116 |
+
print(f" - ποΈ λΉλμ€ νμΌ '{item_name}'μ 보쑴ν©λλ€.")
|
| 117 |
+
continue
|
| 118 |
+
|
| 119 |
+
# νμΌ λλ λ§ν¬μΈ κ²½μ° μμ
|
| 120 |
+
if os.path.isfile(item_path) or os.path.islink(item_path):
|
| 121 |
+
os.unlink(item_path)
|
| 122 |
+
deleted_count += 1
|
| 123 |
+
# ν΄λμΈ κ²½μ° μ¬κ·μ μΌλ‘ μμ
|
| 124 |
+
elif os.path.isdir(item_path):
|
| 125 |
+
shutil.rmtree(item_path)
|
| 126 |
+
deleted_count += 1
|
| 127 |
+
|
| 128 |
+
print(f" β
μ 리 μλ£. 보쑴λ λΉλμ€ μΈ {deleted_count}κ°μ νλͺ©μ΄ μμ λμμ΅λλ€.")
|
| 129 |
+
except Exception as e:
|
| 130 |
+
print(f" β μΆλ ₯ ν΄λ μ 리 μ€ μ€λ₯ λ°μ: {e}")
|
| 131 |
+
# π¨π¨π¨ μμ λ λΆλΆ λ π¨π¨π¨
|
| 132 |
+
|
| 133 |
+
# μμ ν΄λ μ¬μμ± (μ 리 κ³Όμ μμ μμ λμμ μ μμ)
|
| 134 |
+
os.makedirs(f"{COMFYUI_BASE_PATH}/output/temp", exist_ok=True);
|
| 135 |
+
os.makedirs(f"{COMFYUI_BASE_PATH}/output/up", exist_ok=True)
|
| 136 |
os.makedirs(f"{COMFYUI_BASE_PATH}/output/interpolated", exist_ok=True)
|
| 137 |
+
|
| 138 |
add_comfyui_directory_to_sys_path()
|
| 139 |
try: from utils.extra_config import load_extra_path_config
|
| 140 |
except ImportError: print("β οΈ ComfyUIμ extra_model_paths.yaml λ‘λ© μ€ν¨ (무μνκ³ μ§ν)"); load_extra_path_config = lambda x: None
|
|
|
|
| 154 |
clipvisionencode=NODE_CLASS_MAPPINGS["CLIPVisionEncode"]()
|
| 155 |
pathchsageattentionkj=NODE_CLASS_MAPPINGS["PathchSageAttentionKJ"]()
|
| 156 |
|
| 157 |
+
# --- β¨ 1λ¨κ³: CLIP Vision λ‘μ§ μΆκ° λ° λ©λͺ¨λ¦¬ ν΄μ ---
|
| 158 |
print("\n1λ¨κ³: λ°μ΄ν° λ‘λ© λ° μ΄κΈ° Latent μμ± μ€...");
|
| 159 |
print(f" - CLIP λ‘λ©: {args.clip_name}");
|
|
|
|
| 160 |
cliploader_460 = cliploader.load_clip(clip_name=args.clip_name, type="wan", device="default");
|
| 161 |
cliptextencode_462 = cliptextencode.encode(text=args.positive_prompt, clip=get_value_at_index(cliploader_460, 0));
|
| 162 |
cliptextencode_463 = cliptextencode.encode(text=args.negative_prompt, clip=get_value_at_index(cliploader_460, 0));
|
|
|
|
| 164 |
|
| 165 |
imageresizekjv2_401 = imageresizekjv2.resize(
|
| 166 |
width=args.width, height=args.height,
|
| 167 |
+
upscale_method=args.input_resize_algo,
|
| 168 |
image=get_value_at_index(loadimage_88, 0), keep_proportion="crop",
|
| 169 |
pad_color="0, 0, 0", crop_position="center", divisible_by=2,
|
| 170 |
unique_id=random.randint(1, 2**64)
|
|
|
|
| 176 |
clipvisionencode_cv = clipvisionencode.encode(
|
| 177 |
crop="none",
|
| 178 |
clip_vision=get_value_at_index(clipvisionloader_cv, 0),
|
| 179 |
+
image=get_value_at_index(imageresizekjv2_401, 0)
|
| 180 |
);
|
| 181 |
clip_vision_output = get_value_at_index(clipvisionencode_cv, 0)
|
| 182 |
|
|
|
|
| 191 |
positive=get_value_at_index(cliptextencode_462, 0),
|
| 192 |
negative=get_value_at_index(cliptextencode_463, 0),
|
| 193 |
vae=get_value_at_index(vaeloader_temp, 0),
|
| 194 |
+
clip_vision_output=clip_vision_output,
|
| 195 |
start_image=get_value_at_index(imageresizekjv2_401, 0)
|
| 196 |
);
|
| 197 |
|
|
|
|
| 210 |
if args.lora_high_2_name != "None": print(f" - H LoRA 2: {args.lora_high_2_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_high_2_name, strength_model=args.lora_high_2_strength_model, strength_clip=args.lora_high_2_strength_clip, model=model_for_patching, clip=clip)
|
| 211 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 212 |
|
| 213 |
+
# μμ : cfg=args.cfg_high μ¬μ©
|
| 214 |
ksampleradvanced_466 = ksampleradvanced.sample(add_noise="enable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_high, sampler_name=args.sampler_name_high, scheduler=args.scheduler_high, start_at_step=0, end_at_step=split_step, return_with_leftover_noise="enable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(wanimagetovideo_464, 2));
|
| 215 |
|
| 216 |
if to_bool(args.sageattention): del pathchsageattentionkj_124
|
|
|
|
| 222 |
if args.lora_low_2_name != "None": print(f" - L LoRA 2: {args.lora_low_2_name}"); model_for_patching, clip = loraloader.load_lora(lora_name=args.lora_low_2_name, strength_model=args.lora_low_2_strength_model, strength_clip=args.lora_low_2_strength_clip, model=model_for_patching, clip=clip)
|
| 223 |
shifted_model = get_value_at_index(modelsamplingsd3.patch(shift=args.shift, model=model_for_patching), 0); final_model = shifted_model;
|
| 224 |
|
| 225 |
+
# μμ : cfg=args.cfg_low μ¬μ©
|
| 226 |
ksampleradvanced_465 = ksampleradvanced.sample(add_noise="disable", noise_seed=final_seed, steps=args.steps, cfg=args.cfg_low, sampler_name=args.sampler_name_low, scheduler=args.scheduler_low, start_at_step=split_step, end_at_step=10000, return_with_leftover_noise="disable", model=final_model, positive=get_value_at_index(wanimagetovideo_464, 0), negative=get_value_at_index(wanimagetovideo_464, 1), latent_image=get_value_at_index(ksampleradvanced_466, 0));
|
| 227 |
|
| 228 |
if to_bool(args.sageattention): del pathchsageattentionkj_129
|
|
|
|
| 255 |
if loaded_images is None: print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό 건λλλλ€."); continue
|
| 256 |
imageupscale_chunk = imageupscalewithmodel.upscale(upscale_model=get_value_at_index(upscalemodelloader_384, 0), image=loaded_images);
|
| 257 |
imagescale_chunk = imagescaleby.upscale(
|
| 258 |
+
upscale_method=args.output_resize_algo,
|
| 259 |
scale_by=scale_by_ratio,
|
| 260 |
image=get_value_at_index(imageupscale_chunk, 0)
|
| 261 |
);
|
|
|
|
| 264 |
del upscalemodelloader_384; clear_memory(); combine_input_dir_for_ffmpeg = f"{COMFYUI_BASE_PATH}/output/up"; print("5λ¨κ³ μλ£.")
|
| 265 |
else: print("\n5λ¨κ³: μ
μ€μΌμΌλ§ 건λλ (λΉμ¨ 1.0).")
|
| 266 |
|
| 267 |
+
# --- β¨ 6λ¨κ³: RIFE μ²ν¬ λ‘μ§ μμ (Overlap μ μ©) ---
|
| 268 |
print("\n6λ¨κ³: λΉλμ€ κ²°ν© μ€λΉ μ€..."); final_frame_rate = float(args.frame_rate); ffmpeg_input_dir = combine_input_dir_for_ffmpeg
|
| 269 |
if to_bool(args.interpolation):
|
| 270 |
print(" - νλ μ λ³΄κ° (RIFE)μ νμ±νν©λλ€."); interpolated_dir = f"{COMFYUI_BASE_PATH}/output/interpolated"; source_dir = combine_input_dir_for_ffmpeg
|
|
|
|
| 304 |
|
| 305 |
if loaded_images is None:
|
| 306 |
print(" - (κ²½κ³ ) 건λλΈ μ μλ μ΄λ―Έμ§κ° λ‘λλμμ΅λλ€, μ΄ λ°°μΉλ₯Ό οΏ½οΏ½οΏ½λλλλ€.");
|
| 307 |
+
current_frame_idx += chunk_size
|
| 308 |
is_first_chunk = False
|
| 309 |
continue
|
| 310 |
|
|
|
|
| 318 |
|
| 319 |
images_to_save = rife_chunk_result_tensor
|
| 320 |
if not is_first_chunk:
|
| 321 |
+
# 첫 λ²μ§Έκ° μλ λͺ¨λ μ²ν¬λ κ²ΉμΉλ 첫 νλ μμ μ κ±° (ν
μ μ¬λΌμ΄μ±)
|
| 322 |
print(f" - (Overlap) μ€λ³΅ νλ μ 1κ° μ κ±° ν μ μ₯")
|
| 323 |
images_to_save = rife_chunk_result_tensor[1:]
|
| 324 |
|
|
|
|
| 334 |
# --- 6λ¨κ³ μμ μλ£ ---
|
| 335 |
|
| 336 |
print(f" - μ΅μ’
λΉλμ€λ₯Ό FFmpeg ({args.video_encoder})λ‘ κ²°ν©ν©λλ€..."); print(f" - μ
λ ₯ ν΄λ: '{ffmpeg_input_dir}'")
|
| 337 |
+
input_pattern = os.path.join(ffmpeg_input_dir, "example_%05d_.png")
|
| 338 |
timestamp = time.strftime("%Y%m%d-%H%M%S"); output_filename = f"AnimateDiff_{timestamp}.mp4"; output_path = os.path.join(COMFYUI_BASE_PATH, "output", output_filename)
|
| 339 |
ffmpeg_cmd = ["ffmpeg", "-framerate", str(final_frame_rate), "-i", input_pattern]
|
| 340 |
encoder_choice = args.video_encoder
|
|
|
|
| 355 |
except Exception as e: print(f" β μ€λ₯: FFmpeg μ€ν μ€ μμμΉ λͺ»ν μ€λ₯ λ°μ: {e}"); raise
|
| 356 |
print("β
λͺ¨λ λ¨κ³ μλ£.")
|
| 357 |
|
| 358 |
+
# --- β¨ λΉλμ€ κ²½λ‘ νμ λ° λ³΅μ¬ λ‘μ§ (μ΅μ’
) ---
|
| 359 |
latest_video = None
|
| 360 |
|
| 361 |
if os.path.exists(output_path):
|
| 362 |
latest_video = output_path
|
| 363 |
+
print(f"LATEST_VIDEO_PATH:{latest_video}")
|
| 364 |
else:
|
| 365 |
output_dir = os.path.join(COMFYUI_BASE_PATH, "output");
|
| 366 |
video_files = glob.glob(os.path.join(output_dir, '**', '*.mp4'), recursive=True) + \
|
|
|
|
| 370 |
raise FileNotFoundError("μμ±λ λμμ νμΌμ μ°Ύμ μ μμ΅λλ€!")
|
| 371 |
|
| 372 |
latest_video = max(video_files, key=os.path.getctime)
|
| 373 |
+
print(f"LATEST_VIDEO_PATH:{latest_video}")
|
| 374 |
|
| 375 |
if latest_video is None:
|
| 376 |
raise FileNotFoundError("μ΅μ’
λΉλμ€ κ²½λ‘λ₯Ό νμ ν μ μμ΅λλ€. μ€ν¬λ¦½νΈλ₯Ό νμΈνμΈμ.")
|
|
|
|
| 380 |
try:
|
| 381 |
shutil.copy2(latest_video, original_copy_path)
|
| 382 |
print(f"β
μλ³Έ 볡μ¬λ³Έ μμ± μλ£: {original_copy_path}")
|
| 383 |
+
print(f"ORIGINAL_COPY_PATH:{original_copy_path}")
|
| 384 |
except Exception as e:
|
| 385 |
print(f"β μλ³Έ 볡μ¬λ³Έ μμ± μ€ν¨: {e}")
|
| 386 |
+
# --- λΉλμ€ μ μ₯ μλ£ ---
|
| 387 |
+
|
| 388 |
+
# π¨π¨π¨ μ€μ TXT νμΌ μ μ₯ λ‘μ§ (μ μ§) π¨π¨π¨
|
| 389 |
+
txt_path = f"{base}.txt"
|
| 390 |
+
|
| 391 |
+
try:
|
| 392 |
+
print(f" - μ€μ λ‘κ·Έ TXT νμΌ μμ± μ€: {txt_path}")
|
| 393 |
+
|
| 394 |
+
# λͺ¨λ μΈμ(args)λ₯Ό λμ
λλ¦¬λ‘ λ³ν
|
| 395 |
+
settings = vars(args)
|
| 396 |
+
|
| 397 |
+
with open(txt_path, 'w', encoding='utf-8') as f:
|
| 398 |
+
f.write("========== π¬ Video Generation Settings (Full Control) ==========\n\n")
|
| 399 |
+
|
| 400 |
+
f.write("--- π Prompts & Seed ---\n")
|
| 401 |
+
f.write(f"Seed: {final_seed}\n")
|
| 402 |
+
f.write(f"Positive Prompt: {settings['positive_prompt']}\n")
|
| 403 |
+
f.write(f"Negative Prompt: {settings['negative_prompt']}\n\n")
|
| 404 |
+
|
| 405 |
+
f.write("--- πΌοΈ Size & Length ---\n")
|
| 406 |
+
f.write(f"Width: {settings['width']}, Height: {settings['height']}\n")
|
| 407 |
+
f.write(f"Length (Frames): {settings['length']}\n")
|
| 408 |
+
f.write(f"Upscale Ratio (Final): {settings['upscale_ratio']}\n")
|
| 409 |
+
f.write(f"Input Resize Algo: {settings['input_resize_algo']}\n")
|
| 410 |
+
f.write(f"Output Resize Algo: {settings['output_resize_algo']}\n\n")
|
| 411 |
+
|
| 412 |
+
f.write("--- βοΈ Sampler & Steps ---\n")
|
| 413 |
+
f.write(f"Total Steps: {settings['steps']}\n")
|
| 414 |
+
f.write(f"Split Point (%): {settings['split_point_percent']} -> Step {split_step}\n")
|
| 415 |
+
f.write(f"Shift (Speed): {settings['shift']}\n")
|
| 416 |
+
f.write(f"SageAttention: {settings['sageattention']}\n")
|
| 417 |
+
f.write(f"Connect LoRA Clip: {settings['connect_lora_clip']}\n\n")
|
| 418 |
+
|
| 419 |
+
f.write("--- β‘ High Noise (Initial) ---\n")
|
| 420 |
+
f.write(f"Model (Unet): {settings['unet_high_name']}\n")
|
| 421 |
+
f.write(f"CFG: {settings['cfg_high']}\n")
|
| 422 |
+
f.write(f"Sampler: {settings['sampler_name_high']}\n")
|
| 423 |
+
f.write(f"Scheduler: {settings['scheduler_high']}\n")
|
| 424 |
+
if settings['lora_high_1_name'] != 'None':
|
| 425 |
+
f.write(f"LoRA 1: {settings['lora_high_1_name']} (M:{settings['lora_high_1_strength_model']}, C:{settings['lora_high_1_strength_clip']})\n")
|
| 426 |
+
if settings['lora_high_2_name'] != 'None':
|
| 427 |
+
f.write(f"LoRA 2: {settings['lora_high_2_name']} (M:{settings['lora_high_2_strength_model']}, C:{settings['lora_high_2_strength_clip']})\n")
|
| 428 |
+
f.write("\n")
|
| 429 |
+
|
| 430 |
+
f.write("--- πΏ Low Noise (Refiner) ---\n")
|
| 431 |
+
f.write(f"Model (Unet): {settings['unet_low_name']}\n")
|
| 432 |
+
f.write(f"CFG: {settings['cfg_low']}\n")
|
| 433 |
+
f.write(f"Sampler: {settings['sampler_name_low']}\n")
|
| 434 |
+
f.write(f"Scheduler: {settings['scheduler_low']}\n")
|
| 435 |
+
if settings['lora_low_1_name'] != 'None':
|
| 436 |
+
f.write(f"LoRA 1: {settings['lora_low_1_name']} (M:{settings['lora_low_1_strength_model']}, C:{settings['lora_low_1_strength_clip']})\n")
|
| 437 |
+
if settings['lora_low_2_name'] != 'None':
|
| 438 |
+
f.write(f"LoRA 2: {settings['lora_low_2_name']} (M:{settings['lora_low_2_strength_model']}, C:{settings['lora_low_2_strength_clip']})\n")
|
| 439 |
+
f.write("\n")
|
| 440 |
+
|
| 441 |
+
f.write("--- πΎ Other Models ---\n")
|
| 442 |
+
f.write(f"VAE: {settings['vae_name']}\n")
|
| 443 |
+
f.write(f"CLIP: {settings['clip_name']}\n")
|
| 444 |
+
f.write(f"Upscale Model: {settings['upscale_model_name']} (Scale: {settings['upscale_model_scale']}, Chunk: {settings['upscale_chunk_size']})\n\n")
|
| 445 |
+
|
| 446 |
+
f.write("--- π₯ Video Output & Interpolation ---\n")
|
| 447 |
+
f.write(f"Frame Rate (Base): {settings['frame_rate']}\n")
|
| 448 |
+
f.write(f"Interpolation (RIFE): {settings['interpolation']}\n")
|
| 449 |
+
if to_bool(settings['interpolation']):
|
| 450 |
+
f.write(f" - RIFE Fast Mode: {settings['rife_fast_mode']}\n")
|
| 451 |
+
f.write(f" - RIFE Ensemble: {settings['rife_ensemble']}\n")
|
| 452 |
+
f.write(f" - RIFE Chunk Size: {settings['rife_chunk_size']}\n")
|
| 453 |
+
f.write(f"Video Encoder: {settings['video_encoder']}\n")
|
| 454 |
+
if 'NVENC' in settings['video_encoder']:
|
| 455 |
+
f.write(f" - NVENC CQ: {settings['nvenc_cq']}, Preset: {settings['nvenc_preset']}\n")
|
| 456 |
+
elif 'CPU' in settings['video_encoder']:
|
| 457 |
+
f.write(f" - CPU CRF: {settings['cpu_crf']}\n")
|
| 458 |
+
|
| 459 |
+
f.write("\n========================================================\n")
|
| 460 |
+
|
| 461 |
+
print(f"β
μ€μ λ‘κ·Έ TXT νμΌ μ μ₯ μλ£: {os.path.basename(txt_path)}")
|
| 462 |
+
|
| 463 |
+
except Exception as e:
|
| 464 |
+
print(f"β μ€μ λ‘κ·Έ TXT νμΌ μ μ₯ μ€ν¨: {e}")
|
| 465 |
+
# π¨π¨π¨ TXT νμΌ μ μ₯ λ‘μ§ λ π¨π¨π¨
|
| 466 |
+
|
| 467 |
|
| 468 |
if __name__ == "__main__":
|
| 469 |
+
main()
|