Nodes/ComfyUI_Fill-Nodes/FL Video CropMask
ComfyUI Node

FL Video CropMask

Crop a video to a moving mask without the jitter

By filliptm·Created 3 years ago·Updated about 7 hours ago· 628
FL Video CropMask
  • video
  • mask
  • cropped_video
  • mask
  • original_video
  • crop_data
output_width512
output_height512
padding0
smoothing_factor0.5

When you want to run an expensive pass on just part of a video - say, a detailer or upscale on the subject and nothing else - you first have to crop each frame to that subject. Do it naively, per-frame, and the crop box jumps around because the mask wobbles slightly frame to frame. FL_VideoCropMask solves exactly that: it crops a video sequence to a mask's bounding box across every frame, with temporal smoothing so the crop window glides instead of jittering. It also hands you back the data you need to paste the processed region right back where it came from.

How it works

You feed it the video (as an IMAGE batch of frames) and a matching mask sequence. For each frame it finds the mask's bounding box, but instead of snapping the crop to each frame's raw box, it smooths the box motion over time by smoothing_factor - so a hand or face that shifts a few pixels doesn't send the crop lurching. It resizes each crop to your target output_width/output_height, keeps aspect sensible, and can add padding around the mask so you're not cropping too tight.

Crucially, it also outputs crop_data. That's the record of where each frame was cropped from, and it's what lets you reverse the operation: process the cropped clip (upscale it, restyle it, whatever), then use the pack's FL_VideoRecompose node with that same crop_data to drop the processed region back into the original frames at the right position and size. Crop → process → recompose is the whole pattern.

The inputs and outputs

  • video - the frames to crop (an IMAGE batch).
  • mask - the per-frame mask defining what to crop to.
  • output_width / output_height - the size each cropped frame is resized to.
  • smoothing_factor - how much to smooth the crop box's motion over time (0–1). This is the knob that kills the jitter; raise it if the crop still shakes, lower it if it lags behind fast motion.
  • padding - extra margin around the mask so the crop isn't uncomfortably tight.

Outputs: cropped_video (the cropped, resized frames), mask (the corresponding cropped masks), original_video (passed through), and crop_data - feed that last one to FL_VideoRecompose.

Installing it

Ships in the Fill-Nodes pack. ComfyUI Manager: search ComfyUI_Fill-Nodes, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/filliptm/ComfyUI_Fill-Nodes

then restart. The "Machine Delusions" splash banner in the console at startup is cosmetic.

Where people get tripped up

  • You need FL_VideoRecompose to close the loop. Cropping is only half the workflow. If you process the cropped clip and then wonder how to get it back into the full frame, that's what crop_data + the recompose node are for. Keep the crop_data wire alive.
  • smoothing_factor is a trade. Too low and the crop jitters with the mask; too high and it lags behind genuine subject motion, clipping the subject on fast movement. Tune it to your footage.
  • Video and mask must line up frame-for-frame. Mismatched frame counts between the video and the mask sequence is the classic breakage. Make sure both came from the same clip length.
  • Tight crops plus small output sizes lose detail. If the subject is small in frame and you crop tight to a 512×512 output, you're throwing away pixels before the expensive pass even runs. Use padding and a sensible output size.
Category🏵️Fill Nodes/Utility

Inputs (6)

NameTypeDefaultDescription
videoIMAGE
maskIMAGE
output_widthINT51264–2048
output_heightINT51264–2048
paddingINT00–100
smoothing_factorFLOAT0.50–1

Outputs (4)

NameTypeDescription
cropped_videoIMAGE
maskIMAGE
original_videoIMAGE
crop_dataCROP_DATA