Nodes/comfyui-latent-astronaut-suite/Video Length from Batch
ComfyUI Node

Video Length from Batch

How many seconds of video are sitting in that image batch?

By latentastronaut·Created 8 months ago·Updated 7 months ago· 2
Video Length from Batch
  • images
  • seconds
  • frame_count
frame_rate24.0

Video Length from Batch answers a dumb question that somehow always trips people up: "I loaded a video into ComfyUI as a stack of frames - how long is it?" Feed it the image batch and the frame rate, and it tells you the duration in seconds plus the exact frame count. One line of math, zero drama - but when you're building a video pipeline that needs to compute an output length or split clips, having that number as a real output you can wire into other nodes is worth more than you'd think.

How it works

The source is almost embarrassingly simple. The frame_count output is just images.shape[0] - the batch dimension of the tensor, i.e. how many frames are in the stack. seconds is frame_count / frame_rate. That's it. The cleverness, if you can call it that, is that it turns something ComfyUI does internally into a first-class output other nodes can consume, instead of you eyeballing it or counting frames in your head.

Inputs and outputs

  • images (required) - any IMAGE batch; a loaded video, a batch of generated frames, whatever
  • frame_rate - frames per second, 0.1 to 120, default 24

Outputs:

  • seconds (FLOAT) - duration of the batch at that frame rate
  • frame_count (INT) - number of frames

Where you'd actually use it

Video work is the obvious home. If you're converting a batch to video with VHS or a similar node, frame_count can feed the encoder's frame count input, and seconds can drive timing logic downstream - audio sync, interleaving, caption scheduling. It's also handy when you've generated a video as a batch and want to check you actually got the length you asked for before rendering. Pair it with the pack's BatchLastImage and you've got "last frame + its timestamp" in two nodes.

One caveat: it only knows what the batch has. If you load a video, ComfyUI keeps the frame count it decoded - so frame_count is accurate, but if you've dropped or duplicated frames upstream, seconds reflects the batch you fed it, not the source file. That's usually exactly what you want.

Install

Standard pack install - ComfyUI Manager (search "Latent Astronaut Suite") or:

cd ComfyUI/custom_nodes
git clone https://github.com/latentastronaut/comfyui-latent-astronaut-suite

Restart and you're done. No dependencies beyond what ComfyUI already ships. It's a tiny node, so the main "issue" is overthinking it: set frame_rate to match how your video is actually encoded (24, 30, 25 - whatever the source used), and the numbers will be right.

Categoryimage/latent-astronaut

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
frame_rateFLOAT24.00.1–120Frames per second

Outputs (2)

NameTypeDescription
secondsFLOAT
frame_countINT