Nodes/ComfyUI-TJ_NODE/Universal Calculator (TJ)
ComfyUI Node

Universal Calculator (TJ)

Resolution and frame math, both ways, zero paper

By designloves2·Created 4 months ago·Updated 4 days ago· 13
Universal Calculator (TJ)
    • width
    • height
    • frame_count
    • seconds
    • fps
    • info
    res_modeaspect_ratio
    width0
    height0
    aspect_w16
    aspect_h9
    megapixels1.00
    divisor8
    fps24.00
    seconds0.00
    frame_count0

    Stop doing aspect-ratio arithmetic in your head

    Universal Calculator (TJ) is a single-node calculator that handles the two math chores every ComfyUI user does constantly: resolution (aspect ratio ↔ dimensions ↔ megapixels) and time/frames (seconds ↔ frame count at a given fps). The killer feature is the "0 = blank (auto)" convention: you only fill in the field you know, and the node computes the rest.

    How many times have you wanted 1080×? at 2:3, or needed to know how many frames a 6-second clip is at 24fps, and reached for a calculator or a separate tab? That's this node, as a live part of the graph - and because it outputs real width/height/frame_count INTs and FLOATs, you can wire the results straight into an empty latent or a video node and never type the number anywhere else.

    How it works

    The live math runs in the node's frontend, and the Python backend mirrors the same logic so it also works from the API/direct execution. 0 means "solve this for me":

    • Resolution, aspect_ratio mode - enter one side and it computes the other from aspect_w : aspect_h (default 16:9), rounding to divisor (8/16/32/64) so it lands on sampler-friendly multiples. Enter both and it aligns the height to the width.
    • Resolution, megapixel mode - enter one side (or both) and it sizes to the megapixels target.
    • Time/frames - enter seconds or frame_count and it converts using fps. Leave both blank and nothing happens; fill either and the other fills in.

    It also reports the reduced GCD ratio and snaps resolutions to your divisor, which is exactly the "why is this latent the wrong size" insurance the ecosystem keeps asking for - latent dims that aren't multiples of the sampler's needs are a classic silent-quality killer.

    The inputs that matter

    • width / height - fill one, blank the other, get both.
    • aspect_w / aspect_h - the ratio (in aspect_ratio mode).
    • megapixels - the target size (in megapixel mode).
    • fps / seconds / frame_count - the time trio.
    • divisor - snap multiple (8 is the safe default).

    Outputs: width, height (INT), frame_count (INT), seconds, fps (FLOAT), and info (STRING) with a summary.

    Install it

    Part of TJ_NODE, no extra dependencies:

    cd ComfyUI/custom_nodes
    git clone https://github.com/designloves2/ComfyUI-TJ_NODE.git
    

    Or ComfyUI Manager → search TJ_NODE, restart. Category: ✨ TJ_Node/Utility.

    Where people get burned

    The convention is the trap: 0 is meaningful ("auto"), so a field you genuinely want to be zero is impossible to express - you have to use 1 or something tiny instead, or the node will compute over it. That catches almost everyone once. Second, in aspect_ratio mode it always treats the width as the reference when both are filled, so if you typed both, don't expect the height you typed to survive - it gets re-aligned to the width. And note the outputs are pure numbers, not latents: wire them into an Empty Latent (or this pack's Z-Image Turbo, which takes explicit width/height) to actually use the result. For a one-shot video job, this is the "what's 157 frames at 24fps" answer; for iterative resolution testing it's a workflow node that remembers your ratios for you.

    Category ✨ TJ_Node/Utility

    Inputs (10)

    NameTypeDefaultDescription
    res_modeCOMBOaspect_ratio2 options: aspect_ratio, megapixel
    widthINT00–8192
    heightINT00–8192
    aspect_wINT161–10000
    aspect_hINT91–10000
    megapixelsFLOAT1.000.01–64
    divisorCOMBO84 options: 8, 16, 32, 64
    fpsFLOAT24.000.1–1000
    secondsFLOAT0.000–100000
    frame_countINT00–1000000

    Outputs (6)

    NameTypeDescription
    widthINT
    heightINT
    frame_countINT
    secondsFLOAT
    fpsFLOAT
    infoSTRING