Nodes/ComfyUI Essentials/πŸ”§ Mask Expand Batch
ComfyUI Node Runs on cloud

πŸ”§ Mask Expand Batch

Padding a mask batch up to match your frame count

By cubiqΒ·Created 3 years agoΒ·Updated about a year agoΒ· 1,152
πŸ”§ Mask Expand Batch
  • mask
  • MASK
β—„size16β–Ί
β—„methodβ–Ύβ–Ί

Same job as this pack's Image Expand Batch, applied to masks instead of images: Mask Expand Batch grows a batch of masks up to a target count, rather than just stacking two together (that's what Mask Batch is for). You'll want this when a mask batch needs to line up frame-for-frame with an image or latent batch that's already been padded out to a specific length - a mismatched count here means mask 5 stops corresponding to frame 5, quietly.

This is a quiet but common failure mode in video and batch inpainting workflows: you generate or load a mask for the first frame of a sequence, and then the actual image/latent batch downstream gets padded out to 16, 24, or however many frames a motion module needs - but the mask batch never gets the same treatment and stays at its original length. Everything looks fine until a batch-size assertion fails somewhere deep in the graph, or worse, doesn't fail and silently applies mask 1 to frame 1 through frame 16 because of how some consuming node broadcasts a short batch. This node exists specifically to keep that from happening.

How it works

size (default 16) is the target batch count. method mirrors Image Expand Batch's options exactly:

  • expand - spreads new masks in across the existing sequence.
  • repeat all - loops the whole existing batch to fill up to the target.
  • repeat first - pads the front by repeating the first mask.
  • repeat last - pads the tail by repeating the last mask.

Inputs and outputs

mask, size (INT, minimum 1, default 16), method (enum: expand / repeat all / repeat first / repeat last). Output: MASK.

Installing it

Via ComfyUI Manager, search "ComfyUI Essentials". Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/cubiq/ComfyUI_essentials

Restart. Maintenance-only pack since April 2025.

Common issues & troubleshooting

Mask batch and image batch are the same length but content doesn't line up. This is the failure mode that matters most for this node: keep it in lockstep with whatever padded your paired image or latent batch - same target size, same method. Padding a mask batch with repeat last while the matching image batch was padded with repeat first (or via expand) will leave you with two batches of identical length and completely misaligned content.

Set size smaller than your current mask count expecting it to trim. It won't - this node only pads up to a target, the same as its image sibling. Use a different node if you need to shrink a batch.

Not sure which method to pick. Match whichever choice you used (or plan to use) for the corresponding image/latent batch. There's no mask-specific reason to pick differently - the goal is always alignment with whatever this mask batch is meant to travel alongside.

Only have one mask and need it to cover a whole sequence. That's the simplest case for this node - repeat all (or repeat first/repeat last, all equivalent when there's only one source mask) will fill your target size with copies of that single mask, which is exactly what you want when the masked region genuinely doesn't move across the sequence.

Categoryessentials/mask batch

Inputs (3)

NameTypeDefaultDescription
maskMASKβ€”
sizeINT16β€”
methodCOMBO4 options: expand, repeat all, repeat first, repeat last

Outputs (1)

NameTypeDescription
MASKMASKβ€”