---
name: sam2-kling-o1-v2v-fal
description: Automate Meta SAM 2 temporal video segmentation (fal-ai/sam2/video ~$0.01-$0.05/clip or Apache-2.0 local) with FFmpeg +12px shadow dilation, plus mask-free natural-language Kling O1 Video-to-Video Edit (fal-ai/kling-video/o1/video-to-video/edit at $0.168/sec with image_urls referencing and keep_audio: true) via queue.fal.run. Use when generating rotoscope masks for VFX/Wan VACE or executing talking-head wardrobe, prop, and environment swaps.
---
# Meta SAM 2 Video Masking & Kling O1 V2V Edit fal.ai Skill
## 1. Routing & Pre-Flight Cost Check (Always Print Estimate First)
- **Surgical Object / Logo / Boom-Mic Removal (0% background drift):**
1. Conform clip to constant frame rate (`-r 24 -fps_mode cfr`, NEVER removed `-vsync`).
2. Track via `queue.fal.run/fal-ai/sam2/video` (`~$0.01–$0.05` compute-metered, or `$0` Apache-2.0 local).
3. Dilate matte `+12px` via FFmpeg before handing off to `fal-ai/wan-vace-14b` (`$0.08/s`).
- **Mask-Free Wardrobe, Prop, or Set Swap (Talking-Head / UGC):**
- Queue `queue.fal.run/fal-ai/kling-video/o1/video-to-video/edit` (**`$0.168/sec`** = `$0.84` per 5s, `$1.68` per 10s).
- Always pass `"keep_audio": true` for dialogue clips and attach crisp `"image_urls"` referencing `@Image1` inside `prompt`.
- **Broadcast Relighting / ProRes / 10-bit Rec.709:** Escalate to Runway Aleph 2.0 (`$0.28/s` + `$0.05/s` ProRes).
## 2. Step A — Meta SAM 2 Temporal Mask (`queue.fal.run/fal-ai/sam2/video`)
Supply positive (`label: 1`) and optional negative (`label: 0`) pixel coordinates `(x, y)` on `frame_index: 0`:
```bash
curl -sS -X POST "https://queue.fal.run/fal-ai/sam2/video" \
-H "Authorization: Key $FAL_KEY" \
-H "Content-Type: application/json" \
-d '{
"video_url": "'"$PLATE_CFR_URL"'",
"prompts": [
{"x": 640, "y": 360, "label": 1, "frame_index": 0, "object_id": 1}
],
"apply_mask": false
}'
```
Poll `status_url` until `COMPLETED`, download the binary matte video, and run verified `+12px` dilation before any object-removal pass:
```bash
ffmpeg -v warning -y -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 -an mask_dilated.mp4
```
## 3. Step B — Kling O1 Mask-Free V2V Edit (`queue.fal.run/fal-ai/kling-video/o1/video-to-video/edit`)
```bash
curl -sS -X POST "https://queue.fal.run/fal-ai/kling-video/o1/video-to-video/edit" \
-H "Authorization: Key $FAL_KEY" \
-H "Content-Type: application/json" \
-d '{
"video_url": "'"$CLIP_CFR_URL"'",
"image_urls": ["'"$REF_IMAGE_URL"'"],
"prompt": "Replace the speaker'\''s hoodie in @Video1 with the tailored jacket in @Image1, matching fabric creases and soft daylight from frame left. Keep the speaker'\''s face, lip sync, hands, and camera framing completely unchanged.",
"keep_audio": true
}'
```
Poll `status_url` every 8s until `COMPLETED`, fetch `response_url`, download `.video.url`, and verify matched audio/video streams with `ffprobe -show_entries stream=codec_type,duration,r_frame_rate`.