Nodes/AnimateDiff/Get Image Size + Batch Size
ComfyUI Node

Get Image Size + Batch Size

Read width, height and frame count off a loaded video

By SipherAGI·Created 3 years ago·Updated 2 years ago· 754
Get Image Size + Batch Size
  • image
  • width
  • height
  • batch_size

This one's not glamorous, it's just useful. Feed it an image (or, more usefully, a batch of images - a loaded GIF or video) and it hands back three numbers: width, height, and batch_size. That's it. No AI, no sampling, just reading the tensor shape and reporting it as integers you can wire somewhere else.

Where it earns its keep is at the front of an AnimateDiff graph. Say you load a reference clip with this pack's LoadVideo node to drive a vid2vid or ControlNet workflow - instead of eyeballing the resolution and frame count and typing them into EmptyLatentImage by hand, you plug the loaded frames straight into ImageSizeAndBatchSize and wire its outputs into EmptyLatentImage's width, height, and batch size. Now your generated latent always matches whatever you loaded, automatically, even if you swap the source clip later. It's the kind of node you forget exists until you've hand-typed "512, 512, 16" for the fifth time and get one wrong.

How it works

There's no real "mechanism" to explain here - it inspects the image tensor's shape and splits it into three outputs. batch_size in particular is worth understanding in context: ComfyUI treats a loaded video or GIF as a batch of images stacked along the first dimension, so "batch size" here effectively means "frame count." That's why this node shows up in animation workflows specifically - it's the cheap way to ask "how many frames did I just load, and what size are they?"

The inputs and outputs that matter

There's exactly one input: image (IMAGE) - whatever batch you want measured. Three outputs come back:

  • width (INT)
  • height (INT)
  • batch_size (INT)

Wire any or all of these into EmptyLatentImage, into a math node if you need to scale them, or just into a Reroute/Preview if you're debugging a graph and want to confirm what actually got loaded.

How to install it

It ships as part of the comfyui-animatediff pack, so there's no separate install - get the pack and every node in it, including this one, comes along.

Through ComfyUI Manager: search for "comfyui-animatediff" and install.

Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ArtVentureX/comfyui-animatediff

Restart ComfyUI afterward. This particular node needs no motion modules, no extra models, nothing beyond the base install - it's a plain utility, so if it's not showing up after a restart the problem is the install itself, not a missing model file.

Common issues & troubleshooting

batch_size comes back as 1 when I expected more. That almost always means the upstream node only loaded a single image rather than a sequence - check that LoadVideo (or whatever fed this node) is actually reading multiple frames and not just grabbing frame zero. A batch size of 1 here is diagnostic information, not a bug in this node.

I matched EmptyLatentImage to a weird resolution and my motion looks worse. This pack's own AnimateDiff model was trained on 512x512 images, and results degrade outside that ballpark - more so than a typical image model, because the motion module is fighting an unfamiliar resolution on top of everything else. If you're piping this node's width/height straight into your latent and your source video isn't roughly 512x512, consider resizing the source first rather than forcing AnimateDiff to work at a resolution it wasn't trained for.

Nothing downstream changes when I swap the input video. Double check the wire actually goes from this node's outputs into the fields you think it does - it's easy to leave EmptyLatentImage's width/height on manual values that silently ignore an unconnected ImageSizeAndBatchSize output sitting unused in the graph.

CategoryAnimate Diff/Utils

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (3)

NameTypeDescription
widthINT
heightINT
batch_sizeINT