跳到正文
DEV Community· lyric li·· 34 分鐘前AI 評分56

Claude 影片特效技能如何改善人臉追蹤與頭髮遮罩

How to Improve Face Tracking and Hair Masks in Claude Video Effects Skills

AI 導讀

作者分析 Claude 影片特效技能在 talking-head 影片中出現人臉追蹤及頭髮遮罩問題的原因,並提出分開處理追蹤與髮絲遮罩的改良方向。文章指出,遮罩在 0.5 附近經對比拉伸而硬化,且只與前一影格混合,可能令半透明髮絲消失或在轉頭時拖影。建議保留柔和 alpha、平滑遮罩邊緣而非頭部動作,並先檢查效果中段的靜態影格;分析影格短邊約 540 像素,提高分割解像度則會增加耗時。

正文

If a Claude video effects skill cuts you out of a talking-head clip, and your face or hair looks wrong the moment you turn your head, the mask is usually the problem, not the typography. Most of these skills use a general person segmenter plus a simple face box. That is enough to put a title behind you when you are still, and a weak hair matte once you move. Keep soft alpha in the hair, track the head without letting the mask lag, and stop treating face tracking and background removal as one operation.

How Claude video effects skills actually cut you out

Claude Motion and most claude motion graphics are code-drawn animations, with nobody on camera. The Instagram-style skill packs do a different job: you drop in a talking-head video, Claude Code runs an effect such as /effects backdrop-word, and the renderer tries to sit graphics behind your head.

In the public source for Vibha Ramprakash's popular /effects skill (51 starter effects, credits in the README), that cut-out is built like this:

  1. Your clip is the input, not a text prompt.
  2. A first pass looks at the frames inside each effect window.
  3. MediaPipe Selfie Segmenter produces a person confidence mask, in video mode.
  4. A guided filter refines that mask against the grayscale frame.
  5. OpenCV YuNet detects a face box. If detection misses, the skill falls back to the top of the person mask.
  6. A second pass composites the effect. Layers marked to sit behind you are hidden wherever the person mask is opaque. The original audio is kept, and the output is an MP4, 1080p by default.

HyperFrames-based packs do the same job with npx hyperframes remove-background subject.mp4 -o subject.webm, plus --background-output plate.webm if you want type behind the person. Claude is driving this pipeline; it is not generating the footage.

Why the mask looks worse when you move

Three details in that public /effects tracker explain the usual failure, especially around hair.

First, Selfie Segmenter is a person segmenter, not a hair-aware matte. Fine strands against a busy background are already at the edge of what this class of model keeps. HyperFrames' own guide says the same about its local model: expect trouble with fine hair and fast motion, and the softer hair edges are often the model's limit on that source.

Second, after the guided filter, the skill hardens the mask with a contrast stretch around 0.5. That helps a clean silhouette, but it pushes semi-transparent hair toward fully foreground or fully background. The edge can look wig-like, or a chunk of hair can appear and disappear when you turn.

Third, the mask is only blended one way with the previous frame. Face boxes later get a bidirectional smooth so the box does not lag; the matte does not. A one-way blend can smear on a quick turn, and the previous mask is cleared outside an effect window, so the first frame of a new effect can jump.

YuNet also gives a box, not a head pose. When you turn, the visible face shape changes, and a guard drawn around the box center will not match. The analysis runs on a downscaled frame (around 540 pixels on the short side) and is then scaled up, which throws away the pixels you need for hair.

Fix the source before you rewrite the skill

A better matte still needs a clip the model can read.

  • Use a plain background that contrasts with your hair, not a busy wall or a similar color.
  • Keep the framing steady, leave space around your head, and prefer the vertical phone video this skill is built for.
  • Light the face and the hair edge. Backlight helps strands read as hair instead of noise.
  • Slow the head motion in the takes you care about. Fast turns are a documented failure case for these local cut-out models.
  • Watch dark objects you hold: a mic or phone can be swallowed by a people-only model. HyperFrames documents this limit.
  • Use the skill's check-frame pass before you encode. It writes a plan, renders stills at the middle of each effect, then encodes. If a still already shows a hole in your hair, the render will too.

Separate tracking from the hair matte

Once the source is cleaner, change the mask logic. The following is illustrative, based on the public skill source. It is not a patch I have run, and it is not an online implementation.

Keep the guided filter, which already aligns the matte with image edges. What usually hurts hair is the hardening after it. Leave soft alpha around 0.5 instead of stretching every pixel to 0 or 1:

# Illustrative only. m is the confidence mask after the guided filter.
m = np.clip(m, 0, 1)
# Keep a soft band for hair; do not apply a contrast stretch around 0.5.
hair_band = (m > 0.2) & (m < 0.8)

For flicker, smooth the boundary jitter, not the head motion. The skill already applies a no-lag, bidirectional smooth to the face box. A similar idea can go on the matte edge, so the silhouette can still follow a quick turn. Do not clear the previous mask just because you left an effect window for a few frames.

If you only need the official HyperFrames cut-out, try --quality best when the cut-out goes back over its own footage (this reduces a color halo), and a cleaner source or a stronger external matte when edges flicker. The plate from --background-output is a person-shaped hole, not an inpainted background. Stack something opaque under it.

Do not reshape the hair matte from the YuNet box center alone. If you change tracking, add landmarks or a head-pose estimate to the already-smoothed box. And if you can afford the time, run the segmenter closer to output resolution. A 540-pixel matte cannot invent strands that were never in the analysis frame.

A prompt you can paste into Claude Code

If you are working with the /effects skill on your machine, you can ask Claude Code to adjust the tracker rather than rebuilding the pipeline. Adapt this:

The cut-out in this Claude video effects skill looks uneven on my hair when I turn my head.

Please inspect scripts/fx.py (the Tracker, the guided filter, and the mask hardening).
Do not treat this as a one-click production patch. Propose a small, reversible change that:

1. Keeps the MediaPipe Selfie Segmenter and the guided filter.
2. Stops hardening the mask with a strong contrast stretch around 0.5, so hair can keep soft alpha.
3. Smooths mask-edge flicker without making the matte lag behind a quick head turn. Reuse the idea behind the existing bidirectional face-box smooth.
4. Does not clear the previous mask between nearby effect windows.
5. Optionally runs the segmenter closer to the output resolution, and says what that will cost in time.
6. Leaves YuNet in place for the face box, but does not use the box center alone to reshape the hair matte.

Show me the diff first. Then render check-frame stills, not the full MP4, so I can inspect the hair edge.

Watch the stills before you post. The skill's own README calls these starter versions, and asks you to approve the draft.

When you do not need a talking-head cut-out

If the clip you want is type, charts, or a product interface, and nobody has to be filmed, this masking problem does not apply. That is the other branch of claude motion graphics: Claude writes animation code, and a renderer makes the MP4. Anthropic's official Claude Motion feature works that way, on Team and Enterprise plans, and it does not generate footage of real people.

I maintain Opus 5.5 Video, a browser-based Claude Motion alternative for that no-install path. It is an independent site, not affiliated with Anthropic, and it will not fix a talking-head mask: it does not accept a video upload or cut people out of footage. Use it only for a prompt-to-1080p motion-graphics MP4, at 15, 30, or 60 seconds. For a filmed speaker with graphics behind their head, stay on the skill-and-matte path above.

A short checklist

  • Confirm you are on the talking-head branch, not a code-only claude animation.
  • Relight and recrop the source before you blame the model.
  • Inspect check-frame stills, especially during a head turn, before you encode.
  • Keep soft hair alpha; do not harden the whole person into a sticker.
  • Stabilize edge flicker, not the actual motion of the head.
  • Treat YuNet as a box, not as a pose.
  • If you use HyperFrames, try --quality best for a halo, and a stronger matte only after the source is clean.
  • If you do not need a person in the frame, skip background removal entirely.

來源:DEV Community · dev.to