Nodes/Dream Video Batches/πŸ–© Calculation
ComfyUI Node

πŸ–© Calculation

Named variables, real math functions, and no arbitrary code

By alt-key-projectΒ·Created 3 years agoΒ·Updated 7 months agoΒ· 95
πŸ–© Calculation
    • FLOAT
    • INT
    β—„expressiona + b + c - (r * s * t)β–Ί
    β—„a_int0β–Ί
    β—„b_int0β–Ί
    β—„c_int0β–Ί
    β—„r_float0.00β–Ί
    β—„s_float0.00β–Ί
    β—„t_float0.00β–Ί

    Calculation [DVB] is the pack's math node, and it's better than the throwaway "expression evaluator" you might expect. It takes a single expression string plus up to six named inputs - a_int, b_int, c_int, r_float, s_float, t_float - and evaluates the expression with those variables in scope. Both a FLOAT and an INT come out (the int is the float rounded). The default expression is a + b + c - (r * s * t), which tells you the intended shape: integer counts on one side, float parameters on the other.

    Why the security bit matters

    This is the part people should actually care about. The node doesn't run your expression with Python's eval() - it uses the evalidate library, which parses the expression and evaluates it against a strict allow-list of AST nodes and a curated set of functions. That's a meaningful difference in a world where custom nodes execute arbitrary code on import and malicious packs have shipped through normal channels. You can't smuggle __import__('os').system(...) into an expression here; the sandbox just refuses it. evalidate is in the pack's requirements.txt for exactly this reason.

    And the function list is generous. Beyond the operators, you get the usual Python math module: sin, cos, tan, sqrt, pow, floor, ceil, log, log2, log10, exp, pi, abs, min, max, round, factorial, dist, atan2, and more. For a video-batch pack that's plenty - you're mostly computing frame counts, durations, and ratios.

    How you'd use it in a workflow

    Say you know your clip runs 12 seconds at 24 fps and you want the fade to be a quarter of the length: plug 12*24 into the expression, wire your frame count as a_int, and the output feeds fade_seconds or a frame-count input downstream. The pack's own example workflow chains this - a Calculation between inputs feeding durations into transitions and repeats. It's the node that lets you build a workflow that stays correct when you change one number at the top instead of hand-editing five constants.

    The only inputs you'll touch most of the time are the expression and whichever of the six variables your expression actually references. The unused ones default to zero. Note that all six are optional and each has a default of 0 - so a bare expression that references only r_float works fine with the rest left alone.

    The traps

    Two, both minor. First, the expression result must be a number - if it evaluates to anything else, both outputs silently return 0.0 and 0, which can mask a bug. If your expression throws a syntax error or calls a disallowed function, you get a node error carrying the message, which is the better failure mode. Second, this pack pins numpy<2.0 in its requirements - if another pack in your install wants numpy 2.x, pip may downgrade or complain. That's a dependency-hell classic in the ComfyUI ecosystem, and it's the one thing that can actually make this pack fight with your other nodes.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/alt-key-project/comfyui-dream-video-batches.git
    cd comfyui-dream-video-batches
    pip install -r requirements.txt
    

    Restart ComfyUI, or search "Dream Video Batches" in the Manager. No models, no downloads - pure arithmetic.

    Category🎭 DVB/πŸ›  utils

    Inputs (7)

    NameTypeDefaultDescription
    expressionSTRINGa + b + c - (r * s * t)β€”
    a_intoptINT0β€”
    b_intoptINT0β€”
    c_intoptINT0β€”
    r_floatoptFLOAT0.00β€”
    s_floatoptFLOAT0.00β€”
    t_floatoptFLOAT0.00β€”

    Outputs (2)

    NameTypeDescription
    FLOATFLOATβ€”
    INTINTβ€”