小珠光帧提取
The inverse of frame optimization
- image
- mask
- image
- mask
Frame padding is a one-way door unless you keep the bookkeeping. 小珠光帧提取 (Xiaozhuguang Frame Extract) is the key that opens it back up: you give it a batch that's been padded on the front and/or back, tell it how much padding there was (front_fill / back_fill), and it returns just the original frames - with image and mask handled together.
Think of it as the mirror image of the pack's DuplicateFirstFrame. That node pads a video for frame-count-sensitive models; this one strips the padding so you get your actual footage back after the model's done with it. You pad a short clip to 73 frames for a video model, generate, then extract to throw away the 60 duplicated frames and keep the 13 real ones. Without this, you'd be stuck hand-slicing tensor indices or shipping a video full of still frames.
How it works
Pure slicing with safety rails. It computes start = front_fill and end = batch_count - back_fill, then returns image[start:end] (and the matching mask slice). If the math goes wrong - more padding than frames, a start past the end - it clamps and returns a 1×1 empty rather than raising. It accepts image, mask, or both: pass only a mask and it slices the mask; pass neither and it returns empty placeholders. Since v12.11.0 it's fully cache-friendly (a plain IS_CHANGED that returns None), so it won't recompute on every queue unless the input actually changed.
The inputs that matter
image- optional. The padded frame batch.mask- optional. A matching mask batch, sliced identically.front_fill- how many leading frames to strip.back_fill- how many trailing frames to strip.
Outputs: image and mask, both with the padding removed.
The clean pattern: wire the front_fill and back_fill outputs from DuplicateFirstFrame straight into these two inputs. The numbers are already correct, and they stay in sync with the batch even when the source length changes.
Install
From the ComfyUI-xiaozhuguang pack - Manager (search "ComfyUI-xiaozhuguang"), or:
cd ComfyUI/custom_nodes/
git clone https://github.com/xiaozhuguang/ComfyUI-xiaozhuguang.git
Restart. No dependencies beyond torch.
Gotcha
The one reliable way to break it: type the fill numbers in by hand and get them wrong. front_fill + back_fill must be less than the total batch or the extract clamps to empty, and you get a 1×1 image out instead of a helpful error. That's why the padding outputs from DuplicateFirstFrame exist - wire them, don't retype them.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| imageopt | IMAGE | — | |
| maskopt | MASK | — | |
| front_fillopt | INT | 00–99999 | — |
| back_fillopt | INT | 00–99999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |