An edit timeline becomes a file with `<pacem-media-exporter>`: frame by frame, faster than real time, it seeks the timeline, lets the stage draw and encodes an MP4 (H.264 + AAC), the sound mixed offline. Everything the timeline drives is exact in the file: tracks, effects, masks, nested storyboards, and the CSS animations of HTML tracks. ```html <pacem-media-timeline id="clip">…</pacem-media-timeline> <pacem-media-stage id="screen" timeline="#clip"></pacem-media-stage> <pacem-media-exporter id="exporter" timeline="#clip" stage="#screen" fps="30"></pacem-media-exporter> <pacem-button on-click="#exporter.export().then(blob => Pacem.Utils.download(blob, 'clip.mp4'))">export</pacem-button> ```
## Usage
**Export.** `export()` resolves with the MP4 `Blob` (rejected when aborted or failed); `progress` events report the `phase`
(`audio`, then `video`) and a `ratio` in `[0, 1]`; `exporting` is bindable, `abort()` stops. The size is the stage's
unless `width` / `height` say otherwise, `fps` defaults to 30. A live timeline can't be exported until `stop()` turns
it into an edit.
**Fast and exact.** The exporter doesn't play the timeline: it seeks it, frame after frame, and waits for every track
to settle. Video tracks with an MP4 (H.264) source are decoded with WebCodecs meanwhile (frame-exact, several times
faster than seeking a `<video>`); other sources fall back to their `<video>`. The sound is rendered offline,
with every track's volume and volume effects.
> Canvas scenes running on their own clock and HTML changed by scripts are captured as they are at each frame (the
> exporter logs it): drive them with a nested storyboard, or with CSS / Web Animations, to have them exact.
**Fit.** `fit` fills the track's rect like CSS `object-fit`: `fill` (default) stretches, `contain` letterboxes,
`cover` crops; the crop follows the track's transforms.
**Masks.** `<pacem-media-track-mask>` clips a visual track to a CSS basic shape in its own box: `circle()`,
`ellipse()`, `inset(… round …)`, `polygon()`, `path()`. Without `to` it's static; with `from` / `to` it animates over the
mask's `start` / `end` (an iris above: `circle(0%)` → `circle(100%)`). Several masks intersect.
**HTML tracks.** `<pacem-media-html-track source="#title">` draws a page element with its CSS: its Web Animations
(`@keyframes`, transitions, `element.animate()`) follow the track's time, so seeking and exporting show them exactly.
Chromium draws it through HTML-in-Canvas, other browsers through an SVG snapshot per frame (no web fonts, iframes
or shadow trees there): `renderer` tells which.
## Customization
```html
<!-- a 1080p file at 60 fps, a lighter bitrate, streamed to memory in fragments -->
<pacem-media-exporter timeline="#clip" stage="#screen" width="1920" height="1080" fps="60"
video-bitrate="6000000" layout="fragmented"></pacem-media-exporter>
```
- `width` / `height`: another size than the stage's (drawn on a detached stage of that size);
- `video-bitrate` / `audio-bitrate`, `codec` (an H.264 codec string);
- `layout`: `progressive` (the default: plays while downloading) or `fragmented` (flat memory on long exports);
- `sink`: `{ write(bytes), close() }` receiving the bytes in file order instead of a `Blob` (e.g. a file opened with
the File System Access API; `export()` then resolves with `null`).
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.