Universal Calculator (TJ)
Resolution and frame math, both ways, zero paper
- width
- height
- frame_count
- seconds
- fps
- info
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_ratiomode - enter one side and it computes the other fromaspect_w : aspect_h(default 16:9), rounding todivisor(8/16/32/64) so it lands on sampler-friendly multiples. Enter both and it aligns the height to the width. - Resolution,
megapixelmode - enter one side (or both) and it sizes to themegapixelstarget. - Time/frames - enter
secondsorframe_countand it converts usingfps. 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 (inaspect_ratiomode).megapixels- the target size (inmegapixelmode).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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| res_mode | COMBO | aspect_ratio | 2 options: aspect_ratio, megapixel |
| width | INT | 00–8192 | — |
| height | INT | 00–8192 | — |
| aspect_w | INT | 161–10000 | — |
| aspect_h | INT | 91–10000 | — |
| megapixels | FLOAT | 1.000.01–64 | — |
| divisor | COMBO | 8 | 4 options: 8, 16, 32, 64 |
| fps | FLOAT | 24.000.1–1000 | — |
| seconds | FLOAT | 0.000–100000 | — |
| frame_count | INT | 00–1000000 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| frame_count | INT | — |
| seconds | FLOAT | — |
| fps | FLOAT | — |
| info | STRING | — |