Nodes/ComfyUI-AniPortrait/MaskList2Video
ComfyUI Node

MaskList2Video

Turn any segmentation mask into a padded crop — and the box to paste it back

By chaojie·Created 2 years ago·Updated 2 years ago· 251
MaskList2Video
  • image
  • mask
  • IMAGE
  • BOX
padding

MaskList2Video is the smartest of the three small helpers in ComfyUI-AniPortrait, because it's the one that actually looks at your image. You hand it a segmentation mask and it works out where the interesting thing is, crops around it with a bit of breathing room, and hands back both the crop and the box coordinates so you can stitch everything back together later.

In a typical AniPortrait workflow, that's exactly the move you need: segment the person out of a reference frame with something like GroundingDINO + SAM or a person-mask node, run this node to get a tight padded crop of the face/upper body, feed that crop to AniPortraitRun as the portrait to animate, then use the box it returned with CoverVideo to paste the animated result back onto the original frame. It's the bridge between "I have a mask" and "I have a clean region to animate."

How it works

The source is short and honest. It runs torchvision.ops.masks_to_boxes on your mask to get a bounding box, expands it by padding pixels on every side, clamps the result to the image bounds so you never slice out of range, and crops. That's the whole mechanism - no learning, no heuristics, just geometry.

The inputs that matter

  • image - the frame (or image batch) you're cropping.
  • mask - a MASK tensor from any segmentation node. The mask's bounding box is what drives the crop, so a sloppy mask gives you a sloppy crop.
  • padding - extra pixels added around the box so the crop isn't hugging the subject's face. The code intends 10 as the default, though the parameter's key is typo'd in the source (defualt), which on some ComfyUI versions means the field shows up without a default and asks you to type it. Ten to twenty pixels is a sane range; more if you want headroom for head motion.

Outputs are the cropped IMAGE and the BOX (as [x1, y1, x2, y2]). That box output is what makes the node genuinely useful - wire it into CoverVideo later and the paste-back lands exactly where the crop came from, no guesswork.

Installing it

Same pack, same dance as the rest:

cd ComfyUI/custom_nodes
git clone https://github.com/chaojie/ComfyUI-AniPortrait
pip install -r requirements.txt

No model downloads are needed for this node, and it'll run on a potato - but you still have to install the pack's full requirements first, because the whole nodes.py module (with its mediapipe, decord, av and friends) imports at load time. Once the pack is in, this is the node you reach for when a workflow says "mask the person" and you want a tight, animatable crop without thinking about pixel coordinates yourself.

CategoryAniPortrait

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingINT

Outputs (2)

NameTypeDescription
IMAGEIMAGE
BOXBOX