AP Save Optical Flow
Compute the flow once, reuse it forever — the cache node that skips RAFT on every rerun
- flow_data
- flow_data
- saved_path
RAFT is the slow part of any optical flow workflow. On a big frame it's seconds per pair, and if you're iterating on a loop or tuning the rest of your graph, you'll rerun it dozens of times for no reason - the motion between your frames doesn't change just because you tweaked a sampler setting. AP Save Optical Flow is the fix: it writes your flow_data to a .pt file on disk, so the next run can skip RAFT entirely and load the exact same flow back with APLoadOpticalFlow.
That's the whole point of this node, and it's genuinely one of the most practical ones in the pack. Flow computation is deterministic - same frames, same flow - so caching it is pure free time on every subsequent run. The README's flow-cache workflow is literally: compute flow, save it, "reuse it later to skip recomputing flow."
The mechanism
Give it flow_data (an AP_FLOW object from APGetRAFTOpticalFlow) and it serializes the flow tensors - both directions, plus height/width and the model variant - into a .pt file. The file lands in your ComfyUI output directory under the path you give filename_prefix (default AP_OpticalFlow/flow), with a timestamped filename unless overwrite=true forces the exact name. The payload is a small dict tagged with ap_optical_flow: 1 so the loader can verify it's the right kind of file.
It's also the on-demand companion to the flow_offload=disk_storage option on the compute node: that option auto-saves flow to disk as a memory-saving measure, while this node is your explicit, deliberate save for reuse across runs.
The inputs that matter
Only three, and they're all straightforward:
flow_data- the flow to cache. Straight fromAPGetRAFTOpticalFlow.filename_prefix- output subpath and base name, e.g.AP_OpticalFlow/flow. The.ptand a timestamp get appended.overwrite-false(default) appends a counter/timestamp so you never clobber an earlier save;truewrites the exact file every time, which is what you want when a single canonical file feeds your loader.
Outputs
flow_data passes the flow through unchanged (so you can save and continue using it in the same graph without rewiring). saved_path is a STRING with the actual path written - useful if you want to feed it into a text node or note where the file went.
Installing it
Pack-wide install: ComfyUI Manager (search "AP_OpticalFlow"), or
cd ComfyUI/custom_nodes
git clone https://github.com/adampolczynski/ComfyUI_AP_OpticalFlow
python -m pip install -r custom_nodes/ComfyUI_AP_OpticalFlow/requirements.txt
Restart ComfyUI. Only dependency is torchvision>=0.15.
How people actually use it
Two patterns. Pattern one: you're iterating on a workflow - compute flow once, save it, and while you tune everything downstream, run APLoadOpticalFlow into the same apply/composite chain. Pattern two: you've got a long or expensive sequence and you're batching the flow computation separately from the rest, so the heavy RAFT passes happen once and the results are just data on disk for every later run.
One honest caveat: flow files are not small. A dense flow field for a 1024×1024 frame is two float tensors per direction, and a sequence is one file per pair or a big batched tensor. If you're caching hundreds of frames, keep an eye on disk - and remember the file encodes the resolution the flow was computed at, so if you change your frame size later, the cached flow won't line up and you'll need to recompute (the apply nodes do resize the flow, but resized flow from a different source resolution isn't the same as flow computed at that resolution).
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| flow_data | AP_FLOW | — | |
| filename_prefix | STRING | AP_OpticalFlow/flow | — |
| overwrite | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| flow_data | AP_FLOW | — |
| saved_path | STRING | — |