Nodes/ComfyUI/Replace Video Latent Frames
ComfyUI Node Runs on cloud

Replace Video Latent Frames

Splice new frames into a video latent like a timeline edit

By Comfy-Org·Created 4 years ago·Updated about 16 hours ago· 130,663
Replace Video Latent Frames
  • destination
  • source
  • LATENT
index0

Editing video inside latent space is where the interesting workflows live, and this node is the latent-space version of "select this range of frames and swap in different ones." ReplaceVideoLatentFrames takes a source latent's frames and writes them over a region of a destination latent. If you've ever wanted to swap a bad middle section of a generation without regenerating the whole clip, this is the tool.

How it works

Three inputs: destination (the latent being edited), source (the latent whose frames get inserted), and index (where the insertion starts in the destination's timeline). The source frames overwrite the destination's frames at [index : index + source_frames]. Nothing is blended or interpolated - it's a straight splice.

Two behaviors are worth knowing before you use it:

  • index can be negative. Negative values count from the end of the destination - -5 starts the splice five frames from the end. Handy for replacing the tail of a clip without counting forward.
  • source is optional. Leave it disconnected and the destination comes back unchanged. That's deliberate: you can build graphs where the replacement branch is conditional, and this node degrades gracefully instead of erroring.

The boundary rules that will bite you

The node is strict about out-of-bounds, and it's silent-ish about it. If index is beyond the destination's frame count, or if the source frames don't fit within the destination at that index, it logs a warning and returns the destination unmodified - no error, no partial write. So the failure mode is "nothing happened and you didn't notice," not "red error on the canvas." When a splice appears to do nothing, check your index math against the latent frame counts of both clips.

Where it fits

The classic use is frame surgery on video generations: generate a clip, run a targeted pass on just a segment (say, fixing a face or a motion glitch in the middle), then splice the repaired frames back over the original latent before the final VAE decode - no full re-generation, no visible cut if the regions line up. It pairs naturally with LatentCut (extract a region), LatentConcat (join), and the batch nodes for fancier timeline assembly.

Gotchas

Both latents must be the same spatial size and channel count - you're copying tensors into fixed slots, and a shape mismatch is a hard error or garbage, not a resize. And remember this is a latent-space operation: the spliced frames should come from the same model family (same latent format), because mixing latent spaces produces decode artifacts that look like corrupted footage. Frame counts are latent-time steps, same as every video latent node - count in the latent's time axis, not in output pixel frames.

Categorymodel/latent/batch

Inputs (3)

NameTypeDefaultDescription
destinationLATENTThe destination latent where frames will be replaced.
indexINT0-16384–16384The starting latent frame index in the destination latent where the source latent frames will be placed. Negative values count from the end.
sourceoptLATENTThe source latent providing frames to insert into the destination latent. If not provided, the destination latent is returned unchanged.

Outputs (1)

NameTypeDescription
LATENTLATENT