Nodes/CRT-Nodes/Isolate Input SAM3.1 (CRT)
ComfyUI Node

Isolate Input SAM3.1 (CRT)

Track and crop a face through a whole video with SAM 3.1

By PGCRT·Created 2 years ago·Updated a day ago· 132
Isolate Input SAM3.1 (CRT)
  • images
  • cropped_images
  • pipe
what_to_detectface
performance_presetQuality
single_itemfalse
detect_chunk_size0
padding512
threshold0.30
bbox_expansion0.75
crop_smooth_alpha1.00
crop_megapixels1.00

If you've ever needed to "zoom on the face" across a whole video - a talking head, an actor walking toward camera - you know the nightmare: crop the first frame, the subject moves, the crop is wrong, and now you're hand-keyframing boxes in an editor. Isolate Input SAM3.1 (CRT) is the node that automates it: it uses SAM 3.1 to find the subject you describe (default "face") in every frame, crops around it with smooth motion, and passes a reconstruction pipe to its sibling Isolate Output (CRT) so you can composite the cropped video back onto your own framing. It's subject tracking for video, inside the graph.

How it works

It runs in two halves. This node, the input side, does the detection and cropping:

  • detects instances matching what_to_detect (a plain-language prompt like "face" or "person") across the batch using SAM 3.1,
  • expands the detected box (bbox_expansion) so the crop isn't skin-tight,
  • temporally smooths the crop position (crop_smooth_alpha) so it glides rather than jitters between frames - lower values = steadier, higher = tracks motion closer,
  • rescales the crops to crop_megapixels (0 disables rescaling),
  • and hands the crops out as cropped_images plus a pipe bundle (original frames, masks, boxes, source indices) that CRT_IsolateOutput needs to stitch things back.

The performance_preset (Fast / Balanced / Quality) trades detection cost against quality; single_item limits detection to one subject per frame (right for "main face"); detect_chunk_size controls batch size (0 = whole batch at once, 1 = per-image); threshold is the detection confidence cutoff; padding adds a border around the batch before detection so edge-hugging subjects don't get cropped too tight.

The SAM 3.1 checkpoint (sam3.1_multiplex_fp16.safetensors) auto-downloads from Comfy-Org on first use into models/checkpoints. There's also a caching layer keyed on a fingerprint of the inputs, so re-running the same batch is fast.

The big requirement

This node needs ComfyUI with SAM3 support - the source is explicit: PR #13408 or later, and it imports comfy.ldm.sam3 to check. If your ComfyUI is older than that, the node logs a warning at startup and detection won't work. Update ComfyUI before debugging anything else. This is the single most common reason this node "doesn't work" out of the box.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/PGCRT/CRT-Nodes.git
pip install -r requirements.txt

or ComfyUI Manager → search "CRT-Nodes". Zero dependency on other custom-node packs - the module is self-contained.

Gotchas

First run downloads the SAM 3.1 checkpoint (a few GB). Detection at full video resolution is heavy, which is why the presets exist - start on Fast to validate the crop logic, then move to Balanced/Quality for the final pass. Lower crop_smooth_alpha first if the crop bobs around (that's the #1 tweak for shaky tracking), and raise bbox_expansion if the subject gets chopped mid-motion. And remember the pipe output must go to Isolate Output (CRT) - without it you just have loose crops, not a composited result.

CategoryCRT/Utils/Isolate

Inputs (10)

NameTypeDefaultDescription
imagesIMAGE
what_to_detectSTRINGfaceText prompt used for subject detection, for example 'face' or 'person'.
performance_presetCOMBOQualityFast = quickest detection, Balanced = default tradeoff, Quality = highest available quality in the current custom-node path and slower processing. The SAM path still uses a model-safe square working resolution.
single_itemBOOLEANfalseLimit detection to one item per frame. Enable this when you only want the main face/subject.
detect_chunk_sizeINT00–4096Detection batch size. 0 = process the whole batch at once, 1 = per-image processing, 2+ = fixed chunk size.
paddingINT5120–2048Extra border added around the input batch before detection so subjects near the edges are not cropped too tightly.
thresholdFLOAT0.300–1Detection confidence threshold. Lower values find more masks, higher values are stricter.
bbox_expansionFLOAT0.750.5–4Expands the detected crop box around the subject. Higher values give a looser crop.
crop_smooth_alphaFLOAT1.000–1Temporal smoothing for crop position. Lower = steadier crop, higher = follows motion more closely.
crop_megapixelsFLOAT1.000–8Target resolution for the cropped output images. 0 disables crop rescaling.

Outputs (2)

NameTypeDescription
cropped_imagesIMAGE
pipeCRT_ISOLATE_PIPE