Nodes/ComfyUI-SAM2Matting/SAM2Matting Video Background (Streaming)
ComfyUI Node

SAM2Matting Video Background (Streaming)

Streams a native ComfyUI VIDEO through temporal matting, composites the foreground over a solid color, and returns both that native H.264 VIDEO and a lossless white-on-black matte VIDEO. Tracking frames and mattes are disk-backed, so host RAM does not grow with the full-resolution clip length. Connect either result to ComfyUI Save Video.

By ethanfel·Created 17 days ago·Updated 9 days ago· 5
SAM2Matting Video Background (Streaming)
  • model
  • video
  • initial_mask
  • streaming_options
  • video
  • matte_video
mask_frame0
mask_threshold0.50
background_color#808080
state_devicegpu
CategorySAM2Matting/video

Inputs (8)

NameTypeDefaultDescription
modelSAM2MATTING_VIDEO_MODELLoaded SAM2Matting temporal video model.
videoVIDEONative, file-backed ComfyUI video. Use Load Video Path (Native) for files too large for browser upload.
initial_maskMASKSeed mask for one source frame: white is the foreground subject to keep, black is background.
mask_frameINT00–2147483647Zero-based video frame that matches initial_mask. Tracking propagates forward and, when needed, backward from this frame.
mask_thresholdFLOAT0.500–1Threshold used only to turn the seed mask into a binary tracking prompt. It does not threshold the soft output matte.
background_colorSTRING#808080Solid RGB background written behind the extracted foreground, as a six-digit hex color such as #808080.
state_deviceCOMBOgpuWhere the bounded temporal tracking state is stored. gpu is faster and avoids system-RAM pressure; cpu saves VRAM but is slower and uses host RAM.
streaming_optionsoptSAM2MATTING_STREAMING_OPTIONSOptional advanced settings from SAM2Matting Streaming Options. Leave disconnected for recommended defaults.

Outputs (2)

NameTypeDescription
videoVIDEOFile-backed H.264 MP4 with the tracked foreground composited over the chosen color.
matte_videoVIDEOFile-backed lossless matte video: white foreground, black background, and soft gray edges.