Nodes/TrentNodes/Int Offset Clamp
ComfyUI Node

Int Offset Clamp

The three-input node that keeps your video loops from indexing out of bounds

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Int Offset Clamp
    • result
    value0
    offset-1
    min_value0

    Int Offset Clamp is the kind of node you don't think about until the moment it saves you. It computes max(value + offset, min_value) - that's the whole job - and it exists to answer one question that comes up constantly in iterative video workflows: what's the previous frame index, even when the current frame is frame 0?

    Here's the scenario. You're building an auto-queue loop that samples a video one chunk at a time and feeds the last generated frame back in as the first frame of the next pass. At some point you need current_frame - 1 as an index into a batch. On frame 0 that's -1, and -1 in most ComfyUI batch-slicing means "the last item," which is a completely different frame than you meant, or a crash. You could build the clamp out of three separate math and logic nodes, but this one does it in a single box with the exact default you want.

    What the inputs do

    Only three knobs, and they're all integers:

    • value - the input integer you're operating on.
    • offset - what gets added to it. Negative subtracts, which is the whole point. The default of -1 is "previous frame."
    • min_value - the floor. The result never goes below this. Default 0 means frame indices can never go negative.

    With the defaults, value=0 gives you 0 instead of -1. That's the node in its intended habitat: with offset=-1, min_value=0 it computes the previous frame index safely, so frame 0 just clamps to itself instead of wrapping around or erroring.

    Where it fits

    This is plumbing in the purest sense - the comfyui-node-plumbing school of thought where half of any graph is nodes that touch no pixels and exist only to fight repetition and illegibility. Int Offset Clamp is the repetition side: the same "previous frame, clamped" math wired into five downstream consumers becomes one node instead of five copies of the same arithmetic.

    The node is flagged IS_CHANGED to always recompute, so it plays nicely in loops and doesn't get cached into staleness. Wire its result output anywhere you'd wire an INT - a Get Image From Batch index, a cherry-pick frame selector, a filename counter.

    Install

    It ships in the TrentNodes pack, so it lands alongside ~69 other nodes. Easiest path:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TrentHunter82/TrentNodes.git
    cd TrentNodes
    pip install -r requirements.txt
    

    Or search "Trent Nodes" in ComfyUI Manager and hit Install, then restart ComfyUI. You'll find it under Trent/Utils.

    The one gotcha

    Because min_value defaults to 0, this node is only a floor, never a ceiling. If you also need an upper bound (say the last frame index), you'll want a separate clamp node or a min()-style node on the other end. And remember the inputs are forceInput-able, so you can convert the widget to a socket and drive value from a counter node rather than typing it - that's the whole point when you're looping.

    It's a boring node. That's the compliment.

    CategoryTrent/Utils

    Inputs (3)

    NameTypeDefaultDescription
    valueINT0-999999–999999Input integer
    offsetINT-1-999999–999999Amount to add to value. Negative subtracts.
    min_valueINT0-999999–999999Result will not go below this value

    Outputs (1)

    NameTypeDescription
    resultINTmax(value + offset, min_value)