Add DUMAS external folder video saver
This commit is contained in:
+66
-2
@@ -21,6 +21,11 @@ except ImportError: # The ComfyUI runtime provides NumPy; keep import-time test
|
||||
|
||||
import folder_paths
|
||||
|
||||
try:
|
||||
from .dumas_image_nodes import _next_available_relative_path
|
||||
except ImportError: # Support the lightweight standalone test import.
|
||||
from dumas_image_nodes import _next_available_relative_path
|
||||
|
||||
|
||||
_SAFE_NAME = re.compile(r"[^A-Za-z0-9_.-]+")
|
||||
|
||||
@@ -72,7 +77,7 @@ def _write_wav(audio, path, start_sample=0):
|
||||
return sample_rate
|
||||
|
||||
|
||||
def _encode_images(images, audio, output_path, fps, start_frame=0):
|
||||
def _encode_images(images, audio, output_path, fps, start_frame=0, quality=18):
|
||||
if images is None or len(images) <= start_frame:
|
||||
raise ValueError("Dumas video output has no frames after the requested overlap.")
|
||||
first = images[0].detach().cpu().numpy() if hasattr(images[0], "detach") else np.asarray(images[0])
|
||||
@@ -93,7 +98,8 @@ def _encode_images(images, audio, output_path, fps, start_frame=0):
|
||||
]
|
||||
if wav_path is not None:
|
||||
command += ["-i", str(wav_path)]
|
||||
command += ["-map", "0:v:0", "-c:v", "libx264", "-preset", "fast", "-crf", "18", "-pix_fmt", "yuv420p"]
|
||||
crf = max(1, min(51, int(quality)))
|
||||
command += ["-map", "0:v:0", "-c:v", "libx264", "-preset", "fast", "-crf", str(crf), "-pix_fmt", "yuv420p"]
|
||||
if wav_path is not None:
|
||||
command += ["-map", "1:a:0", "-c:a", "aac", "-b:a", "192k", "-shortest"]
|
||||
command += ["-movflags", "+faststart", str(output_path)]
|
||||
@@ -238,6 +244,62 @@ class DumasStandaloneVideoNode:
|
||||
return str(full), str(complete), count, count / float(fps), reference
|
||||
|
||||
|
||||
class DumasSaveVideoNode:
|
||||
"""Save an IMAGE batch as an MP4 in any user-selected folder."""
|
||||
|
||||
DESCRIPTION = (
|
||||
"Save Video DUMAS writes an image batch as an MP4 to any folder on the "
|
||||
"server. Leave the folder empty for ComfyUI's output folder, or type "
|
||||
"an absolute path. Existing files are never overwritten."
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"images": ("IMAGE",),
|
||||
"fps": ("FLOAT", {"default": 24.0, "min": 1.0, "max": 240.0, "step": 0.001}),
|
||||
"folder": ("STRING", {"default": "", "multiline": False}),
|
||||
"filename": ("STRING", {"default": "dumas_video_%counter%", "multiline": False}),
|
||||
"quality": ("INT", {"default": 18, "min": 1, "max": 51}),
|
||||
"save_on_run": ("BOOLEAN", {"default": True}),
|
||||
},
|
||||
"optional": {"audio": ("AUDIO",)},
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, **_kwargs):
|
||||
return float("nan")
|
||||
|
||||
RETURN_TYPES = ("STRING", "INT", "FLOAT")
|
||||
RETURN_NAMES = ("video_path", "frames", "duration")
|
||||
FUNCTION = "save"
|
||||
CATEGORY = "Dumas/Video"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def save(self, images, fps, folder, filename, quality, save_on_run=True, audio=None):
|
||||
if images is None or len(images) == 0:
|
||||
raise ValueError("Save Video DUMAS received no frames.")
|
||||
fps = float(fps)
|
||||
if fps <= 0:
|
||||
raise ValueError("FPS must be greater than zero.")
|
||||
base = Path(folder).expanduser() if str(folder or "").strip() else Path(folder_paths.get_output_directory())
|
||||
if not save_on_run:
|
||||
base = Path(folder_paths.get_temp_directory())
|
||||
base = base.resolve()
|
||||
base.mkdir(parents=True, exist_ok=True)
|
||||
relative = str(filename or "dumas_video_%counter%").replace("\\", "/").strip().lstrip("/")
|
||||
if not relative.lower().endswith(".mp4"):
|
||||
relative += ".mp4"
|
||||
relative = _next_available_relative_path(str(base), relative)
|
||||
target = (base / relative).resolve()
|
||||
if os.path.commonpath((str(base), str(target))) != str(base):
|
||||
raise ValueError("Video filename must stay inside the selected folder.")
|
||||
_encode_images(images, audio, target, fps, 0, quality)
|
||||
frames = len(images)
|
||||
return {"ui": {"text": [str(target)]}, "result": (str(target), frames, frames / fps)}
|
||||
|
||||
|
||||
class DumasPrepareContinuationNode:
|
||||
"""Prepare a generated continuation for chaining and presentation.
|
||||
|
||||
@@ -369,12 +431,14 @@ class DumasJoinVideoClipsNode:
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"DumasStandaloneVideo": DumasStandaloneVideoNode,
|
||||
"DumasSaveVideo": DumasSaveVideoNode,
|
||||
"DumasPrepareContinuation": DumasPrepareContinuationNode,
|
||||
"DumasJoinVideoClips": DumasJoinVideoClipsNode,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DumasStandaloneVideo": "Dumas Standalone Video",
|
||||
"DumasSaveVideo": "Save Video DUMAS",
|
||||
"DumasPrepareContinuation": "Dumas Prepare Continuation",
|
||||
"DumasJoinVideoClips": "Dumas Join Video Clips (No Re-encode)",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user