Skip to content
FramesField
SKILL.md Beginner Setup (1 Command) SKILL.md
Verified Dec 1, 2026

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

How to install this SKILL.md

Drop into .claude/skills/, .cursor/skills/, or .agents/skills/ to automate point-prompted video rotoscoping, dilated mask generation, and audio-preserving wardrobe/prop/set swaps from your coding agent.

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.

Compatible agent hosts
Claude Code Cursor Codex
Target tool: fal.ai Queue API / Meta SAM 2 / Kling O1 V2V Edit / FFmpeg · License: MIT
  1. STEP 01
    Install pure SKILL.md from /raw/skills/

    Copy the Claude Code, Cursor, or Codex installer below targeting /raw/skills/ directly.

  2. STEP 02
    Pick SAM 2 masked lane vs. Kling O1 mask-free lane

    Agent routes surgical removal to SAM 2 (~$0.02) + Wan VACE ($0.08/s) and talking-head wardrobe/set swaps to Kling O1 ($0.168/s, keep_audio: true).

  3. STEP 03
    Enforce CFR conform, queue.fal.run & ffprobe verification

    Conforms phone VFR via -fps_mode cfr, polls asynchronously, and verifies synced audio/video duration automatically.

1. Install for your tool

Pick the app you use below for the exact verified command or config—zero manual guessing.

Direct raw file (SKILL.md) ↓
Claude Code bash
Installs pure SKILL.md bytes directly into Claude Code:
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

2. Inspect or download the full SKILL.md file

This is the exact raw file served at /raw/skills/sam2-video-masking-and-kling-o1-v2v-fal-skill.

Meta SAM 2 Video Masking & Kling O1 V2V fal.ai Skill SKILL.md
---
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`.

3. Test it right away (sample prompt & result)

Sample prompt / input
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.
What happens when it runs
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).

What you need & known limits

Requirements

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

Watch out for

  • 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

Frequently Asked Questions

How do I find exact (x, y) pixel coordinates for Meta SAM 2 point prompts?
Extract frame 0 with ffmpeg -i plate_cfr24.mp4 -frames:v 1 frame0.png, inspect the target pixel coordinates in Preview/Photoshop or via a quick Python script, and pass label: 1 for target points plus label: 0 for foreground actors you want excluded.
Does Kling O1 V2V Edit strip audio if I forget keep_audio?
Explicitly passing keep_audio: true guarantees the original spoken dialogue track carries straight through the edited output cleanly—always confirm audio stream presence afterward with ffprobe.
Use this page in AI tools or notes
raw .md