Nodes/ComfyUI-Buff-Nodes/Batch Raft Optical Flow Node (Buff)
ComfyUI Node

Batch Raft Optical Flow Node (Buff)

Batch optical flow for a whole clip

By BuffMcBigHuge·Created 2 years ago·Updated 20 days ago· 2
Batch Raft Optical Flow Node (Buff)
  • images
  • optical_flow
batch_chunk_size4

Chaining a two-image optical flow node across a 60-frame clip is exactly the kind of thing you do once, get bored of, and never want to repeat. That's the gap the batch version in this pack exists for. Feed it one image batch - the whole clip as a single tensor - and it computes RAFT optical flow between every consecutive pair, returning n−1 motion visualizations in a single pass.

If you're new to optical flow: it's a per-pixel motion estimate between two frames, and it's the backbone of a lot of temporal-consistency and motion-analysis work in ComfyUI. The classic use for this family of nodes is feeding flow into TemporalNet2-style ControlNet pipelines for video streaming workflows, where the model needs to know how the scene moved between the previous frame and the current one. This node is the "whole clip at once" variant of that idea.

How it works

Under the hood it's torchvision's raft_large model with the default large weights, the same engine as the single-pair node in this pack but without the per-frame loop. The batch gets permuted to [B, C, H, W], padded so both dimensions are multiples of 8 (RAFT's native constraint), then split into two tensors: frames 0 through n−2 and frames 1 through n−1. Every pair goes through the model in one shot, and the result is turned into the familiar color-coded flow visualization via torchvision's flow_to_image, normalized to [0,1] so it behaves like any other ComfyUI image. Padding is cropped off before the output.

The one knob that matters is batch_chunk_size (default 4). Instead of pushing all pairs through at once - which can OOM on long clips - the node processes pairs in chunks and frees GPU memory between them. Lower it if you're running out of VRAM, raise it if you've got headroom and want speed. The model runs on CUDA when available and falls back to CPU otherwise.

Inputs and output

  • images - a IMAGE batch, frames first. Must contain at least 2 images, or the node raises an error.
  • batch_chunk_size - pairs per GPU batch, 1–64. The VRAM-versus-speed dial.

The only output is optical_flow - a batch of flow visualizations, one per consecutive pair, same spatial size as the input. Wire it into whatever wants flow: a temporal ControlNet, a flow-based interpolator, or just a preview node so you can see the motion.

Install and gotchas

Same story as every node in this pack - install once via ComfyUI Manager (search "ComfyUI-Buff-Nodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/BuffMcBigHuge/ComfyUI-Buff-Nodes

Restart ComfyUI. There's no requirements.txt; the pack only needs torch/torchvision/PIL, which you already have. The one thing to know: the RAFT weights download from Hugging Face on the first run, so the very first execution needs network access and takes a minute. It's cached after that. You'll also see debug prints on the console saying how many pairs ran and on what device - harmless, and honestly useful.

Where people trip up: feeding a 2-frame "clip" and wondering why there's only one flow image, and running huge batches with the default chunk size on a small GPU. Both have obvious answers. It's a small node with a narrow job, but for clip-level flow it beats wiring up per-frame nodes hands down.

CategoryImage

Inputs (2)

NameTypeDefaultDescription
imagesIMAGEBatch of images [B, H, W, C]. Optical flow is computed between each consecutive pair.
batch_chunk_sizeoptINT41–64Number of pairs to process per GPU batch. Lower values use less VRAM. Increase for speed if you have enough VRAM.

Outputs (1)

NameTypeDescription
optical_flowIMAGE