AP Select Flow By Index
Grab the one flow you need — slicing a batched flow by frame index
- flow_data
- flow_data
- flow_visualization
A flow_data object from APGetRAFTOpticalFlow can hold a whole batch of flows - one per frame pair. Most of the time the downstream nodes handle that transparently with their batch_mode and current_frame_index plumbing. But sometimes you want to be explicit: give me exactly the flow for frame N, so you can route it somewhere specific or debug one entry. That's the entire job of AP Select Flow By Index.
Think of it as the flow equivalent of an index node: it takes the batched flow, takes an integer frame_index, and returns a single-entry flow_data plus a visualization of that one flow. It's the manual, no-magic version of what the apply nodes do automatically when you wire current_frame_index - the README lists it as an explicit alternative: "use AP Select Flow By Index for explicit flow slicing."
The mechanism
Under the hood it calls the same _select_flow_data_by_index helper the apply nodes use, so the indexing semantics are identical to the rest of the pack - no surprises, no off-by-one between this node and the automatic path. It slices both flow directions to the requested entry, keeps the height/width metadata consistent, and then renders a flow_visualization from the selected forward field so you can confirm you grabbed the right one.
Inputs and outputs
Two inputs:
flow_data- the batchedAP_FLOWfromAPGetRAFTOpticalFlow.frame_index- which flow entry to pull (0-based). Wire this fromAPIndexeror any integer source; an out-of-range index clamps rather than exploding, which is friendlier than it strictly had to be.
Two outputs: flow_data (the single-entry AP_FLOW, feedable into any apply/occlusion node) and flow_visualization (the color IMAGE of that one flow).
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. Dependency is torchvision>=0.15.
When you'd actually use it
Honest answer: you don't need it in most graphs, because the apply nodes' index-aware batch modes already do this internally. You do need it in two situations. First, when you want to feed a specific flow entry into a node that doesn't have index plumbing (a custom node, a manual warp) - slice it here, then wire the single-entry flow anywhere. Second, when debugging: extract flow for one frame, look at the visualization, confirm motion direction and magnitude before you trust the whole pipeline.
It also composes with APIndexer nicely: indexer produces current_frame_index as the loop runs, this node slices the matching flow, and downstream you have exactly one flow to reason about. Slightly more wiring than the automatic mode, but zero ambiguity about which flow is in play.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| flow_data | AP_FLOW | — | |
| frame_index | INT | 00–2147483647 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| flow_data | AP_FLOW | — |
| flow_visualization | IMAGE | — |