ComfyUI Node

AP Indexer

A frame counter that remembers — persistent indexing for loop pipelines

By adampolczynski·Created 6 months ago·Updated 6 months ago· 1
AP Indexer
  • images
  • images
  • current_frame_index

The optical flow nodes in this pack are "index-aware": give them a current_frame_index and they'll align the right flow entry to the right frame automatically. Which raises the question - where does current_frame_index come from in the first place? That's what AP Indexer is for. It's a persistent frame counter that counts up across iterations and hands the count to anything that needs it.

It's a small node with an outsized role. In a loop pipeline - say, processing frames one at a time with APLoopOpen/APLoopClose - something has to know which iteration you're on so the flow and skip logic line up. The loop nodes track their own internal iteration_index, but APIndexer is the standalone, reusable counter you can wire into any node that takes a frame index, including flow nodes outside the loop structure. The README's loop pipeline section is literally: "AP Indexer to produce current_frame_index, feed current_frame_index into flow nodes that support it."

The mechanism

Give it an IMAGE batch and it returns the same images unchanged, plus an INT. The interesting part is the INT: it's a counter that increments by your batch size on every execution and remembers its state across iterations of the same run. Two details make it behave sanely:

  • It's keyed per-node and per-run, so the counter resets automatically when a new prompt execution starts - you don't get stale counts leaking from a previous run.
  • It increments by max(1, batch_size), so a batch of 4 images advances the index by 4, keeping the counter aligned with how many frames you've actually consumed.

That "persistent across iterations, reset per run" behavior is exactly what loop pipelines need and what a plain PrimitiveInt can't give you.

Inputs and outputs

One required input, images - any IMAGE batch; it's just the thing being counted and it passes through untouched.

Two outputs: images (the identical batch, for convenient passthrough wiring) and current_frame_index (INT) - the counter, which you feed into the optional current_frame_index inputs on APApplyRAFTOpticalFlow, APApplyRAFTOpticalFlowMasked, APFlowOcclusionMask, or into APSelectFlowByIndex's frame_index.

Installing it

Same 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. Dependency is torchvision>=0.15 (though, like a lot of plumbing nodes, this one doesn't actually invoke RAFT - it's counting, not computing).

The honest scope

This is a counter, not a scheduler. It goes up by your batch size each execution and resets per run; it won't step by custom amounts or skip frames for you. If you need those, the loop nodes' own iteration_index output is the richer source (it knows the total frame count and history state), and flow_skip/frames_skip on the apply nodes handle offset starts. Reach for APIndexer when you want a dead-simple, node-agnostic frame number that any index-aware node can consume - especially when the flow apply nodes are doing auto batch mode, where "is current_frame_index connected?" decides whether alignment is index-based at all.

CategoryAP_OpticalFlow

Inputs (1)

NameTypeDefaultDescription
imagesIMAGE

Outputs (2)

NameTypeDescription
imagesIMAGE
current_frame_indexINT