Nodes/ComfyUI-PJLatent/PJ Video Latent Generator
ComfyUI Node

PJ Video Latent Generator

Video latents are a different beast — PJ Video Latent Generator sizes them for you

By pongjoo·Created 7 months ago·Updated 2 months ago· 0
PJ Video Latent Generator
    • LATENT
    • width
    • height
    • length
    • batch_size
    aspect_ratio
    longest_side1024
    duration_seconds5
    batch_size1

    Image latents are easy to reason about: four channels, 8x smaller each side, done. Video latents are the same idea with two extra dimensions - time, and four times the channels - and that's where people's eyes glaze over. PJ Video Latent Generator is a cousin of the pack's PJ Latent Generator, but shaped for video models like HunyuanVideo and Wan: a 16-channel 5D latent, with the frame count and temporal compression handled for you.

    If you've ever stared at a video workflow and wondered what the empty latent node is actually supposed to output for HunyuanVideo, this is the answer wrapped in a dropdown. You tell it the aspect ratio, the longest side, and how many seconds you want. It does the rest.

    How it works

    The math is the interesting part, and it's specific to how video VAEs compress. Where an image VAE downsamples only spatially (8x per side), a video VAE also compresses along time - HunyuanVideo-style models use roughly 4x temporal compression. So the node builds:

    torch.zeros([batch, 16, (frames-1)//4 + 1, H/8, W/8])

    The 16 is the video latent channel count (vs 4 for images). The frame count comes from your duration at an assumed 16 FPS: frames = seconds * 16 + 1, so a default 5-second clip is 81 frames. That (frames-1)//4 + 1 term is the temporal axis after 4x compression - 81 frames becomes 21 latent time-steps. Width and height get snapped to multiples of 16 rather than 8, which is the convention the video samplers expect.

    This is the node's whole value proposition: get any of those dimensions wrong and the model silently produces garbage or errors out. This one makes the shape correct by construction.

    Inputs and outputs

    • aspect_ratio - same 9 presets as the image node (1:1, 4:3, 3:4, 16:9, 9:16, 2:3, 3:2, 21:9, 9:21).
    • longest_side - default 1024, 64–8192, step 16.
    • duration_seconds - default 5, range 1–60. This is how long you want the clip, not the frame count.
    • batch_size - default 1; each item in the batch is a separate video.

    It outputs LATENT, plus width, height, length (the actual frame count, 81 for the default) and batch_size as integers. The length output is the one to watch - it's the ground truth of how many frames you'll actually get, useful if your downstream node or VAE wants the real count.

    Installing it

    Same pack as the rest: ComfyUI Manager, search PJLatent, or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/pongjoo/ComfyUI-PJLatent.git
    

    Restart, and it's under Add Node → PJ_Nodes → Latent. Pure torch, no extra dependencies, nothing to download.

    Where people get burned

    The 16 FPS assumption is baked in, not optional. If your model family expects a different frame-rate convention (24 FPS is common), a "5 second" latent here isn't 5 seconds in your sampler's head - so check the length output and adjust duration_seconds rather than trusting the label. And be honest about VRAM before you go big: 16 channels is four times the latent memory of image generation, and a 1024-wide, 81-frame HunyuanVideo latent on top of the model weights will flatten anything under ~16 GB. The 60-second max is technically allowed; practically it's a ticket to swap territory. Start at the 5-second default at 768–1024 and scale up from there.

    CategoryPJ_Nodes/Latent

    Inputs (4)

    NameTypeDefaultDescription
    aspect_ratioCOMBO9 options: 1:1, 4:3, 3:4, 16:9, 9:16, 2:3, +3
    longest_sideINT102464–8192
    duration_secondsINT51–60
    batch_sizeINT11–64

    Outputs (5)

    NameTypeDescription
    LATENTLATENT
    widthINT
    heightINT
    lengthINT
    batch_sizeINT