OpenCV writeOpticalFlow_0
Export your optical flow to .flo so real video tools can use it
- flow
- bool
Optical flow - the per-pixel motion field between two frames - is one of those things ComfyUI video people keep needing and keep having to smuggle in from outside. writeOpticalFlow_0 is the node that gets it out: it takes a flow field as an NPARRAY and writes it to disk in the Middlebury .flo format, the de-facto interchange format that frame-interpolation and motion tools actually read. It's the handoff node - the one that connects a ComfyUI pipeline to everything else that speaks .flo.
How it works
A flow field is a 2-channel float32 map where each pixel holds (dx, dy) - how far that pixel moved between frame A and frame B. In this pack you produce one with calcOpticalFlowFarneback_0 (give it two NPARRAY frames and the classic Farneback parameters: pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags). writeOpticalFlow_0 then serializes that to the .flo format: a PIEH magic header, the width and height, and the raw float32 data. Because .flo is just a fixed binary layout, every serious flow consumer reads it - RIFE and other frame-interpolation engines, FlowFrames-style utilities, academic toolkits, the whole ecosystem.
The flip side lives in the pack too: readOpticalFlow_0 takes a .flo path and hands you the flow back as an NPARRAY, so the round trip is fully covered.
Inputs and outputs
path- aSTRINGfilesystem path, e.g./home/you/flow.flo. Note this is a raw string widget, not a ComfyUI folder picker - type the absolute path, and the file gets overwritten without warning if it exists.flow- theNPARRAYflow field (float32, 2 channels) fromcalcOpticalFlowFarneback_0or another source.- Output:
bool-Truewhen the write succeeded. That's your "did it work" signal; it's not meant to be wired anywhere.
Installing
Pack-standard:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
or ComfyUI Manager, search "opencv-comfyui", install, restart. Dependencies: opencv-contrib-python, numpy, torch.
Where this shines
Frame interpolation is the standout use. Video workflows that interpolate between keyframes - whether for smoother animation, slow-mo, or temporal upscaling - often want a proper optical flow field to steer the motion, and the tools that do the heavy lifting expect .flo. Export Farneback flow from a generated video pair, feed it to an external interpolator, bring the result back. It's also handy as a debugging/storage format: .flo is compact, and readOpticalFlow_0 means you can stash a flow on disk and reload it without recomputing. Just remember the flow has to be float32 and 2-channel - if you feed it an 8-bit or single-channel array, the write is silently meaningless or errors. Match the dtype and this node just works.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| path | STRING | — | |
| flow | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| bool | BOOLEAN | — |