`<pacem-media-timeline>` is a video editor's timeline, written in markup: tracks of video, audio, images and
canvases, each placed in time, with fades and moves on top. The timeline only keeps time; a `<pacem-media-stage>`
draws it on a canvas, and a `<pacem-media-recorder>` turns that canvas (and the mixed audio) into a video file.
```html
<pacem-media-timeline id="clip">
<pacem-media-video-track src="intro.mp4" size="100%,100%"></pacem-media-video-track>
<pacem-media-image-track src="logo.svg" start="00:00:02" end="00:00:05">
<pacem-media-track-alpha from="0" to="1" end="500"></pacem-media-track-alpha>
</pacem-media-image-track>
</pacem-media-timeline>
<pacem-media-stage id="screen" timeline="#clip" width="1280" height="720"></pacem-media-stage>
<pacem-media-recorder source="#screen"></pacem-media-recorder>
```
## Usage
**Three roles.** The timeline holds the tracks and the clock: `play()`, `pause()`, `seek(ms)` and a two-way
`currentTime`. A stage draws a timeline at its current time; several stages may draw the same one. A recorder records
a stage. Tracks:
- `<pacem-media-video-track>` and `<pacem-media-audio-track>`: a source file, played in sync with the clock;
- `<pacem-media-image-track>`: a picture;
- `<pacem-media-canvas-track>`: another canvas (its `source`), e.g. a `pacem-2d` / `pacem-3d` scene.
**Place them in time.** `start` and `end` are offsets (`hh:mm:ss.fff`, or plain milliseconds) from an *edge* of a
reference: the parent timeline by default, or another track through `start-anchor` / `end-anchor`.
The edge is `start` unless `start-anchor-edge` / `end-anchor-edge` say `end`.
```html
<!-- 10 s before the end of #intro, until the end of #intro -->
<pacem-media-image-track start="-00:00:10" start-anchor="#intro" start-anchor-edge="end"
end-anchor="#intro" end-anchor-edge="end"></pacem-media-image-track>
```
> The sign of an offset never picks the edge: a negative offset only means *earlier*.
> "10 s before the timeline's end" counts from the `end` edge:
```html
<pacem-media-image-track start="-00:00:10" start-anchor-edge="end"></pacem-media-image-track>
```
Without an end, a video or audio track lasts its source, cropped by `start-offset` / `end-offset` and divided by
`speed`; images and canvases last until the timeline's end. Without a `duration`, the timeline lasts until its
latest track ends. The resolved `absoluteStart` / `absoluteEnd` of every track are bindable.
**Play it.** Browsers start media and audio only after a user gesture: call the first `play()` from a click.
A `<pacem-slider>` bound to `currentTime` needs `smooth="false"`, or its glide makes the thumb trail the clock.
`seek()` returns a promise, resolved (and `seeked` fired) once every source shows the new time.
**Effects** are nested in a track and count from its start: `<pacem-media-track-alpha>` (opacity),
`<pacem-media-track-volume>` (loudness, video and audio) and `<pacem-media-track-transform>`
(an `"a,b,c,d,e,f"` matrix, applied around the track's anchor). Each goes `from` → `to` with an `easing`
(`sineInOut`, …) and holds its values outside its range.
**Animations in time.** A `<pacem-storyboard>` (or a single `<pacem-number-animation>`…) nested in a
track is driven by the timeline: seeking shows its state at that time, and recordings are exact. Anything else can
hook the `start` / `end` events every track and effect fires when the time enters or leaves it.
> Nested storyboards must not `autostart`: the timeline is their clock.
**Record it.** A stage is a source for `<pacem-media-recorder>`: video from its canvas, audio from the
timeline's mix. Start the recorder, play, stop on the timeline's `ended`, then read the recorder's `output` blob.
## Customization
A stage draws at its own resolution, `width` × `height` (default 1280 × 720), and the theme scales its canvas down to
the container, keeping the aspect ratio. `background` paints behind the tracks (`transparent` leaves the canvas clear).
```css
.my-screen > canvas {
width: 100%; /* fill the container, up too */
border-radius: 8px;
}
```
Visual tracks are placed on the stage by three pairs, in `px` or `%`:
```html
<!-- centered, half the stage wide -->
<pacem-media-image-track anchor="50%,50%" position="50%,50%" size="50%,50%"></pacem-media-image-track>
```
- `size`: on the stage (`%` of the stage); the picture's own size when missing;
- `position`: the point of the stage where the anchor goes (`%` of the stage);
- `anchor`: the point of the track placed there (`%` of the track), also the origin of its transforms.
## Examples
### An end card pinned to the photo The card starts 1.5 s before the photo ends and fades in over it: stretch the photo and the card follows.
### Scrub a tween A number animation nested in a track follows the timeline: drag the position and the level shows its value at that time; the track's `start` / `end` events are logged as the position crosses its edges. No stage here: a timeline is just a clock.
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.