Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
docs(prompting): add colour grading and film effects chapter
Vance Ingalls819ed632d922
diff --git a/docs/docs.json b/docs/docs.jsonindex 8bb5f0e6dc..8a299ff2d4 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -111,6 +111,7 @@"prompting/overlays-and-lower-thirds","prompting/captions-catalog","prompting/generated-artwork",+ "prompting/color-grading","prompting/vfx-and-liquid-glass","prompting/runtimes-and-3d"]diff --git a/docs/guides/color-grading.mdx b/docs/guides/color-grading.mdxindex d59a4617ee..8d40cf0d15 100644--- a/docs/guides/color-grading.mdx+++ b/docs/guides/color-grading.mdx@@ -123,7 +123,9 @@ skin from a broad creative grade.HyperFrames supports up to four ordered selections. These are staticmedia-level qualifiers: they do not include object tracking, rotoscoping,-facial recognition, or spatial masks.+facial recognition, or spatial masks. To confine a grade to a region of the+frame rather than a range of colors, see+[Limiting a Grade to Part of the Frame](#limiting-a-grade-to-part-of-the-frame).### Scopes@@ -237,6 +239,167 @@ npx hyperframes media-treatment --all --jsonUse `--all` only for exhaustive tooling or contract inspection.+## Animating a Grade++Nine grading properties are exposed as CSS custom properties and can be tweened+directly:++```text+--hf-color-grading-ascii --hf-color-grading-bloom --hf-color-grading-blur+--hf-color-grading-dither --hf-color-grading-exposure --hf-color-grading-intensity+--hf-color-grading-kuwahara --hf-color-grading-lut --hf-color-grading-pixelate+```++```js+tl.to("#plate", { "--hf-color-grading-pixelate": 0.5, duration: 3, ease: "power2.inOut" }, 0.3);+```++Start the value at identity in the payload and in an inline `style`, so frame 0+is the ungraded reference and every intermediate value is rendered rather than+just the endpoints.++Two things this list does **not** give you:++- **`--hf-color-grading-intensity` does not scale a grade at render time.**+ Setting it to `0.5` renders the same as `0`, and animating `0 → 1` produces no+ change. Do not reach for it as a generic "ramp the whole look" dial.+- **Every other property — `halftone`, `twoInkPrint`, `tapeDamage`, hue curves,+ secondaries — has no custom property**, so it cannot be tweened this way.++For some of those, you can drive the payload itself from the timeline.+Rewriting `data-color-grading` re-applies the grade:++```js+const plate = document.getElementById("plate");+const v = { halftone: 0, bloom: 0 };++tl.to(v, {+ halftone: 0.72,+ bloom: 0.7,+ duration: 3.4,+ ease: "power2.inOut",+ onUpdate: () => {+ plate.setAttribute("data-color-grading", JSON.stringify({+ intensity: 1,+ effects: {+ halftone: v.halftone, halftoneSize: 0.38,+ bloom: v.bloom, bloomRadius: 18,+ },+ }));+ },+}, 0.3);+```++This stays deterministic: the value is derived from timeline position, never+from wall-clock time, so seeking to a frame always produces the same result.+It costs a payload parse per tick, so prefer a custom property when one exists.++<Warning>+ **This does not work for every effect.** It is verified working for `halftone`+ and `twoInkPrint`. It is verified *not* working for `crtCurvature`,+ `scanlines`, `chromaBleed`, and `chromaticAberration` — the identical payload+ applied statically renders correctly, but the same values driven through+ `setAttribute` produce no visible change, and seeding them non-zero at init+ does not help. Measure the effect you intend to animate before committing to+ it, and fall back to a static treatment if the ramp does not move.+</Warning>++## Limiting a Grade to Part of the Frame++Grading qualifies pixels **by value, never by position**. Selections key on hue,+saturation, and luma; the one spatially-varying control, `vignette`, is locked+to the frame centre and cannot be moved or reshaped into a power window. There+are no masks, shapes, or tracked regions in the contract.++A grade also applies to a whole media element. So to treat part of the frame,+split that part into its own layer and grade the layer:++| You want | Build |+| --- | --- |+| Subject graded, background clean | Matted cutout on top, graded; original clip underneath, clean |+| Background graded, subject clean | Original clip underneath, graded; matted cutout on top, clean |+| One region of the subject graded | Two copies of the cutout — clean underneath, graded copy on top clipped to the region |++Two rules that are easy to get wrong:++- **Use the original clip as the background plate, not a subject-removed+ plate.** A subject-removed plate is a hole where the subject was, and a+ feathered cutout composited over it produces a dark rim.+- **If your cutout ships premultiplied alpha**, the browser composites it as+ straight and edge pixels get multiplied twice, giving a black outline. Rebuild+ it from the original plus its matte:+ `ffmpeg -i clip.mp4 -i matte.mp4 -filter_complex "[1:v]format=gray[m];[0:v][m]alphamerge" -c:v libvpx-vp9 out.webm`++### Worked Example: Redacting a Face++Only the face is pixelated. The rest of the subject and the entire room are+untouched. Three layers, and the region comes from `clip-path` on the third:++```html index.html+<div class="band">+ <!-- 1. the room, clean -->+ <video src="media/room.mp4" muted+ data-start="0" data-duration="4" data-track-index="2"></video>++ <!-- 2. the subject, clean -->+ <video src="media/subject.webm" muted class="fg"+ data-start="0" data-duration="4" data-track-index="3"></video>++ <!-- 3. the same subject, graded, clipped to the head -->+ <video src="media/subject.webm" muted class="fx"+ data-start="0" data-duration="4" data-track-index="4"+ style="clip-path: ellipse(9.8% 15.5% at 50.7% 14.5%)"+ data-color-grading='{"intensity":1,"effects":{"pixelate":0.5}}'></video>+</div>+```++```css+.band .fg { z-index: 2; }+.band .fx { z-index: 3; }+```++Everything outside the clip falls through to the clean copy beneath. Because the+graded layer *is* the cutout, the ellipse can overshoot the head without+touching the room — there is nothing outside the silhouette to paint — so size+it generously rather than tightly around the features.++Pixelate preserves alpha, so the block grid clips to the silhouette instead of+filling a rectangle.++<Warning>+ A fixed `clip-path` is only valid for footage where the subject barely moves.+ Measure before relying on it. Anything with real subject movement needs a+ tracked matte produced outside HyperFrames — there is no tracking in the+ grading pipeline.+</Warning>++The prompt that produces the composition above:++```text+Take room.mp4 and its matted cutout subject.webm and build a 4-second+1920x1080 composition that redacts only the subject's face.++Three stacked layers inside one band, all playing the same 4 seconds:+ 1. room.mp4, no grading at all+ 2. subject.webm, no grading at all+ 3. subject.webm again, on top, carrying the grade++Layer 3 is the only graded element: pixelate at 0.5, held constant for the+whole shot — no ramp and no fade-up. A redaction that animates on reads as an+effect; one that is simply on reads as policy. Mid strength should leave a+recognisable human shape without a readable face.++Limit layer 3 to the head with a CSS clip-path ellipse. Do not try to do this+with the grading payload — it has no spatial masking. Size the ellipse+generously so it takes in the hairline, ears, and jaw rather than sitting tight+on the features; it can overshoot the head safely, because outside the+silhouette the cutout is transparent and there is nothing to paint.++Use the original room clip as the background plate rather than a+subject-removed plate, and if the cutout has premultiplied alpha, rebuild it+with ffmpeg alphamerge first so the edges do not come out with a black rim.+```+## Custom LUTsHyperFrames supports project-local 3D `.cube` LUTs:@@ -275,7 +438,7 @@ validation, and rendered comparisons to evaluate it.| HDR delivery render | Separate workflow | The native HDR compositor preserves HDR source pixels and does not apply this SDR grading/effects pipeline to native HDR layers || LOG camera footage | Partial | Requires a known matching transform/LUT; no automatic camera profile management || Full-scene grade including DOM/text | Not supported | Current grading targets individual media elements |-| Face or region tracking | Not supported | Use a separate isolated media layer or external tracking/masking workflow |+| Face or region tracking | Not supported | No masks or tracking in the contract. Isolate the region as its own layer — see [Limiting a Grade to Part of the Frame](#limiting-a-grade-to-part-of-the-frame) || Remote media | Partial | Requires compatible CORS headers; project-local assets are reliable || ACES/OCIO finishing | Not supported | Outside the current browser shader pipeline |diff --git a/docs/prompting/color-grading.mdx b/docs/prompting/color-grading.mdxnew file mode 100644index 0000000000..fd79e6c638--- /dev/null+++ b/docs/prompting/color-grading.mdx@@ -0,0 +1,159 @@+---+title: Colour grading and film effects+description: "Grade media with a fixed-order pipeline — tonal work, hue keys, print and analogue treatments — and know why the source matters more than the payload."+---++Every chapter so far has built the image. This one changes what the image appears to have been *recorded on*. A grade is not decoration applied at the end; it is a claim about the medium — that this came off tape, or a press, or a tube, or a camera with a particular stock in it. Viewers read that claim instantly and they read it whether or not you meant it.++Grading attaches to a single `<img>` or `<video>` through a `data-color-grading` payload. It never touches your text, your cards, or your captions — only the pixels of the media element it is on. The full contract lives in the [Colour Grading guide](/guides/color-grading); this chapter is about what to *ask for*, and about the three ways these prompts go wrong.++## The source has to have something to lose++This is the failure that costs the most time, and it is invisible in the prompt. Every one of these treatments works by *removing* something, so the shot must contain the thing being removed.++Three worked examples from building this page, each of which produced a demo that technically executed and visibly taught nothing:++| Treatment | Wrong source | Why it showed nothing |+| --- | --- | --- |+| Hue key — hold one colour | Talking head in a kitchen | Skin **is** the red band. Keying red kept the face; 6% of pixels moved. |+| Two-ink press | Black type on white paper | Already two-tone. Nothing to collapse. |+| Kuwahara — painterly | Soft-focus office | An edge-preserving smoother needs edges to preserve. |++Fixing all three meant changing the footage, not the payload. So specify the subject in the prompt, and specify it in terms of the property the effect consumes: *"pick a subject with dense colour and dense edges"*, *"the surround has to carry colour, not be neutral grey"*.++## The pipeline order is fixed++Sections apply in a set order regardless of how you write them:++```text+adjust → wheels → curves → hueCurves → secondaries → lut → details → effects+```++This is not cosmetic. A global `saturation: -0.9` in `adjust` runs *before* `secondaries`, so a hue-keyed selection that tries to hold one colour back finds it already desaturated and has nothing to restore. If you want one colour to survive a drain, key it in `hueCurves` rather than draining globally and painting it back.++## Grading qualifies by value, never by position++Selections key on hue, saturation, and luma. There are no masks, shapes, or tracked regions, and the one spatially-varying control — `vignette` — is locked to the frame centre. To treat *part* of a frame you split that part into its own layer and grade the layer. That pattern, with worked markup, is in [Limiting a Grade to Part of the Frame](/guides/color-grading#limiting-a-grade-to-part-of-the-frame).++---++## Separating subject from background++The most useful thing grading does is not a look. It is protecting one part of the frame while treating another — which requires a matte, and therefore two layers.++### Grade the room, protect the face++> Take the talking-head clip and separate the subject from the room. Leave the person photographic — a gentle skin-softening pass and about a third of a stop of extra exposure, nothing that reads as an effect on skin. Grade the room behind them instead: across the four seconds bring up a halftone screen so the space resolves into small coloured dots, and let a restrained bloom build alongside it so the windows lift. Both start at zero so the shot opens ungraded.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-matte-separation-b0ef8e73.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++Two traps here. Use the **original clip** as the background plate, not a subject-removed plate — that plate is a hole where the subject was, and a feathered cutout over it gives a dark rim. And if your cutout ships premultiplied alpha, the browser composites it as straight, multiplying edge pixels twice and producing a black outline; rebuild it with `ffmpeg alphamerge` from the original plus its matte.++### Redact only the face++> Matte the subject off the plate, then redact just their face — the rest of them and the room behind both stay completely untouched. Hold pixelation constant at about half strength for the whole shot: no ramp, no fade-up. A redaction that animates on reads as an effect; one that is simply on reads as policy. Size the redaction generously so it takes in the hairline, ears and jaw rather than sitting tight on the features.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-redaction-engaging-ec781f26.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++The region comes from a `clip-path` on a *third* layer — a second copy of the cutout carrying the grade, stacked over an ungraded copy. Because the graded layer **is** the cutout, the ellipse can overshoot the head without touching the room; there is nothing outside the silhouette to paint. Size it generously rather than tightly.++A fixed clip only holds for footage where the subject barely moves. Measure before relying on it — here the head travelled 5.5px across the whole clip. Anything with real movement needs a tracked matte produced outside HyperFrames.++---++## Destroying the picture on purpose++### Pixelate, dither, bloom++Three ways to take the image apart, each saying something different. Pixelation reads as *redaction*. Dither reads as a *display failing*. Bloom reads as *light overwhelming the sensor*.++> Degrade the picture into a screen over four seconds. Ramp dithering from clean up to 0.85 at mid pattern size, so continuous tone breaks into discrete quantised levels. It should read as a display failing, not as a filter being applied.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-signal-loss-babe88ef.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++> Blow the highlights out over four seconds. Ramp bloom from nothing all the way to 3 — well past a tasteful highlight lift — on a wide radius, so light spills out of the windows and progressively swallows the frame. I want to see the top of the range, not a subtle glow.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-bloom-out-11531968.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++<Warning>+ Bloom is the one control that will fool your instruments. Pushed hard it looks blown out while measuring as *less* clipped than the ungraded source — the haze is halation spreading light, not clipping. No clipping metric catches it. Judge bloom at 1:1, never from a thumbnail.+</Warning>++### Painterly, without mush++> Turn the shot into a painting over four seconds without turning it to mush. Ramp a Kuwahara filter from nothing to full — mid radius, fairly high sharpness so edges stay crisp, and pull the saturation back a little so it reads as brushwork rather than as a filter. Boundaries stay defined while flat areas smooth into strokes. Pick a subject with dense colour and dense edges; the effect has nothing to preserve on flat skin or a soft-focus background.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-painterly-ffd5c0f9.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++---++## Print and colour++### Two inks++> Take the poster and print it in two inks only: a near-black navy and a warm cream, at mid dot size, like a two-colour press run. Everything collapses to those two colours. Bring it up across the four seconds from the untouched poster rather than cutting straight to it. Give it the exact hex values rather than a named palette.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-two-ink-press-3c5662f1.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++Type is the harshest test of a two-ink reduction — dense small copy either survives the dot screen or turns to mud, and you can see which at a glance. Note the payload takes an explicit hex array; a named palette id is rejected.++### Hold one colour, drain the rest++> A single red apple on a teal backdrop. Hold the apple's colour and drain everything else — key off hue and collapse saturation everywhere outside the reds, so the backdrop goes fully neutral grey while the apple stays exactly as saturated as it was. Use a hue-vs-saturation curve rather than a global desaturation with the apple keyed back in: global saturation runs first in the pipeline and would kill the apple before the key ever sees it. Keep a generous skirt on the band so the apple's shadowed side doesn't clip grey.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-brand-spotlight-5ebe45bf.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++Three things have to be true of the subject, and each one killed an earlier attempt at this shot. It must be **inanimate** — the grade desaturates everything outside the band, and on a person that means a grey, corpse-like face. It must be a **single** subject — a still life of mixed produce is full of colour, but half the items fall outside the band and grey out, so it reads as a filter misfiring rather than one colour deliberately held. And the surround must **carry** colour: against a neutral grey backdrop the grade would desaturate grey to grey and do nothing at all.++---++## Analogue: three different failures++"Make it look old" is three separate treatments, and mixing them muddles the period.++| Treatment | What is failing | Signature |+| --- | --- | --- |+| **Tape** | The transport | Rolling horizontal wave, tracking error, dropout |+| **Tube** | The display glass | Barrel curvature, scanlines, phosphor bleed, convergence error |+| **Camera** | The capture | Grain, crushed contrast, RGB split, vignette |++The rolling wave is `tapeTracking` and `tapeDamage`. Static interlacing is `scanlines` — a different thing, and it belongs on a camera or a tube without dragging the wave along with it.++### Tape++> Make it look like a worn VHS tape. Not one artefact — layer them: strong tape damage with tracking error, a little noise, mid tape speed, scanlines, and noticeable chroma bleed. Any one of these alone reads as a filter; together they read as a failing signal.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-tape-degradation-6050228f.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++### Tube++> Make this look like it is being displayed on an old CRT television, not like it came off a worn tape. Bow the geometry with barrel curvature so the straight lines curve and the corners pull inward, lay scanlines across it at a fairly fine pitch, add phosphor bleed and enough chromatic aberration to give visible RGB fringing at the edges. Bleed and scanlines want to sit near the top of their range — bleed is subtle even at 0.9. Curvature and chromatic aberration are the exceptions: both read strongly, so hold curvature around half and keep the aberration modest, or the tube turns into a fisheye novelty. Grade the tone as well as the geometry: crush the shadows and blacks, lift the highlights and whites, nudge saturation up, and add a restrained bloom — a CRT has no true black and lets its top end halate. Add grain and a vignette. Use a test card or something with dead-straight lines: curvature is invisible on organic subject matter.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-crt-broadcast-b64dc1a8.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++The tonal work is doing as much as the geometry. Without crushed shadows and a halating top end, curvature and scanlines read as a filter laid over a clean digital image.++If you composite a subject into the shot, do it **before** grading. A CRT warps the whole displayed picture; grading two layers separately bows the background while the subject stays rectilinear and spills past the tube's curved edge. One layer, one warp — the opposite of the matte-separation rule above, and for the opposite reason.++### Camera++> Take the clip and give it a camcorder grade: crush the shadows and blacks, lift the highlights and whites, pull the saturation back slightly, and add a restrained bloom, film grain for noise, a vignette, interlacing lines, and a little RGB splitting at the edges. Crushed contrast with muted colour is what consumer tape actually looked like — crushed and punchy reads as a modern filter. For the split use chromatic aberration, which offsets the channels; chroma bleed is a different thing, a smear rather than a fringe. Keep the interlacing static — no tape tracking and no tape damage, because those produce a rolling horizontal wave that reads as a broken deck rather than as a camera.++<video controls muted loop playsinline preload="metadata" src="https://static.heygen.ai/hyperframes-oss/docs/images/prompting/grade-camcorder-overlay-18e80485.mp4" style={{ borderRadius: "0.5rem", marginTop: "0.75rem" }}></video>++The HUD in that shot is not part of the grade. It is a [`camcorder-hud`](/guides/media-overlays) registry block — real HTML, CSS, and a paused GSAP timeline composed *above* the media canvas. Grading never touches it, which is exactly what you want: burn a timestamp into the source pixels and it degrades with them; put it in an overlay and it stays crisp, editable, and timeline-driven while the footage falls apart underneath.++## Animating a grade++Nine properties expose a CSS custom property and tween directly — `ascii`, `bloom`, `blur`, `dither`, `exposure`, `intensity`, `kuwahara`, `lut`, `pixelate`. Start them at identity so the shot opens ungraded and every intermediate value renders.++Two caveats worth knowing before you promise a client a ramp:++- **`--hf-color-grading-intensity` does not scale a grade at render time.** A static `0.5` renders the same as `0`. Do not reach for it as a generic "ramp the whole look" dial.+- **Everything else has no custom property.** Some of those can still be animated by rewriting the `data-color-grading` payload from the timeline — verified working for `halftone` and `twoInkPrint`. It is verified *not* working for `crtCurvature`, `scanlines`, `chromaBleed`, and `chromaticAberration`, where the same payload renders correctly applied statically but produces no change when driven through `setAttribute`. Measure the effect you intend to animate, and fall back to a static treatment if the ramp does not move.++## Next steps++- [Colour Grading guide](/guides/color-grading) — the full contract, every key and bound+- [Media Overlays](/guides/media-overlays) — HUD, flash, light leak, freeze-frame dressing+- [VFX and liquid glass](/prompting/vfx-and-liquid-glass) — the canvas-pipeline end of the catalog