---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://framesfield.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
title: "Fix AI Video Object Removal Ghost Smudges, Shadow Trails & Mask Bleed"
description: "Conform every source clip to constant 24fps CFR (-fps_mode cfr) before tracking, dilate your Meta SAM 2 binary mask video by +10 to +16 pixels in FFmpeg so cast shadows and motion-blur fringes sit inside the white matte, prompt strictly for the empty background texture (never mention the removed item), and composite the patch over the original 4K plate."
canonical: "https://framesfield.com/fixes/ai-video-object-removal-ghost-smudge-and-mask-bleed-fix"
---

# Fix AI Video Object Removal Ghost Smudges, Shadow Trails & Mask Bleed

> Conform every source clip to constant 24fps CFR (-fps_mode cfr) before tracking, dilate your Meta SAM 2 binary mask video by +10 to +16 pixels in FFmpeg so cast shadows and motion-blur fringes sit inside the white matte, prompt strictly for the empty background texture (never mention the removed item), and composite the patch over the original 4K plate.

- **Canonical URL:** https://framesfield.com/fixes/ai-video-object-removal-ghost-smudge-and-mask-bleed-fix
- **Category:** Visual & 3D Craft
- **Error Signature:** `Visual symptom: after Meta SAM 2 + Wan VACE 14B object removal, the boom mic or pedestrian vanishes but leaves a sliding dark shadow smudge, shimmering silhouette outline, or drifting matte sync`
- **Last Verified:** 2026-12-01

## Observed Symptom

You track an unwanted bystander, tripod, or logo with Meta SAM 2 and pass the resulting mask video straight into Alibaba Wan VACE 14B ($0.08/sec). The object disappears, yet a ghostly dark smudge slides along the pavement where its shadow used to be—or the removal patch lags two frames behind fast pans.

## Technical Root Cause

Two separate pipeline bugs create 90% of video inpainting artifacts: (1) Meta SAM 2 outputs a razor-tight binary mask hugging only the physical object boundary, leaving its cast contact shadow, ambient occlusion, and 2px motion-blur fringe outside the white mask so Wan VACE faithfully preserves the orphaned shadow; and (2) variable-frame-rate (VFR) phone footage drifts out of temporal alignment against mask_video_url.

## Under the Hood

When Wan VACE 14B runs masked video inpainting, every black pixel outside mask_video_url is treated as ground truth that the generator must match seamlessly. If a pedestrian’s dark cast shadow sits 10 pixels outside the white SAM 2 matte on the black side, Wan VACE is mathematically forced to blend newly generated sunlit asphalt right into that dark shadow edge—producing an unmistakable fuzzy ghost smudge moving across the empty sidewalk.

Smartphones (iPhone, Android) and screen recorders introduce a second silent killer: variable frame rate (VFR) timestamps. A clip reporting "29.94 fps" can swing from 22fps to 30fps between frames. When SAM 2 extracts frame indices sequentially and Wan VACE renders at a fixed integer cadence, the mask falls 1 to 4 frames behind camera movement mid-shot, causing hard silhouette edges to poke out from behind the inpaint patch.

Running a deterministic two-step FFmpeg pre-flight solves both errors in under three seconds: conform the raw clip to constant 24fps CFR yuv420p (-fps_mode cfr) before running SAM 2, then run an FFmpeg binary mask dilation pass (boxblur=12:1 + threshold lut + 2px edge feather) on the SAM 2 matte to expand the white region by +10 to +16 pixels in every direction before calling Wan VACE 14B.

## Before vs. After

### Broken (Broken Removal Pipeline (Raw VFR Phone Clip + Tight SAM 2 Mask + Wrong Prompt))

```
1. Upload raw VFR iPhone .mov straight to SAM 2 -> frame index drifts mid-pan
2. Pass raw tight SAM 2 matte directly to Wan VACE 14B (cast shadow stays in black region)
3. Prompt: "Remove the black boom microphone and tripod from the living room"
   # Naming the object in a positive prompt encourages the diffusion model to hallucinate mic shapes!
Result: Ghostly shadow floats across wall; matte lags 2 frames during pan.
```

### Verified Fix (Fixed Removal Pipeline (24fps CFR + FFmpeg +12px Mask Dilation + Clean-Plate Prompt))

```
1. Conform raw clip to 24fps CFR first:
   ffmpeg -i raw_phone.mov -r 24 -fps_mode cfr -pix_fmt yuv420p -c:v libx264 -crf 16 plate_cfr24.mp4
2. Track object on plate_cfr24.mp4 in Meta SAM 2 -> download sam2_mask.mp4
3. Dilate binary mask +11px radius (locally verified on FFmpeg 9.0.1) to swallow cast shadows:
   ffmpeg -i sam2_mask.mp4 -vf "format=gray,boxblur=12:1,lut=y='if(gt(val,18),255,0)',boxblur=2:1,format=yuv420p" -r 24 -fps_mode cfr -c:v libx264 -crf 18 mask_dilated.mp4
4. Wan VACE 14B prompt describes ONLY the revealed background:
   "Empty warm plaster living room wall with soft afternoon sunlight, clean hardwood floor, natural film grain, static architectural detail"
```

Constant-frame-rate locking eliminates matte drift, +11px to +16px dilation engulfs cast shadows and motion blur fringes, and describing the revealed background (instead of naming the deleted object) prevents phantom re-generation.

## Copy-Paste Fix (prep-cfr-and-dilate-sam2-mask.sh)

```bash
#!/usr/bin/env bash
set -euo pipefail
# Verified locally on FFmpeg 9.0.1 (uses -fps_mode cfr instead of removed -vsync)
# Step A: Run with --conform before SAM 2. Step B: Run with --dilate after SAM 2.

MODE="${1:?Use --conform <raw.mov> <plate_cfr24.mp4> OR --dilate <sam2_mask.mp4> <mask_dilated.mp4> [radius=12]}"
IN_FILE="${2:?Missing input file}"
OUT_FILE="${3:?Missing output file}"
RADIUS="${4:-12}" # 10-16 covers cast shadows & motion-blur fringe cleanly

if [ "${MODE}" = "--conform" ]; then
  ffmpeg -v warning -y -i "${IN_FILE}"     -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p"     -r 24 -fps_mode cfr -c:v libx264 -crf 16 -movflags +faststart     -c:a pcm_s16le -ar 48000 "${OUT_FILE%.mp4}.mov"
  ffmpeg -v warning -y -i "${OUT_FILE%.mp4}.mov"     -c:v copy -an -movflags +faststart "${OUT_FILE}"
  echo "Saved video-only CFR plate -> ${OUT_FILE} + PCM audio master -> ${OUT_FILE%.mp4}.mov"
elif [ "${MODE}" = "--dilate" ]; then
  ffmpeg -v warning -y -i "${IN_FILE}"     -vf "format=gray,boxblur=${RADIUS}: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 "${OUT_FILE}"
  echo "Saved +${RADIUS}px dilated matte -> ${OUT_FILE}"
else
  echo "Unknown mode: ${MODE}" >&2
  exit 1
fi
```

## Step-by-Step Resolution

1. **Conform raw source media to constant 24fps CFR first:** Transcode smartphone or screen recordings with -r 24 -fps_mode cfr and archive uncompressed 48 kHz WAV audio before generating any mask.
2. **Track the unwanted object in Meta SAM 2 (plus shadow points if long):** Drop positive point prompts on the object—and if a long dramatic sunset shadow stretches across the floor, drop an extra positive point directly onto the shadow itself.
3. **Dilate the binary matte +10 to +16 pixels in FFmpeg:** Run boxblur=12:1 + lut threshold + boxblur=2:1 so contact shadows and edge motion blur fall completely inside the white inpaint mask.
4. **Prompt Wan VACE 14B purely for the empty background:** Never write "remove the boom mic" in the positive prompt; describe the clean surface behind it ("clean beige plaster ceiling with even soft interior light") and list unwanted items in negative_prompt.

## Verification Check (Verify Exact Frame Count Parity & White Margin Expansion)

```bash
ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=width,height,r_frame_rate,avg_frame_rate,nb_read_packets -of default=nw=1 plate_cfr24.mp4
ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=width,height,r_frame_rate,avg_frame_rate,nb_read_packets -of default=nw=1 mask_dilated.mp4
```

**Expected healthy output:**

```text
Both files report identical width, height, r_frame_rate=24/1, avg_frame_rate=24/1, and identical nb_read_packets (exact 1:1 frame lock).
```

## Prevention Guardrails

1. **Never name the deleted object in the Wan VACE positive prompt:** Diffusion text encoders attend strongly to nouns even after the word "no" or "remove". Describe strictly what should occupy the empty space instead.
2. **Use Kling O1 V2V Edit ($0.168/s) when an entire moving reflection spans glass:** When a crew member reflects across complex curved glass windows that are tedious to mask, mask-free Kling O1 Edit or Runway Aleph 2.0 often cleans reflections cleaner in one pass.
3. **Preserve original 4K sharpness by compositing only inside the mask:** Overlay the Topaz-upscaled Wan VACE patch inside a feathered copy of mask_dilated.mp4 over your untouched 4K camera plate in DaVinci Resolve or After Effects.

## FAQs

### Why did ffmpeg fail with "Unrecognized option vsync" when conforming my clip?

Modern FFmpeg (7.x, 8.x, and 9.x on Homebrew) removed the deprecated -vsync flag in favor of -fps_mode cfr. Using -r 24 -fps_mode cfr works reliably across FFmpeg 5.1 through 9.x.

### How many pixels should I dilate a SAM 2 mask for Wan VACE 14B?

On 720p plates, a radius of 10–14 pixels covers standard edge blur and tight contact shadows cleanly without chewing into adjacent actors. Increase to 16–24 pixels only if the unwanted object casts a wide dark shadow on an open floor or wall.

### What if the unwanted object passes briefly behind a foreground actor?

Add a negative point prompt (label: 0) on the foreground actor inside Meta SAM 2 on the frame where overlap begins so SAM 2 carves the actor out of the white mask—protecting the actor completely during Wan VACE inpainting.
