智能视频裁剪 (Smart Video Crop)
Auto-crop a driving video around the tracked person
- frames
- track_data
- mask_frames
- cropped_frames
- cropped_mask
- debug_info
Motion-transfer models care about the person, not the scenery. A wide shot where your dancer occupies a fifth of the frame produces a generation where the character is tiny and the pose signal is weak - SCAIL-2 and WanAnimate both work far better when the subject fills the frame. SmartVideoCrop is the automatic version of the manual "crop the clip to the person" step: it takes video frames plus SAM3 tracking data, finds the tracked subject's bounding region every frame, and outputs a smoothly following crop at whatever resolution you set.
It's built on a pretty clean mechanism. The node unpacks the packed masks from a SAM3 tracking result (SAM3_TRACK_DATA, the same driving_track_data you'd feed a SCAIL-2 node), combines the masks for the object IDs you select, computes the centroid of that mask per frame, and slides a crop window around it. The window is smoothed frame to frame so it doesn't jitter, and it watches for scene cuts: if the centroid jumps more than scene_cut_threshold between consecutive masked frames, it treats it as a cut and resets the smoothing instead of trying to glide across a hard transition.
The inputs that matter
- frames - the current chunk's video frames
(B, H, W, C)(required). - track_data - SAM3_VideoTrack output. This is the required input that makes everything else possible.
- object_ids - which tracked person(s) to follow, comma-separated like
1or1,2(default1). If SAM3 assigned your dancer ID 3, this is where you tell it. - output_width / output_height - the crop resolution (defaults 480×864, both stepped to multiples of 16 for video-model friendliness).
- smoothing (default 0.3) - inter-frame smoothing: 0 is no smoothing (raw follow), 1 is completely static. Low values track fast but jitter; higher values are steadier but lag quick moves.
- mask_fallback (hold_last/center) - what happens when a frame's mask is empty (tracking lost the subject).
hold_lastkeeps the last valid position;centerreturns to the middle of the frame. - scene_cut_threshold (default 0.3) - normalized centroid-jump threshold for cut detection, 0 disables it.
- mask_frames (optional) - a second image stream (like a mask video) cropped with the exact same window, so masks and frames stay pixel-aligned after cropping.
Outputs are cropped_frames, cropped_mask (both cropped with the same window), and debug_info - a string you can route to a text preview to see what the tracker was doing.
Notes and gotchas
You need SAM3 tracking running upstream (an external tracking model; this node only consumes its output), and the tracking quality is the ceiling on crop quality - if SAM3 loses the subject, the fallback behavior kicks in. The default is a portrait 480×864, which suits a standing person; for dance where the subject moves wide, you may want to let output_width grow. Start with hold_last for fallback and only switch to center if tracking drops make the crop wander.
Install
Part of ComfyUI-CustomNodeKit. ComfyUI Manager → search "ComfyUI-CustomNodeKit", or:
cd ComfyUI/custom_nodes
git clone https://github.com/user2318/ComfyUI-CustomNodeKit.git
cd ComfyUI-CustomNodeKit
pip install -r requirements.txt
Restart ComfyUI. No models bundled - SAM3 itself is a separate install.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| frames | IMAGE | 当前段的原始视频帧 (B, H, W, C)。Original video frames of the current chunk. | |
| track_data | SAM3_TRACK_DATA | SAM3_VideoTrack 输出的追踪数据(接 driving_track_data)。Track data from SAM3_VideoTrack (connect to driving_track_data). | |
| output_width | INT | 48064–4096 | 输出视频宽度。Output video width. |
| output_height | INT | 86464–8192 | 输出视频高度。Output video height. |
| object_ids | STRING | 1 | 追踪的人物 ID,逗号分隔(如 '1' 或 '1,2')。空=默认 ID=1。Person IDs to track, comma-separated (e.g. '1' or '1,2'). Empty=default ID=1. |
| smoothing | FLOAT | 0.300–1 | 帧间平滑度(0=无平滑,1=完全不跟随)。Inter-frame smoothing (0=no smoothing, 1=completely static). |
| mask_fallback | COMBO | hold_last | mask 为空时的处理方式。hold_last=保持最后有效位置;center=回退到画面中心。Behavior when mask is empty. hold_last=keep last valid position; center=fall back to center. |
| scene_cut_threshold | FLOAT | 0.300–1 | 切镜检测阈值(归一化,0=关闭检测)。仅当质心在连续有 mask 的帧间跳变超过此值时判定为切镜,关闭平滑。Scene cut threshold (normalized, 0=disabled). Only triggers when centroid jumps more than this between consecutive masked frames; disables smoothing on cut. |
| fallback_centeropt | FLOAT | 0.500–1 | 仅在 mask_fallback=center 时生效。回退水平中心比例(0=最左, 0.5=居中, 1=最右)。Only effective when mask_fallback=center. Fallback horizontal center ratio (0=left, 0.5=center, 1=right). |
| mask_framesopt | IMAGE | 可选第二路图像(如遮罩),与 frames 同步裁剪。两路共用同一质心和裁剪窗口。Optional second image (e.g. mask) to crop with same parameters as frames. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| cropped_frames | IMAGE | — |
| cropped_mask | IMAGE | — |
| debug_info | STRING | — |