Nodes/CS Hybrid 4K Image-to-Video/CS Replace Keyframes
ComfyUI Node

CS Replace Keyframes

Sew your refined keyframes back into the draft

By lvqunx·Created about a month ago·Updated about a month ago· 0
CS Replace Keyframes
  • draft_images
  • refined_images
  • IMAGE
interval8

You picked your keyframes, refined them at full resolution, and now you need them back in the video. CS Replace Keyframes is the merge step: it takes your draft frame batch and a batch of refined keyframes and splices them in at their original positions. Without this node you'd have a nice 4K clip with a handful of polished frames and nowhere to put them.

It's one of seven nodes in CS Hybrid 4K Image-to-Video (lvqunx/comfyui-cs-hybrid), a new pack built on running the video model at 480P and re-synthesizing only scheduled regions at 4K. Replace Keyframes is the closing move of the loop: Batch Stride pulls keyframes out → your img2img refiner (SDXL/Flux) polishes them → this node drops them back into the slots they came from.

How it works

Straightforward and safe: it copies the draft batch, then replaces frames at positions 0, interval, 2×interval, … with the refined frames in order - the first refined frame goes to slot 0, the second to slot interval, and so on. Nothing else in the draft is touched, so non-keyframe frames keep whatever the flow-based rebuild produced.

There's one bit of genuinely thoughtful handling in the source: if a refined frame's dimensions don't match the draft - which happens when an img2img pass changes size, like VAEEncodeTiled cropping to a multiple of 32 - the node resamples the refined frame to the draft's size before splicing. It won't refuse to run; it'll just fit the piece into the hole.

The inputs that matter

  • draft_images - your full draft batch (the rebuild output).
  • refined_images - the refined keyframes, in the same order your keyframe picker produced them.
  • interval - default 8, the same cadence you used everywhere else in the pack.

One output, IMAGE: the merged batch, ready for preview or save.

The two things that bite

First, order is contract. The node replaces positions in sequence - it doesn't match refined frames to keyframes by any attribute. If your refiner reordered the batch (it shouldn't, but loops have opinions), you'll get polished frames in the wrong slots. Keep the keyframe batch order untouched between extraction and replacement.

Second, interval agreement. interval here has to equal the stride you used in CS Batch Stride - otherwise your refined frames were picked at one cadence and get dropped into another. In this pack, number-consistency between Batch Stride, Replace Keyframes, GOP Recompose's interval, and the scheduler's keyframe_every is the difference between a working loop and a confusing mess.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/lvqunx/comfyui-cs-hybrid
# restart ComfyUI

Or ComfyUI Manager → search CS Hybrid 4K Image-to-Video. No extra pip dependencies; everything it needs ships with ComfyUI.

Common issues

If your final video has a keyframe that didn't get refined, it's usually one of two things: the refiner produced fewer frames than the draft needed (the node uses the smaller of the two counts, so short refined batches just silently leave late keyframes alone), or the interval mismatch above. And don't panic if the node quietly resizes a refined frame - that's the designed behavior for img2img size drift, not an error.

CategoryCSHybrid

Inputs (3)

NameTypeDefaultDescription
draft_imagesIMAGE
refined_imagesIMAGE
intervalINT81–256

Outputs (1)

NameTypeDescription
IMAGEIMAGE