Skip to content

Commit 8080e1f

Browse files
committed
docs(concepts): note that media data-duration can be variable-driven
1 parent d28c082 commit 8080e1f

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

docs/concepts/variables.mdx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,45 @@ The same pattern covers the three media element types:
7878

7979
Pass assets as URL references your composition resolves at render time; don't inline base64. URL-shaped assets travel cleanly through both the local renderer and the Lambda surface — see [Templates on Lambda](/deploy/templates-on-lambda#working-with-large-variables) for the 256 KiB execution-input cap on distributed renders.
8080

81+
### Swapping media: do you need to vary duration too?
82+
83+
A common follow-up: if a variable swaps a `<video>` to a different clip, does `data-duration` need to change too? Usually no. `data-duration` is optional on `<video>` and `<audio>` — leave it off and the renderer ffprobes the source and uses its natural length:
84+
85+
```html compositions/hero.html
86+
<video id="hero" data-start="0" data-track-index="0"></video>
87+
<script>
88+
document.getElementById("hero").src = __hyperframes.getVariables().heroVideo;
89+
</script>
90+
```
91+
92+
If you need to clamp or pin the clip to a specific length per render — for example, to keep downstream timing stable across clips of different source lengths — expose duration as its own `number` variable and apply it via the same script:
93+
94+
```html compositions/hero.html
95+
<video id="hero" data-start="0" data-track-index="0"></video>
96+
<script>
97+
const { heroVideo, heroDuration } = __hyperframes.getVariables();
98+
const el = document.getElementById("hero");
99+
el.src = heroVideo;
100+
if (heroDuration !== undefined) {
101+
el.setAttribute("data-duration", String(heroDuration));
102+
}
103+
</script>
104+
```
105+
106+
The probe phase reads `data-duration` from the live DOM after your script runs, so an attribute written programmatically behaves identically to one baked into the source HTML.
107+
81108
## What can't be a variable
82109

83-
Some inputs look variable-shaped but are configured elsewhere. The right mechanism for each:
110+
A small set of inputs are read once from the source HTML or from the CLI / SDK, with no live-DOM re-read — no script (and therefore no variable) can change them:
84111

85112
| What | Mechanism (not a variable) |
86113
|------|----------------------------|
87-
| Composition duration | `data-duration` attribute on the composition element |
88-
| Composition dimensions | `data-width` / `data-height` attributes |
89-
| Frame rate | `--fps` flag on `hyperframes render` |
90-
| Output format / codec / quality | `--format` / `--codec` / `--quality` flags |
114+
| Composition dimensions | `data-width` / `data-height` on the composition element — parsed from the source HTML at compile time, not from the live DOM |
115+
| Frame rate | `--fps` flag on `hyperframes render`, or `config.fps` in the SDK |
116+
| Output format / codec / quality | `--format` / `--codec` / `--quality` flags, or the SDK equivalents |
91117
| A sibling or parent composition's variables | Variables are per-composition; use [`data-variable-values`](#per-instance-overrides-sub-compositions) on each sub-comp host element to pass overrides |
92118

93-
The deeper rule: variables are runtime values, not authoring inputs. A variable can toggle DOM state, swap text, change a color — anything your composition script does with the resolved value. It can't change the composition's structural identity. Two compositions with different `data-composition-id` or different layout markup remain different compositions, even when their variable values are identical.
119+
The deeper rule: variables are runtime values your script applies to the DOM. They can drive anything the renderer reads from the live DOM after that script runs — text, colors, media `src`, even clip `data-duration` as shown above. They can't change inputs the renderer reads once at compile time (dimensions) or that live entirely outside the composition (CLI flags, encoder settings).
94120

95121
## Reading Variables at Runtime
96122

0 commit comments

Comments
 (0)