Skill Tracer
Skills › HyperFrames › media-use › remove-background.md

remove-background.md

143 lines · skills/media-use/audio/references/remove-background.md at a595755

Open on GitHub
1# Background Removal
2
3Make a transparent overlay (typical: a talking head over an arbitrary scene). Uses `u2net_human_seg` (Apache-2.0).
4
5```bash
6npx hyperframes remove-background subject.mp4 -o transparent.webm # default: VP9 + alpha
7npx hyperframes remove-background subject.mp4 -o transparent.mov # ProRes 4444 (editing)
8npx hyperframes remove-background portrait.jpg -o cutout.png # single-image cutout
9npx hyperframes remove-background subject.mp4 -o subject.webm \
10 --background-output plate.webm # both layers, one pass
11npx hyperframes remove-background subject.mp4 -o transparent.webm --device cpu
12npx hyperframes remove-background --info # detected providers
13```

Background Removal

Make a transparent overlay (typical: a talking head over an arbitrary scene). Uses u2net_human_seg (Apache-2.0).

npx hyperframes remove-background subject.mp4 -o transparent.webm          # default: VP9 + alpha
npx hyperframes remove-background subject.mp4 -o transparent.mov           # ProRes 4444 (editing)
npx hyperframes remove-background portrait.jpg -o cutout.png               # single-image cutout
npx hyperframes remove-background subject.mp4 -o subject.webm \
  --background-output plate.webm                                           # both layers, one pass
npx hyperframes remove-background subject.mp4 -o transparent.webm --device cpu
npx hyperframes remove-background --info                                   # detected providers
Raw lines 1 to 14
15## Output Format
17- **`.webm` (VP9 alpha)** — default. Plug straight into `<video>` for Chrome-native transparent playback (~1 MB / 4s @ 1080p).
18- **`.mov` (ProRes 4444)** — round-trip in editors (Premiere / Resolve / DaVinci). ~50 MB / 4s.
19- **`.png`** — single-image cutout.

Output Format

  • **.webm (VP9 alpha)** — default. Plug straight into <video> for Chrome-native transparent playback (~1 MB / 4s @ 1080p).
  • **.mov (ProRes 4444)** — round-trip in editors (Premiere / Resolve / DaVinci). ~50 MB / 4s.
  • **.png** — single-image cutout.
Raw lines 15 to 20
21## Quality (`--quality`)
23Controls VP9 encoder CRF only — segmentation quality is fixed. Higher quality keeps the cutout's RGB closer to the source MP4 (important when overlaying the cutout on its own source).
25| Preset | CRF | When |
26| ---------- | --- | --------------------------------------------- |
27| `fast` | 30 | Iterating, smaller files, looser color match |
28| `balanced` | 18 | **Default**; visually identical for most uses |
29| `best` | 12 | Master / final delivery, tightest color match |

Quality (--quality)

Controls VP9 encoder CRF only — segmentation quality is fixed. Higher quality keeps the cutout's RGB closer to the source MP4 (important when overlaying the cutout on its own source).

PresetCRFWhen
fast30Iterating, smaller files, looser color match
balanced18Default; visually identical for most uses
best12Master / final delivery, tightest color match
Raw lines 21 to 30
31## Device (`--device`)
33`auto` (default) picks CoreML on Apple Silicon, CUDA when available, otherwise CPU. Force with `--device cpu | coreml | cuda`. CUDA requires `HYPERFRAMES_CUDA=1` plus a GPU-enabled `onnxruntime-node` build. Use `--info` to inspect detected providers without rendering.

Device (--device)

auto (default) picks CoreML on Apple Silicon, CUDA when available, otherwise CPU. Force with --device cpu | coreml | cuda. CUDA requires HYPERFRAMES_CUDA=1 plus a GPU-enabled onnxruntime-node build. Use --info to inspect detected providers without rendering.

Raw lines 31 to 34
35## Compositing patterns — pick the right one
37The cutout WebM is a **re-encoded copy** of the source MP4's RGB. What sits behind it matters.
39| Pattern | Behind the cutout | Result |
40| -------------------------------------------------------- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
41| **Cutout over a different scene** (most common) | Static image, gradient, unrelated video | Looks great. Single RGB source for the subject. |
42| **Cutout over its own source mp4** (text-behind-subject) | Same mp4 the cutout came from | At `balanced` doubling is barely visible; at `fast` you'll see color shift / edge halo. Use `best` for masters. |
43| **Cutout over a different take of the same person** | Footage of the same subject | **Two overlapping people. Don't do this.** |

Compositing patterns — pick the right one

The cutout WebM is a re-encoded copy of the source MP4's RGB. What sits behind it matters.

PatternBehind the cutoutResult
Cutout over a different scene (most common)Static image, gradient, unrelated videoLooks great. Single RGB source for the subject.
Cutout over its own source mp4 (text-behind-subject)Same mp4 the cutout came fromAt balanced doubling is barely visible; at fast you'll see color shift / edge halo. Use best for masters.
Cutout over a different take of the same personFootage of the same subjectTwo overlapping people. Don't do this.
Raw lines 35 to 44
45## Text-behind-subject pattern (two non-obvious rules)
47Putting a headline behind a presenter cutout:
49```html
50<video
51 src="presenter.mp4"
52 id="bg"
53 data-start="0"
54 data-duration="6"
55 data-track-index="0"
56 muted
57 playsinline
58></video>
60<h1 id="headline" style="z-index:2; ...">MAKE IT IN HYPERFRAMES</h1>
62<div class="cutout-wrap" style="position:absolute; inset:0; z-index:3; opacity:0">
63 <video
64 src="presenter.webm"
65 data-start="0"
66 data-duration="6"
67 data-track-index="1"
68 muted
69 playsinline
70 ></video>
71</div>
72```
74```js
75// Flip the wrapper's opacity at the cut, NOT the video's
76tl.set(".cutout-wrap", { opacity: 1 }, 3.3);
77```
79Two rules that are easy to miss:
811. **Wrap the cutout `<video>` in a non-timed `<div>` and animate the wrapper's opacity, not the video element's.** The framework forces `opacity: 1` on active clips (any element with `data-start` / `data-duration`), so animating the video's opacity directly is silently overridden. The wrapper has no `data-*` attributes, so it's owned by your CSS / GSAP.
822. **Both videos use `data-start="0"` and `data-media-start="0"`** so the framework decodes them in sync from t=0. Late-mounting the cutout (`data-start=3.3`) introduces a seek + warm-up that lands a frame off the base mp4 — visible as one frame of misalignment at the cut.

Text-behind-subject pattern (two non-obvious rules)

Putting a headline behind a presenter cutout:

<video
  src="presenter.mp4"
  id="bg"
  data-start="0"
  data-duration="6"
  data-track-index="0"
  muted
  playsinline
></video>

<h1 id="headline" style="z-index:2; ...">MAKE IT IN HYPERFRAMES</h1>

<div class="cutout-wrap" style="position:absolute; inset:0; z-index:3; opacity:0">
  <video
    src="presenter.webm"
    data-start="0"
    data-duration="6"
    data-track-index="1"
    muted
    playsinline
  ></video>
</div>
// Flip the wrapper's opacity at the cut, NOT the video's
tl.set(".cutout-wrap", { opacity: 1 }, 3.3);

Two rules that are easy to miss:

  1. **Wrap the cutout <video> in a non-timed <div> and animate the wrapper's opacity, not the video element's.** The framework forces opacity: 1 on active clips (any element with data-start / data-duration), so animating the video's opacity directly is silently overridden. The wrapper has no data-* attributes, so it's owned by your CSS / GSAP.
  2. **Both videos use data-start="0" and data-media-start="0"** so the framework decodes them in sync from t=0. Late-mounting the cutout (data-start=3.3) introduces a seek + warm-up that lands a frame off the base mp4 — visible as one frame of misalignment at the cut.
Raw lines 45 to 83
84## Layer separation (`--background-output`)
86Emits a **second** transparent video alongside the cutout: same source RGB, alpha is `255 - mask` instead of `mask`. The cutout has the subject opaque; the plate has the surroundings opaque (with a transparent hole where the subject was). Use it when text / graphics need to live **between** the two layers.
88| File | Alpha is… | Use it for |
89| -------------------------------- | ------------------------------------------------------- | ---------------------------------------------------------------- |
90| `-o subject.webm` | mask — subject opaque, background transparent | Foreground layer (top) |
91| `--background-output plate.webm` | inverse mask — surroundings opaque, subject transparent | Bottom layer; place text / graphics between this and the subject |
93Both share the same `--quality` and run from a single inference pass — only encode cost roughly doubles. Only valid for video inputs with `.webm` / `.mov` outputs.
95**Hole-cut, not inpainted.** The subject region in `plate.webm` is fully transparent — composite something opaque under it to fill the hole.
97**Single test for whether `--background-output` is the right tool:** _will anything ever be visible through the subject's silhouette where the subject used to be?_ If no, you don't need the plate — `subject.webm` alone over a different background is enough.

Layer separation (--background-output)

Emits a second transparent video alongside the cutout: same source RGB, alpha is 255 - mask instead of mask. The cutout has the subject opaque; the plate has the surroundings opaque (with a transparent hole where the subject was). Use it when text / graphics need to live between the two layers.

FileAlpha is…Use it for
-o subject.webmmask — subject opaque, background transparentForeground layer (top)
--background-output plate.webminverse mask — surroundings opaque, subject transparentBottom layer; place text / graphics between this and the subject

Both share the same --quality and run from a single inference pass — only encode cost roughly doubles. Only valid for video inputs with .webm / .mov outputs.

Hole-cut, not inpainted. The subject region in plate.webm is fully transparent — composite something opaque under it to fill the hole.

**Single test for whether --background-output is the right tool:** will anything ever be visible through the subject's silhouette where the subject used to be? If no, you don't need the plate — subject.webm alone over a different background is enough.

Raw lines 84 to 98
99### Use case → right tool
101| Use case | Right tool |
102| ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
103| Text/graphics between the cutout and the plate (this command's reason for existing) | **Hole-cut** (`--background-output`) |
104| Subject onto an unrelated scene | Just `subject.webm`; ignore the plate |
105| Show the room _without_ the person, alone over no other content | **Clean plate** — needs an inpainter (LaMa, ProPainter, E2FGVI). Not this command. |
106| Replace the subject with a different subject | **Clean plate** — same as above |

Use case → right tool

Use caseRight tool
Text/graphics between the cutout and the plate (this command's reason for existing)Hole-cut (--background-output)
Subject onto an unrelated sceneJust subject.webm; ignore the plate
Show the room without the person, alone over no other contentClean plate — needs an inpainter (LaMa, ProPainter, E2FGVI). Not this command.
Replace the subject with a different subjectClean plate — same as above
Raw lines 99 to 107
108### Canonical 3-layer template (plate + content + cutout)
110Ship just the two transparent layers and let arbitrary content live between them — no original mp4 needed:
112```html
113<!-- z=1 plate: surroundings opaque, subject silhouette transparent -->
114<video
115 src="plate.webm"
116 data-start="0"
117 data-duration="6"
118 data-track-index="0"
119 muted
120 playsinline
121></video>
123<!-- z=2 your content lives between the layers -->
124<h1 id="headline" style="z-index:2; ...">MAKE IT IN HYPERFRAMES</h1>
126<!-- z=3 cutout floats the subject back on top -->
127<div class="cutout-wrap" style="position:absolute; inset:0; z-index:3">
128 <video
129 src="subject.webm"
130 data-start="0"
131 data-duration="6"
132 data-track-index="1"
133 muted
134 playsinline
135 ></video>
136</div>
137```
139Functionally equivalent to the text-behind-subject pattern above, but doesn't require shipping the original mp4 — the plate replaces it. Use this when delivering just the two transparent layers as a reusable asset.

Canonical 3-layer template (plate + content + cutout)

Ship just the two transparent layers and let arbitrary content live between them — no original mp4 needed:

<!-- z=1 plate: surroundings opaque, subject silhouette transparent -->
<video
  src="plate.webm"
  data-start="0"
  data-duration="6"
  data-track-index="0"
  muted
  playsinline
></video>

<!-- z=2 your content lives between the layers -->
<h1 id="headline" style="z-index:2; ...">MAKE IT IN HYPERFRAMES</h1>

<!-- z=3 cutout floats the subject back on top -->
<div class="cutout-wrap" style="position:absolute; inset:0; z-index:3">
  <video
    src="subject.webm"
    data-start="0"
    data-duration="6"
    data-track-index="1"
    muted
    playsinline
  ></video>
</div>

Functionally equivalent to the text-behind-subject pattern above, but doesn't require shipping the original mp4 — the plate replaces it. Use this when delivering just the two transparent layers as a reusable asset.

Raw lines 108 to 140
141## When `remove-background` is NOT the right tool
143If a user asks for "the room **without** the person, displayed standalone" (no subject anywhere, no compositing on top), `--background-output` is wrong — its plate has a transparent hole, not a filled-in clean plate. They need an **inpainter**: LaMa, ProPainter, or E2FGVI. Tell them this command can't do it.

When remove-background is NOT the right tool

If a user asks for "the room without the person, displayed standalone" (no subject anywhere, no compositing on top), --background-output is wrong — its plate has a transparent hole, not a filled-in clean plate. They need an inpainter: LaMa, ProPainter, or E2FGVI. Tell them this command can't do it.

Raw lines 141 to 143