Nodes/CubicJ Comfy Nodes/Calculate Resolution (Aspect + Megapixels)
ComfyUI Node

Calculate Resolution (Aspect + Megapixels)

Stop doing megapixel math in your head — this node does it for LTX

By cubicj·Created 4 months ago·Updated 3 months ago· 0
Calculate Resolution (Aspect + Megapixels)
    • width
    • height
    aspect_width16
    aspect_height9
    megapixels0.37
    multiple_of32

    CalculateResolution is the laziest node in this pack, and that's a compliment. Give it an aspect ratio, a megapixel budget, and a divisibility requirement, and it hands you back a width and a height as clean INTs. No image input, no model, no inference - it's pure arithmetic with the LTX constraints baked in. It exists because text-to-video workflows have a gap: with image-to-video you can measure the input frame, but with T2V there's no frame to measure, and the resolution has to come from somewhere.

    That "somewhere" is usually where people get burned. LTX is picky about geometry in a way SDXL never was - width and height must be divisible by 32, and the latent you generate into has to match the conditioning. On LTX-2.3 the constraint is a hard failure: off-grid values fail rather than round. Punching 832x448 into an EmptyLTXVLatentVideo is fine, but computing that from "16:9 at 0.37 megapixels" by hand is the kind of thing you get wrong at 2am.

    How it works

    The math is the same as any aspect-preserving resize: target pixels are megapixels × 1,000,000, then it solves for the dimensions that hit that area at your aspect ratio and rounds each to the nearest multiple_of. So the defaults - 16:9 at 0.37 MP, aligned to 32 - resolve to roughly 832x448, which is LTX's classic low-res working size. Bump megapixels to 0.64 and you get the 1024x640 territory the tooltip points at. It's the same calculation ResizeImageToMegapixels does on an actual image, minus the image.

    The inputs that matter

    Only four, and you'll touch three of them:

    • aspect_width / aspect_height - the ratio, as integers. 16 and 9 for widescreen, 9 and 16 for vertical, 1 and 1 for square. Defaults to 16:9.
    • megapixels - the area budget, as a float. 0.37 is a good LTX starting point; you rarely need to go over 1.
    • multiple_of - the alignment. Keep 32 for LTX unless you know the model wants something else.

    Outputs are just width and height, both INTs. Wire them straight into EmptyLTXVLatentVideo's width/height (that's exactly what the author built it for), or into any node that takes dimensions as numbers.

    Installing it

    It ships in the cubicj-comfy-nodes pack alongside four other nodes. In ComfyUI Manager, search "CubicJ Comfy Nodes" and hit install. Or, the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cubicj/cubicj-comfy-nodes
    # restart ComfyUI
    

    There are no dependencies and no model downloads - the pack's pyproject lists an empty dependency array, which is rare and refreshing. Python 3.10+ is all it wants.

    Common issues

    The one real gotcha: the snap to multiple_of slightly changes the actual megapixels you get. 0.37 MP at 16:9 lands close to 832x448, but it won't be exact, because the dims round to the nearest 32. That's fine - LTX cares about the divisibility far more than the exact area. Also note the floor: dimensions can't drop below multiple_of itself, so a tiny target like 0.1 MP with multiple_of 64 won't go below 64px wide. If your numbers look off, check whether the snap moved you more than one step, and nudge megapixels rather than fighting it.

    One honest caveat: this is a small, fresh pack from an individual dev with essentially zero community footprint yet. The code is simple and readable, but don't expect forum threads full of troubleshooting lore - the source is the documentation.

    Categoryutils

    Inputs (4)

    NameTypeDefaultDescription
    aspect_widthINT161–100Aspect ratio width (e.g. 16 for 16:9)
    aspect_heightINT91–100Aspect ratio height (e.g. 9 for 16:9)
    megapixelsFLOAT0.370.1–4
    multiple_ofINT321–128

    Outputs (2)

    NameTypeDescription
    widthINT
    heightINT