Why SAM 2 + FFmpeg Dilation + Wan VACE 14B beats manual VFX paint-and-roto
Manually painting out a creeping boom mic, camera reflection, or pedestrian across 120 frames in After Effects or Nuke routinely eats two to four billable hours. Chaining Meta SAM 2 (~$0.02/clip API or $0 Apache-2.0 local) into Alibaba Wan VACE 14B ($0.08/sec = $0.40 per 5s clip, or $0 Apache-2.0 local) solves the exact same shot in under five minutes—provided you obey two upstream geometry rules: constant-frame-rate locking and binary matte dilation.
Step 1: Lock 24fps CFR & protect uncompressed production audio
iPhones and screen capture tools record variable frame rate (VFR) video. Feeding raw VFR clips straight into temporal tracking makes SAM 2 masks drift 2 to 4 frames behind camera pans. Run --prep in the copyable script above (verified locally on FFmpeg 9.0.1 using -fps_mode cfr, replacing the deprecated -vsync flag) to emit:
plate_cfr24.mp4— exact integer 24fps constant-frame-rate visual plate (yuv420p, even dimensions).original_audio_48k.wav— untouched 48 kHz dialogue and room tone ready to re-mux at Step 4.
Need custom SDR tone-mapping or broadcast mastering flags alongside CFR? Generate verified commands in our FFmpeg Studio Command Builder.
Step 2: Generate a temporal mask in Meta SAM 2 & dilate +12px
Submit plate_cfr24.mp4 to Meta SAM 2 (fal-ai/sam2/video or local ComfyUI-SAM2):
- Drop 1–2 positive points (
label: 1) directly onto the unwanted object on frame0(plus an extra positive point directly on a long dark shadow if sunset light stretches it far across the pavement). - Drop negative points (
label: 0) onto any foreground actor passing in front of the target so SAM 2 preserves the actor crisply.
Next, run --dilate sam2_mask.mp4 12. Our local verification confirmed boxblur=12:1 + lut threshold + boxblur=2:1 expands every white edge smoothly by +11–12 pixels radially (+22px total width/height), engulfing dark contact shadows and motion-blur fringes cleanly so zero phantom smudges survive inpainting.
Step 3: Run Wan VACE 14B asynchronously with a clean-plate prompt
Invoke --vace in the script above—which calls queue.fal.run/fal-ai/wan-vace-14b (preventing 60-second HTTP 504 timeouts) with match_input_frames_per_second: true and match_input_num_frames: true.
Build your clean-plate prompt using our V2V Object Removal & Subject Swap Prompt Builder, remembering never to name the removed object inside the positive prompt. Put unwanted shapes strictly in negative_prompt.
Step 4: Patch over 4K plates & re-mux original WAV audio
If your source footage is 720p/1080p social video, run --mux vace_clean_720p.mp4 original_audio_48k.wav final_clean.mp4 and ship. For 4K commercial masters, run vace_clean_720p.mp4 through Topaz Video Upscale API ($0.40 for 5s 4K), track-matte ONLY the feathered mask_dilated.mp4 area over your untouched 4K camera plate in DaVinci Resolve, and re-mux original_audio_48k.wav ($0.82 total shot cost!).
Hit a shadow smudge or frame drift? Jump straight to Fix 73: Video Object Removal Ghost Smudges & Mask Bleed or read our complete AI Video Object Removal & 3D Rigging Guide.