Nodes/ComfyUI Layer Style/LayerUtility: Restore Pad Image Batch
ComfyUI Node Runs on cloud

LayerUtility: Restore Pad Image Batch

Restore Pad Image Batch

By chflame163·Created 3 years ago·Updated 17 days ago· 3,124
LayerUtility: Restore Pad Image Batch
  • images
  • images
◄original_batch_length—►

Restore Pad Image Batch is the bookend nobody gets excited about - and the one that stops your video from coming out with a pile of duplicate frames stapled to the end. Its job: after you padded a batch of frames up to some model-friendly length, trim it back to the exact count you started with.

It exists because of the video model frame-count problem. Lots of video pipelines want a batch length that follows a multiplier*n + remainder rule - Wan's VAE wants 4n+1 frames, some other processors want 8n+1 - and the clean fix is to pad your real footage up to the next valid length, run it through the model, then cut the filler back off. This node is the "cut it back off" step. Skip it and you save a video that's a few frames too long, the padding frames being copies of your last real frame.

How it works

Dead simple under the hood: it takes your images and an integer original_batch_length, and returns images[:original_batch_length] - the first N frames, nothing more. That's the whole mechanism, and it's correct because the pad node always prepends nothing and appends the filler at the end. Your original frames are untouched, in order, at the front of the batch.

There's one guard worth knowing: if original_batch_length is larger than the current batch length, it raises a ValueError rather than silently doing nothing. That's your cue that you wired the lengths wrong, not a bug.

The inputs and outputs

  • images - the processed batch (IMAGE).
  • original_batch_length (INT) - and this is where beginners trip. It's marked forceInput, which means ComfyUI expects it to come from a wire, not a hand-typed number. In practice you almost never type it; you connect the original_batch_length output of Pad Image Batch to 8n+1 straight in. The pad node records your true frame count for exactly this purpose, so let it do the bookkeeping.

Output: images - the trimmed batch, ready for your save/encode node.

Using the pair

Typical graph: load video → Pad Image Batch to 8n+1 → your processing (frame interpolation, upscaling, or a model that insists on the padded length) → Restore Pad Image Batch → save. The pad node is on the front door, this one's on the back door, and the original_batch_length wire between them is the handshake. If your batch was already at a valid length, the pad node is a no-op and this one trims nothing - the pair is harmless to leave in place.

One honest note: because this node only slices, you can also use it standalone to truncate any batch to N frames. That's a legitimate use, just not the one it was built for.

Installing it

Part of the ComfyUI Layer Style pack (chflame163) - a hugely popular Photoshop-style utility pack. Install via ComfyUI Manager (search "Layer Style"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle

Then install dependencies and restart - on the official portable build:

..\..\..\python_embeded\python.exe -s -m pip install -r requirements.txt
.\repair_dependency.bat

Expect a heavy install: the pack pulls transformers, timm, opencv-contrib-python, scikit-image, pymatting, and friends, even though this particular node is pure torch slicing. No model files needed for it.

Common issues

Your most likely failure isn't this node - it's the pack failing to import, the top complaint in r/comfyui threads about LayerStyle. It's almost always a dependency conflict after an update: a broken opencv-contrib-python (NameError: name 'guidedFilter' is not defined) or too-old transformers. Run repair_dependency.bat in the pack folder (or repair_dependency_aki.bat for Aki builds) and restart; if Manager's "Try Fix" keeps failing, a clean reinstall of the pack is the reliable move.

For this node specifically: keep the original_batch_length wire connected, and remember the restore count can never exceed the batch you hand it. Wire it from the pad node and you'll never hit that error in the first place.

Category😺dzNodes/LayerUtility

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE—
original_batch_lengthINT—

Outputs (1)

NameTypeDescription
imagesIMAGE—