PC Video Mask Smooth Crop
Stop your video inpaint bounding box from jittering
- masks
- images
- cropped_masks
- bboxes
- cropped_images
"PC Video Mask Smooth Crop" is the node that turns a per-frame mask into a smoothly tracking crop of a video, the kind you need before you send a small moving subject to an inpaint or face-swap model. If you've ever tried video inpainting and watched the output flicker every time your box snaps to a new position, this is the fix.
Here's the problem it solves. Video inpainting - the LTX-2 style workflow this pack was born from - works like still-image "only masked" inpainting, just on every frame: mask the subject, crop it, run the model at proper resolution, paste it back. The catch is a raw per-frame bounding box dances. One frame the box is tight around the head, the next the segmentation wobbles and the box jumps a few pixels, and the video model treats that jitter as motion. The author's origin post says it plainly: he tried "all kinds of crop and stitch nodes," gave up, and wrote his own "to get a bounding box automatically and prevent jitter and jumping of it."
How it works
For every frame it finds the largest contour in the mask, gets its bounding rectangle, and pads it by your padding. Then comes the part that makes it different from a dumb crop: it keeps a running "camera" - a center and a size - and glides it toward each frame's mask with an exponential moving average. The center tracks at your smoothing_factor (default 0.05), the size moves even slower (a fifth of that rate). Net effect: the crop pans and zooms like a cameraman, not like a barcode scanner, and the box can't teleport between frames. Coordinates get clamped to the frame edges, then the crop is warped to your target resolution with Lanczos for the image and linear for the mask.
One detail worth knowing: output dimensions are snapped to multiples of 64, whatever you asked for. The code does this deliberately so the crop's latent is an even size for video models - useful, but don't be surprised when a 512 request on a wide subject comes back 512×384.
The inputs that matter
masks- your per-frame segmentation (from SAM3, or any mask-from-video node). This drives everything.images- the video frames to crop alongside.smoothing_factor- the jitter dial. 0.05 is gentle; higher makes the box chase the mask faster but jitter more.padding- breathing room around the subject, default 64px. Too little and the inpaint model sees the subject touch the crop edge; too much and you're back to processing half the frame.resolution- the long edge of the output crop, default 512.
It outputs cropped_masks and cropped_images (feed these into your inpaint step) plus bboxes in the standard BBOX type Impact Pack uses, so anything that understands a detection box can consume it - or you just hand it straight to this pack's stitcher.
How to install
ComfyUI Manager: search "PCVideoMask" and install. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/pavelchezcin/pcvideomask ComfyUI-PCVideoMask
Then restart ComfyUI. No models to download. The one real gotcha: the pack declares zero Python dependencies but imports OpenCV (cv2), and ships no requirements.txt. If opencv-python isn't already in your ComfyUI environment, the node fails at load. If that happens:
pip install opencv-python
Gotchas
The code only uses the largest contour per frame - if your mask contains several disconnected blobs, everything else is ignored. And it silently processes min(mask_count, image_count) frames, so if your mask batch and frame count drift apart, you'll get a truncated, misaligned result rather than an error. Keep those batches in lockstep. It's a young, two-node pack from a single author, so treat it as "works great for its lane," not as a general-purpose video toolkit - that lane is crop-and-stitch video inpainting, and it's genuinely good at it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — | |
| images | IMAGE | — | |
| resolution | INT | 512256–4096 | — |
| smoothing_factor | FLOAT | 0.050.01–1 | — |
| padding | INT | 640–512 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| cropped_masks | MASK | — |
| bboxes | BBOX | — |
| cropped_images | IMAGE | — |