Nodes/ComfyUI_Swwan/Pad Image Batch Interleaved (Swwan)
ComfyUI Node

Pad Image Batch Interleaved (Swwan)

Insert blank frames between your frames and get a mask for free

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Pad Image Batch Interleaved (Swwan)
  • images
  • images
  • masks
◄empty_frames_per_image1►
◄pad_frame_value0.00►
◄add_after_lastfalse►

What it's for

It takes a batch and spreads the frames out, inserting N blank frames between each original. [A, B, C] with empty_frames_per_image=2 becomes [A, –, –, B, –, –, C].

Why on earth? Timing. Frames in ComfyUI don't carry a duration, so "hold this image for three frames at 8fps" has to be expressed as three actual frames. This node is how you get holds, stutters and frame-rate changes without a video editor: pad a keyframe batch and every shot lingers. It's also the plumbing under simple frame-interpolation tricks - insert blanks, let an interpolator fill them, and you've invented easing out of a batch of stills. The pack's preview and transition nodes are the natural companions: pad the batch, then watch it with Preview Animation.

KJNodes' original, in the pack's Swwan/Advanced/Batch drawer.

How it works

Three widgets, one non-obvious interaction:

  • empty_frames_per_image (default 1) is how many blanks go between each pair of real frames.
  • pad_frame_value is the fill value, 0 to 1. 0 is black, 1 is white. If you're feeding an interpolator, 0 is the safer choice - but note the padded frames are constant-filled, not noise, so a motion interpolation pass on a blank frame has nothing to interpolate toward except its neighbours.
  • add_after_last appends a final run of blanks.

The count arithmetic has a special case worth knowing, straight from the source: a single-frame batch doesn't get padding at all unless add_after_last is on - B=1 gives you 1 frame, or 1 + empty_frames_per_image with the flag. That's not a bug so much as a deliberate guard: "insert between frames" is meaningless with one frame, and silently tripling it would be worse. With two or more frames you get B + (B-1) × empty_frames_per_image, plus empty_frames_per_image more if add_after_last.

Then the second output, masks, and this is the part people miss. For every frame position the node emits a mask that is 1.0 for an original frame and 0.0 for an inserted one - flat, per-frame, full resolution. It's a "was this a real frame" flag in mask clothing. Use it to multiply a mask chain (so your per-frame masks don't get applied to blanks), to drive a composite or a fade, or as the condition for whichever mask-aware node you're already running downstream. Nothing else in the batch toolkit hands you that labelling.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Restart, refresh the browser, search Swwan. Tensor-only work: no models, no GPU needed, and it's fast even on long batches because it allocates one filled tensor and writes the originals into it rather than looping with concatenations.

Common issues

A single image didn't get padded. By design - turn on add_after_last if you want the hold at the end.

My video came out with a black flash. A padded frame reached the output. Insert them before processing and take them back out with Replace Images In Batch or a batch-range node, or mask them downstream with the masks output.

Blanks look grey. pad_frame_value=0 is black in 0–1 float terms; a value like 0.5 is middle grey, which is often a better neutral for interpolation or blending work than pure black.

The batch got much bigger than expected. You asked for 8 frames between each of 30 frames; that's 240 frames, and at 1080p that's several gigabytes of float32. Put the padding near the end of the chain, not the start.

CategorySwwan/Advanced/Batch

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE—
empty_frames_per_imageINT10–4096—
pad_frame_valueFLOAT0.000–1—
add_after_lastBOOLEANfalse—

Outputs (2)

NameTypeDescription
imagesIMAGE—
masksMASK—