---
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: "Meta SAM 2 Video Masking & Kling O1 V2V fal.ai Skill"
description: "Executable SKILL.md playbook teaching Claude Code, Cursor, and Codex to run Meta SAM 2 temporal video masking (fal-ai/sam2/video ~$0.02/clip or Apache-2.0 local) with verified FFmpeg +12px shadow dilation AND mask-free Kling O1 Video-to-Video Edit (fal-ai/kling-video/o1/video-to-video/edit at $0.168/s with @Image1 anchoring and keep_audio: true) via async queue.fal.run."
canonical: "https://framesfield.com/skills/sam2-video-masking-and-kling-o1-v2v-fal-skill"
---

# Meta SAM 2 Video Masking & Kling O1 V2V fal.ai Skill

> Executable SKILL.md playbook teaching Claude Code, Cursor, and Codex to run Meta SAM 2 temporal video masking (fal-ai/sam2/video ~$0.02/clip or Apache-2.0 local) with verified FFmpeg +12px shadow dilation AND mask-free Kling O1 Video-to-Video Edit (fal-ai/kling-video/o1/video-to-video/edit at $0.168/s with @Image1 anchoring and keep_audio: true) via async queue.fal.run.

- **Canonical URL:** https://framesfield.com/skills/sam2-video-masking-and-kling-o1-v2v-fal-skill
- **Raw Payload URL:** https://framesfield.com/raw/skills/sam2-video-masking-and-kling-o1-v2v-fal-skill
- **Asset Type:** SKILL.md
- **Compatible Hosts:** Claude Code, Cursor, Codex
- **Target Creative Tool:** fal.ai Queue API / Meta SAM 2 / Kling O1 V2V Edit / FFmpeg
- **License:** MIT
- **Last Verified:** 2026-12-01

## Setup & Install

```bash
mkdir -p .claude/skills/sam2-kling-o1-v2v-fal && curl -fsSL https://framesfield.com/raw/skills/sam2-video-masking-and-kling-o1-v2v-fal-skill -o .claude/skills/sam2-kling-o1-v2v-fal/SKILL.md

```

## Copyable Asset (SKILL.md)

````markdown
---
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`.
````

## Example Input

```text
Swap the presenter's grey t-shirt in our 6-second CFR clip with the navy blazer at https://cdn.example.com/blazer.png via Kling O1 keeping her original speech synced, and verify audio duration with ffprobe.
```

## Expected Output

```text
Pre-flight estimate: 6s × $0.168/sec = $1.01 (fal-ai/kling-video/o1/video-to-video/edit, keep_audio=true).
1) Submitted async to queue.fal.run with @Video1 + @Image1 preservation contract -> COMPLETED in 94s.
2) Downloaded kling_o1_blazer.mp4.
3) ffprobe verified video=6.000s (24/1 CFR) and audio=6.000s (aac 48kHz synced).
```

## Requirements

- FAL_KEY exported in environment, plus curl, jq, and FFmpeg 5.1–9.x / ffprobe
- Claude Code, Cursor, or Codex agent workspace

## Known Limits

- Meta SAM 2 outputs hard binary masks (not continuous wispy hair alpha)—use Bria RMBG 2.0 or BiRefNet v2 for soft still portrait alpha
- Kling O1 outputs HD MP4s—escalate to Runway Aleph 2.0 ($0.28/s) when 10-bit Rec.709 or ProRes 422 is mandatory

## Implementation Notes

## Automate video rotoscoping & mask-free V2V edits under one `FAL_KEY`

Drop this skill into Claude Code, Cursor, or Codex to give your coding agent exact async `queue.fal.run` schemas for [Meta SAM 2](/specs/sam2-video) temporal video segmentation (`~$0.02/clip` or `$0` Apache-2.0 local) and [Kling O1 Video-to-Video Edit](/specs/kling-o1-v2v-edit) (`$0.168/s` with `keep_audio: true` and `@Image1` product/wardrobe anchoring).

See [Workflow 53: Kling O1 Mask-Free Subject Swap Pipeline](/workflows/kling-o1-natural-language-v2v-subject-swap-pipeline) or browse all verified endpoints on our [fal.ai Skills Directory](/skills/for/fal-ai).
