Nodes/Richard's Video Kits/RVK Save Segment Video
ComfyUI Node

RVK Save Segment Video

An MP4 Writer That Refuses to Overwrite Anything

By Richard-Wang-fs·Created 26 days ago·Updated 16 days ago· 0
RVK Save Segment Video
  • images
  • receipt
  • path
◄fps24.000►
◄output_directoryrvk/run►
◄segment_index0►
◄crf23►
◄presetmedium►

One job, done carefully

RVK Save Segment Video takes an IMAGE batch and writes one silent H.264 MP4 - then decodes the result back to check it before calling it finished. You can use it with no Wan model in the graph at all; it's a general video save node that happens to be paranoid.

Which is the point. Every video node you already own will happily overwrite your last take, and when a five-hour segment run dies at segment 6 you do not want to discover that the file on disk is half a file. This one writes to segment_0006.partial.mp4, verifies the encode, then publishes to segment_0006.mp4 in a way that cannot replace an existing file. If the write dies, you get a .partial.mp4 and a clean error - your previous good segments are untouched.

How it works

The encode goes through PyAV, which already ships in ComfyUI's environment - the pack adds no pip dependencies of its own. Frames go in as H.264 with yuv420p, at the exact rational frame rate you gave it, and the node validates the batch before touching the disk rather than writing garbage.

It rejects batches that aren't dense floating tensors with a positive [T,H,W,3] shape, and it refuses odd frame dimensions outright - yuv420p needs even width and height. Then it inspects what it wrote: frame count, dimensions, codec, stream count. Only after that comes the no-replace publish. What comes out the other end is a receipt, and the receipt is not decoration - it's the evidence struct the rest of the loop trusts, carrying the published path, segment index, frame count, width, height, fps as a fraction, CRF and preset. RVK Wan Animate 2 Advance will not move the run forward without a receipt that matches its plan frame-for-frame.

Like every node in this pack, it's marked non-idempotent - internally it overrides the fingerprint to NaN so ComfyUI can never decide to serve a cached result and skip the write. Saving a file is a side effect; caching would be wrong.

Inputs and outputs

  • images - the batch. In the loop workflow this is the delivery_images output from RVK Wan Animate 2 Collect, which is already the trimmed, de-overlapped, exactly-the-frames-you-asked-for batch.
  • fps - default 24. In the loop workflow it's wired from Loop Entry, which reads it off your driving video. That matters more than it looks: Finalize stream-copies these files, so if the fps here disagrees with the source timeline, your finished video will be out of sync with the audio and nothing downstream can fix it.
  • output_directory - default rvk/run, relative to ComfyUI's output folder. Absolute paths and .. are rejected.
  • segment_index - default 0, which produces segment_0000.mp4. Zero-padded to four digits, so indexes sort correctly.
  • crf - default 23, range 0–51. Lower is better and bigger. 23 is fine; drop to 18 if this clip is going into another encode later.
  • preset - an x264 preset, ultrafast through veryslow, default medium.

Two outputs: receipt (wire it to RVK Wan Animate 2 Advance) and path (a STRING, handy for a text or note node when you're debugging a run). That's it - no VIDEO type, no frames coming back out.

The one encode in the whole chain

Worth internalising: from your sampler to final.mp4, the video is encoded exactly once, and it happens here. Finalize concatenates with a stream copy, so CRF 23 at medium is your delivered quality. If a run took six hours of GPU time and looks slightly soft, this widget is where you find out why. Bumping to slow at CRF 18 costs you seconds per segment on 81 frames and you'll never notice on 900.

Install

Manager → Richard's Video Kits / richards-video-kits, version 1.0.0, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Richard-Wang-fs/ComfyUI-RichardsVideoKits

One copy only, then launch with --cache-classic as the author tested it (Windows, Python 3.12, ComfyUI 0.36.0). No FFmpeg binary is needed for this node - the python-side encoder does the work - but the pack's Finalize node needs one with AAC on PATH, so install it anyway if you plan to finish a video.

Where people get burned

  • "Segment already exists." Queue the same index into the same directory twice and the second run fails instead of overwriting. That's the feature working. Start a new output directory; Loop Entry wants an empty one anyway.
  • Leftover .partial.mp4 files. Something died mid-write. Read the error before deleting, and make sure nothing is still writing that file - a live writer plus a manual rm is how you get a corrupt segment that looks complete.
  • Wrong fps, silent disaster. Saving a 30fps drive video's frames at the default 24 gives you perfectly valid files that run 25% slow once Finalize marries them to the original audio. Wire the fps, or set it to match.
  • Wiring the receipt into something that isn't Advance. It's an opaque custom type; nothing else in ComfyUI consumes it. Leave it dangling if you're only saving.

The pack is PolyForm Noncommercial 1.0.0 - source-available, not OSI open source. Fine for personal and research work, but commercial use needs permission from Richard-Wang-fs directly.

CategoryRVK/Video

Inputs (6)

NameTypeDefaultDescription
imagesIMAGE—
fpsFLOAT24.0000.001–1000—
output_directorySTRINGrvk/runRelative to the ComfyUI output directory.
segment_indexINT00–999999—
crfINT230–51—
presetCOMBOmedium9 options: ultrafast, superfast, veryfast, faster, fast, medium, +3

Outputs (2)

NameTypeDescription
receiptRVK_VIDEO_RECEIPT—
pathSTRING—