Add continuation tail preparation node

This commit is contained in:
2026-10-12 10:09:54 +00:00
parent 69d93e685a
commit b15d89c185
3 changed files with 91 additions and 2 deletions
+7
View File
@@ -28,6 +28,13 @@ converted using the clip's frame rate, but a codec may choose the nearest safe
packet boundary. For exact frame cuts, use the existing `complete_clip` output
or accept a re-encoded workflow.
### Dumas Prepare Continuation
Give this node the raw output of a continuation generation and its reference
frame count. It produces a clean presentation clip and a `next_reference`
tail clip. Only the tail is intended to feed the next generation; the entire
previous clip is never passed forward as the continuity input.
## Other nodes
- Dumas Image Compare
+74
View File
@@ -176,6 +176,30 @@ def _trim_stream_copy(path, reference_frames, fps, temporary_directory):
return output
def _run_stream_copy(command, error_message):
result = subprocess.run(command, capture_output=True, text=True, check=False)
if result.returncode != 0:
raise RuntimeError(f"{error_message}: {result.stderr.strip()}")
def _stream_copy_trim_to_output(path, start_seconds, output):
_run_stream_copy([
"ffmpeg", "-hide_banner", "-loglevel", "error", "-y",
"-ss", f"{float(start_seconds):.6f}", "-i", str(path),
"-map", "0", "-c", "copy", "-avoid_negative_ts", "make_zero",
"-movflags", "+faststart", str(output),
], "ffmpeg could not create the clean continuation clip")
def _stream_copy_tail(path, seconds, output):
_run_stream_copy([
"ffmpeg", "-hide_banner", "-loglevel", "error", "-y",
"-sseof", f"-{float(seconds):.6f}", "-i", str(path),
"-map", "0", "-c", "copy", "-avoid_negative_ts", "make_zero",
"-movflags", "+faststart", str(output),
], "ffmpeg could not extract the continuation tail")
class DumasStandaloneVideoNode:
"""Save a full generated clip and a trimmed, assembly-ready clip."""
@@ -214,6 +238,54 @@ class DumasStandaloneVideoNode:
return str(full), str(complete), count, count / float(fps), reference
class DumasPrepareContinuationNode:
"""Prepare a generated continuation for chaining and presentation.
The raw clip is never fed forward as a whole. The node extracts only its
trailing reference window for the next generation and creates a clean clip
with the regenerated lead removed.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"raw_clip": ("STRING", {"default": "", "multiline": False}),
"reference_frames": ("INT", {"default": 48, "min": 1, "max": 4096}),
"fps": ("FLOAT", {"default": 24.0, "min": 1.0, "max": 240.0, "step": 0.001}),
"filename_prefix": ("STRING", {"default": "dumas/continuation"}),
},
}
RETURN_TYPES = ("STRING", "STRING", "INT", "FLOAT")
RETURN_NAMES = ("clean_clip", "next_reference", "reference_frames", "clean_duration")
FUNCTION = "prepare"
CATEGORY = "Dumas/Video"
OUTPUT_NODE = True
def prepare(self, raw_clip, reference_frames, fps, filename_prefix):
path = str(raw_clip or "").strip().strip('"').strip("'")
if not path:
raise ValueError("Connect a raw generated continuation clip.")
if not os.path.isfile(path):
raise FileNotFoundError(f"Raw continuation clip not found: {path}")
reference = int(reference_frames)
source_info = _probe(path)
source_fps = _video_fps(source_info)
if abs(source_fps - float(fps)) > 0.01:
fps = source_fps
duration = float((source_info.get("format") or {}).get("duration") or 0.0)
reference_seconds = reference / float(fps)
if duration <= reference_seconds:
raise ValueError("Reference window must be shorter than the raw clip.")
clean = _output_path(f"{filename_prefix}_clean")
tail = _output_path(f"{filename_prefix}_tail")
_stream_copy_trim_to_output(path, reference_seconds, clean)
_stream_copy_tail(path, reference_seconds, tail)
clean_duration = max(0.0, duration - reference_seconds)
return str(clean), str(tail), reference, clean_duration
class DumasJoinVideoClipsNode:
"""Concatenate already-complete clips with FFmpeg stream copy."""
@@ -297,10 +369,12 @@ class DumasJoinVideoClipsNode:
NODE_CLASS_MAPPINGS = {
"DumasStandaloneVideo": DumasStandaloneVideoNode,
"DumasPrepareContinuation": DumasPrepareContinuationNode,
"DumasJoinVideoClips": DumasJoinVideoClipsNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasStandaloneVideo": "Dumas Standalone Video",
"DumasPrepareContinuation": "Dumas Prepare Continuation",
"DumasJoinVideoClips": "Dumas Join Video Clips (No Re-encode)",
}
+10 -2
View File
@@ -14,10 +14,10 @@ class DumasVideoNodeTests(unittest.TestCase):
cls.module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cls.module)
def test_registers_two_generic_video_nodes(self):
def test_registers_generic_video_nodes(self):
self.assertEqual(
set(self.module.NODE_CLASS_MAPPINGS),
{"DumasStandaloneVideo", "DumasJoinVideoClips"},
{"DumasStandaloneVideo", "DumasPrepareContinuation", "DumasJoinVideoClips"},
)
def test_standalone_node_exposes_full_and_complete_outputs(self):
@@ -34,6 +34,14 @@ class DumasVideoNodeTests(unittest.TestCase):
self.assertEqual(optional["clip_2_reference_frames"][1]["default"], 0)
self.assertEqual(optional["clip_6_reference_frames"][1]["max"], 4096)
def test_prepare_continuation_exposes_clean_and_tail_outputs(self):
node = self.module.DumasPrepareContinuationNode
self.assertEqual(
node.RETURN_NAMES,
("clean_clip", "next_reference", "reference_frames", "clean_duration"),
)
self.assertIn("raw_clip", node.INPUT_TYPES()["required"])
def test_video_fps_parses_frame_rate(self):
self.assertEqual(
self.module._video_fps({"streams": [{"codec_type": "video", "r_frame_rate": "24/1"}]}),