Skip to content
FramesField
Intermediate Light CLI / Copy-Paste Script
Verified Dec 1, 2026

Meta SAM 2 Masking + Wan VACE 14B Video Object Removal Pipeline ($0.42–$0.82 / 5s)

What you’ll make

A clean-plate 720p or 4K-patched MP4 video with the unwanted object and its cast shadow completely removed and original uncompressed 48 kHz WAV audio re-muxed.

Erase boom mics, light stands, branded logos, or stray bystanders from moving video without shifting a single untouched pixel: conform smartphone VFR to 24fps CFR via FFmpeg (-fps_mode cfr), generate a temporal mask with Meta SAM 2 (~$0.02 API or $0 Apache-2.0 local), dilate the binary matte +12 pixels to swallow cast shadows, inpaint clean background via Alibaba Wan VACE 14B ($0.08/s = $0.40/5s), and optionally upscale to 4K via Topaz Video API ($0.40).

Before you start
  • A 3–10 second source clip showing the unwanted object cleanly separated from primary faces
  • FFmpeg 5.1–9.x, curl, and jq installed locally (plus FAL_KEY for cloud runs, or 24GB VRAM ComfyUI for $0 Apache-2.0 local runs)
  • Public HTTPS hosting (or fal storage) for the conformed CFR clip and dilated mask video
Estimated cost
$0.42 per 5s 720p removal · $0.82 with Topaz 4K patch finish ($0.00 fully local Apache-2.0)
Time needed
20 min
Jump to section (5)
  1. 01Why SAM 2 + FFmpeg Dilation + Wan VACE 14B beats manual VFX paint-and-roto
  2. 02Step 1: Lock 24fps CFR & protect uncompressed production audio
  3. 03Step 2: Generate a temporal mask in Meta SAM 2 & dilate +12px
  4. 04Step 3: Run Wan VACE 14B asynchronously with a clean-plate prompt
  5. 05Step 4: Patch over 4K plates & re-mux original WAV audio
Step-by-step overview
SIGNAL PATH READY Click any node or press “Step Through” to trace data flow from input plate to final deliverable.
01–04
CFR 24fps Plate → Meta SAM 2 Track → FFmpeg +12px Dilation → Wan VACE 14B Clean Plate
Official Demo · Privacy-Enhanced Player (Zero Cookies Until Click)

CFR 24fps Plate → Meta SAM 2 Track → FFmpeg +12px Dilation → Wan VACE 14B Clean Plate

Bria AI (Official Demo) · youtube-nocookie.com
Frame 01 PREP · $0.00
24fps CFR + WAV Archive
FFmpeg -r 24 -fps_mode cfr

Eliminates variable-frame-rate smartphone drift and preserves untouched 48 kHz dialogue.

Frame 02 MASK · ~$0.02
SAM 2 Track + 12px Pad
boxblur=12:1 + lut threshold

Expands tight silhouette mask radially so dark contact shadows vanish alongside the prop.

Frame 03 CLEAN · $0.40
Wan VACE 14B Inpaint
$0.08/s · Clean-Plate Prompt

Prompt strictly for revealed background; composite Topaz 4K patch over original 4K plate.

Conforming phone VFR and dilating SAM 2 binary mattes by +12px prevents shadow trails and matte sync drift during Wan VACE 14B video inpainting.

Source: Bria AI (Official Demo) Model: META SAM 2 + ALIBABA WAN VACE 14B (APACHE-2.0) Verified Dec 1, 2026
Original source ↗

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 frame 0 (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.

Copy-paste template

Verified CFR Conform, +12px SAM 2 Mask Dilation & Wan VACE 14B Queue Script sam2-wan-vace-removal.sh
Tested locally on FFmpeg 9.0.1: locks source footage to 24fps CFR (-fps_mode cfr), dilates Meta SAM 2 masks +11–12px radially to erase cast shadows, queues Wan VACE 14B ($0.08/s) cleanly on queue.fal.run, and re-muxes original 48 kHz audio.
#!/usr/bin/env bash
set -euo pipefail
# Verified locally on FFmpeg 9.0.1 (uses -fps_mode cfr, never removed -vsync)
# 1) ./sam2-wan-vace-removal.sh --prep raw_clip.mov
# 2) Run Meta SAM 2 (fal-ai/sam2/video or local ComfyUI) on plate_cfr24.mp4 -> sam2_mask.mp4
# 3) ./sam2-wan-vace-removal.sh --dilate sam2_mask.mp4 12
# 4) FAL_KEY="..." ./sam2-wan-vace-removal.sh --vace <plate_url> <dilated_mask_url> "Empty warm plaster wall, soft afternoon light"

MODE="${1:?Use --prep <raw> | --dilate <sam2_mask.mp4> [radius=12] | --vace <plate_url> <mask_url> <bg_prompt> | --mux <vace.mp4> <audio.wav> <final.mp4>}"

if [ "${MODE}" = "--prep" ]; then
  RAW="${2:?Pass raw video file}"
  ffmpeg -v warning -y -i "${RAW}" \
    -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p" \
    -r 24 -fps_mode cfr -c:v libx264 -crf 16 -an -movflags +faststart plate_cfr24.mp4
  ffmpeg -v warning -y -i "${RAW}" -vn -c:a pcm_s16le -ar 48000 original_audio_48k.wav || true
  echo "Saved plate_cfr24.mp4 + original_audio_48k.wav"
  exit 0
fi

if [ "${MODE}" = "--dilate" ]; then
  MASK="${2:?Pass raw SAM 2 mask video}"
  RAD="${3:-12}"
  ffmpeg -v warning -y -i "${MASK}" \
    -vf "format=gray,boxblur=${RAD}:1,lut=y='if(gt(val,18),255,0)',boxblur=2:1,format=yuv420p" \
    -r 24 -fps_mode cfr -c:v libx264 -crf 18 -an -movflags +faststart mask_dilated.mp4
  echo "Saved +${RAD}px dilated mask -> mask_dilated.mp4"
  exit 0
fi

if [ "${MODE}" = "--vace" ]; then
  PLATE_URL="${2:?Pass HTTPS plate_cfr24.mp4 URL}"
  MASK_URL="${3:?Pass HTTPS mask_dilated.mp4 URL}"
  BG_PROMPT="${4:?Describe ONLY the empty background behind the removed object}"
  SUBMIT=$(curl -sS -X POST "https://queue.fal.run/fal-ai/wan-vace-14b" \
    -H "Authorization: Key ${FAL_KEY:?Set FAL_KEY}" \
    -H "Content-Type: application/json" \
    -d "{
      \"video_url\": \"${PLATE_URL}\",
      \"mask_video_url\": \"${MASK_URL}\",
      \"prompt\": \"${BG_PROMPT}\",
      \"negative_prompt\": \"blur, ghost shadow, dark smudge, floating pole, distortion, artifacts\",
      \"resolution\": \"720p\",
      \"match_input_frames_per_second\": true,
      \"match_input_num_frames\": true,
      \"seed\": 2048
    }")
  REQ_ID=$(echo "${SUBMIT}" | jq -r '.request_id // empty')
  STATUS_URL=$(echo "${SUBMIT}" | jq -r '.status_url // empty')
  RESP_URL=$(echo "${SUBMIT}" | jq -r '.response_url // empty')
  if [ -z "${REQ_ID}" ]; then echo "VACE submit failed: ${SUBMIT}" >&2; exit 1; fi
  echo "Queued Wan VACE 14B request_id=${REQ_ID}..."
  while true; do
    POLL=$(curl -sS -H "Authorization: Key ${FAL_KEY}" "${STATUS_URL}")
    STATE=$(echo "${POLL}" | jq -r '.status // "UNKNOWN"')
    echo "[$(date +%H:%M:%S)] status=${STATE}"
    if [ "${STATE}" = "COMPLETED" ]; then break; fi
    if [ "${STATE}" = "FAILED" ] || [ "${STATE}" = "CANCELED" ]; then echo "${POLL}" >&2; exit 1; fi
    sleep 8
  done
  OUT_URL=$(curl -sS -H "Authorization: Key ${FAL_KEY}" "${RESP_URL}" | jq -r '.video.url // empty')
  curl -fsSL "${OUT_URL}" -o vace_clean_720p.mp4
  echo "Saved clean plate -> vace_clean_720p.mp4"
  exit 0
fi

if [ "${MODE}" = "--mux" ]; then
  VID="${2:?Pass vace video}"; AUD="${3:?Pass original_audio_48k.wav}"; OUT="${4:-final_clean_muxed.mp4}"
  ffmpeg -v warning -y -i "${VID}" -i "${AUD}" \
    -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac -b:a 192k -ar 48000 -shortest -movflags +faststart "${OUT}"
  echo "Saved audio-synced master -> ${OUT}"
  exit 0
fi

Helpful prompts & skills for this workflow

Frequently Asked Questions

Why shouldn't I write 'remove the boom mic' inside the Wan VACE prompt?
Diffusion text encoders attend strongly to object nouns even when preceded by 'remove' or 'no'. Naming the boom mic increases the odds of phantom poles re-appearing inside the mask—describe only the empty plaster wall, floor planks, or foliage that belongs behind it.
Can I run this entire pipeline offline at $0 for confidential unreleased footage?
Yes. Both Meta SAM 2 (SAM 2.1) and Alibaba Wan VACE 14B (Wan-AI/Wan2.1-VACE-14B) ship under the permissive Apache-2.0 license and execute completely offline inside local 24GB VRAM ComfyUI with zero external uploads.
How do I keep 4K camera sharpness when Wan VACE outputs 720p?
Upscale the approved 5-second Wan VACE output through Topaz Video Upscale API ($0.40), feather mask_dilated.mp4 slightly in DaVinci Resolve or After Effects, and composite only the patched pixels over your original 4K camera plate so 90%+ of the image remains 100% untouched camera footage.
Use this page in AI tools or notes
raw .md