How Motion Mask Works
All neural inference, optical block-matching propagation, alpha fusion, and video effect compositing run off
the main thread inside three dedicated module Web Workers with zero server uploads.
1. SAM 3 Tracker Vision Encoder + Prompt Decoder
onnx-community/sam3-tracker-ONNX (model_type: sam3_tracker, local
Transformers.js 4.3.2 pin inside worker.js) ships two ONNX subgraphs:
vision_encoder (1008×1008 input → 3-level pyramid image_embeddings.0/1/2) and
prompt_encoder_mask_decoder (points + boxes → 3 candidate masks [1,1,3,288,288]
+ iou_scores). Because this ONNX export omits the PyTorch-only temporal memory bank,
multi-frame tracking pairs SAM 3 with coarse-to-fine SAD optical displacement to carry boxes and interior
anchors across frames while caching up to 12 encoded frame pyramids for ~21–44 ms click refinement.
2. BiRefNet-lite 512×512 Crop-Level Edge Polish
studioludens/birefnet-lite-512 (MIT, 98.48 MB fp16 swin, shared
Transformers.js 3.7.5) solves the 1024×1024 browser OOM wall by re-exporting deformable convolutions at
512×512. Stage 2 crops tightly around the SAM 3 subject ROI (+22% padding), runs CPU WASM
fp16 (avoiding the 3.7.5 WebGPU WGSL computeSliceOffsets compiler bug), applies
sigmoid to output_image, and blends continuous alpha back inside a soft-dilated SAM 3 gate.
3. Off-Thread VFX Compositor & Zero-Dep Exports
compositor-worker.js executes 2-pass separable Gaussian privacy blur, Color Pop background
desaturation, checkerboard cutout previews, and SAD motion estimation on transferable
ArrayBuffers. Export individual lossless RGBA PNGs, a pure-JS Store-mode .zip
PNG sequence, or a recorded video/webm clip directly from canvas.