The camera
Some moves belong to the whole picture: a card comes in and everything else slides aside to make room, or the frame pulls back to show what was beside it. Writing that on each element means the same keys copied onto every one, and kept in step by hand. A <Camera> writes it once.
import { Camera, Clip, Composition, Shape, Title, Track } from "@uberscene/kit";
export default function Video() {
return (
<Composition fps={30} width={960} height={540} background={{ type: "color", color: "#3447ff" }}>
{/* Everything on the camera's tracks moves together: here it pans to make room, then pulls back. */}
<Camera
id="cam"
x={[
{ at: 1, value: 0, easing: "snappy" },
{ at: 1.3, value: -70 },
]}
zoom={[
{ at: 2.2, value: 1, easing: "snappy" },
{ at: 2.5, value: 0.88 },
]}
>
<Track id="subject" layout="free">
<Clip
id="pour"
src="asset:espresso"
start={0}
in={6}
duration={4}
volume={0}
fit="cover"
box={{ x: 480, y: 280, width: 400, height: 225, origin: "center" }}
transform={{ borderRadius: 16 }}
/>
</Track>
<Track id="cards" layout="free">
<Shape
id="card"
type="rectangle"
start={1}
duration={3}
width={150}
height={190}
cornerRadius={12}
fill="#ffffff"
box={{ x: 130, y: 280, origin: "center" }}
enter={{ type: "pop", duration: 0.3 }}
/>
<Shape
id="card-2"
type="rectangle"
start={2.2}
duration={1.8}
width={150}
height={190}
cornerRadius={12}
fill="#ffffff"
box={{ x: 870, y: 280, origin: "center" }}
enter={{ type: "pop", duration: 0.3 }}
/>
</Track>
</Camera>
{/* A track outside the camera stays fixed to the screen. */}
<Track id="brand" layout="free">
<Title id="mark" start={0} duration={4} box={{ x: 480, y: 48, origin: "center" }} style={{ size: 20 }}>
fixed to the screen
</Title>
</Track>
</Composition>
);
}What it moves
A camera is a parent: it moves the tracks written inside it, and nothing else.
<Composition fps={30} width={1920} height={1080}>
<Camera id="cam" zoom={1.1}>
<Track id="speaker">...</Track>
<Track id="cards" layout="free">...</Track>
</Camera>
<Track id="logo" layout="free">...</Track>
</Composition>- Everything on
speakerandcardsmoves, zooms and turns together: footage, titles, shapes, layers, nested sequences. logois outside, so it stays fixed to the screen. Captions and the composition's background stay too.- Tracks still draw in the order the file writes them, across the camera's edge. A track under the camera's tracks is under them; one written after is over them.
- Each element keeps its own place, entrance and keys. The camera goes on top of those, so an element that slides in slides in under a moving camera as it would under a still one.
- A file without a camera draws as it always did. A composition has one camera, and it holds
<Track>s only.
Clips written straight in the composition are its main track, and stay outside. To move them, write them in <Track id="main"> inside the camera.
Its four values
| Prop | What it does |
|---|---|
x | How far the view has moved right, in pixels. At 180, everything under the camera sits 180 px to the left. |
y | How far the view has moved down. At 100, everything sits 100 px higher. |
zoom | How close the view is, about the frame's centre. 1 is as written, 2 shows everything twice the size. |
rotation | How far the view is turned clockwise, in degrees. What it shows turns the other way. |
These are a camera's numbers, not an element's: moving the view right moves the picture left. The point at (width / 2 + x, height / 2 + y) is what sits in the middle of the frame, whatever the zoom.
Each value is a number, or a list of keys when it changes. A key's at is seconds from the start of the video, since a camera has no start of its own. easing says how the value leaves that key, as on any key.
<Camera id="cam"
x={[
{ at: 1, value: 0, easing: "snappy" },
{ at: 1.3, value: -110 },
{ at: 2.2, value: -110, easing: "snappy" },
{ at: 2.5, value: 110 },
]}
zoom={[{ at: 0, value: 1 }, { at: 6, value: 1.06 }]}>The view holds until 1 s, snaps 110 px left as the first card lands, holds, then snaps to the right for the second. Under it the zoom closes in slowly for the whole six seconds, so the frame is never still.
An element written off the frame is not lost: a camera that pans or pulls back far enough shows it.
Depth
Under one camera every track moves by the same amount, so a pan slides the picture like a sheet of paper. Give a track a depth and it takes only part of the move: far things move less than near ones, and the flat picture reads as deep.
import { Camera, Composition, Shape, Title, Track } from "@uberscene/kit";
/**
* One camera move, five depths. The camera pans 520 px to the right and closes in a little, and that is the only
* motion written: each track takes the share of it its `depth` gives. The sky, three focal lengths back, moves a
* quarter as far; the two rows of buildings a third and a half; the title, at the camera's own depth, all of it; and
* the grass, in front of the focal plane, twice as far. Tracks still draw in the order they are written, far to near.
*/
const NIGHT = "#0e1430";
const SKY = "#1a2452";
const STAR = "#f4ecd0";
const FAR = "#27336e";
const MID = "#3a4c9c";
const LIT = "#ffd27a";
const PAPER = "#ffffff";
const GRASS = "#0a2a22";
const BLADE = "#12443a";
const HORIZON = 600;
/** Stars: where each sits, and how big it is. */
const STARS = [
[40, 90, 6],
[210, 190, 4],
[330, 60, 5],
[520, 150, 7],
[700, 80, 4],
[860, 210, 5],
[1010, 110, 6],
[1180, 60, 4],
[1290, 170, 7],
[1420, 90, 5],
] as const;
/** A row of buildings: each one's left edge, its width and its height above the horizon. */
const FAR_ROW = [
[-60, 150, 190],
[120, 110, 260],
[260, 170, 170],
[470, 120, 300],
[620, 190, 210],
[850, 130, 270],
[1010, 160, 180],
[1200, 120, 310],
[1350, 180, 200],
[1560, 140, 250],
] as const;
const MID_ROW = [
[-100, 220, 230],
[180, 160, 360],
[400, 240, 190],
[700, 170, 330],
[930, 260, 240],
[1250, 180, 380],
[1490, 230, 210],
[1780, 190, 300],
] as const;
/** Tufts of grass in front: each one's centre and its height. */
const TUFTS = [
[80, 150],
[420, 210],
[760, 130],
[1130, 230],
[1500, 160],
[1870, 220],
[2240, 140],
[2600, 200],
] as const;
export default function Video() {
return (
<Composition fps={30} width={1280} height={720} background={{ type: "color", color: NIGHT }}>
<Camera
id="cam"
x={[
{ at: 0, value: 0, easing: "easeInOut" },
{ at: 6, value: 520 },
]}
zoom={[
{ at: 0, value: 1, easing: "easeInOut" },
{ at: 6, value: 1.12 },
]}
>
{/* Far: the camera's move reaches the sky by a quarter. */}
<Track id="sky" layout="free" depth={3}>
<Shape
id="band"
type="rectangle"
start={0}
duration={6}
width={1900}
height={700}
fill={SKY}
box={{ x: -200, y: HORIZON - 380, origin: "topLeft" }}
/>
<Shape
id="moon"
type="circle"
start={0}
duration={6}
width={120}
height={120}
fill={STAR}
box={{ x: 1060, y: 250, origin: "center" }}
/>
{STARS.map(([x, y, size], i) => (
<Shape
key={`star-${x}`}
id={`star-${i}`}
type="circle"
start={0}
duration={6}
width={size}
height={size}
fill={STAR}
box={{ x, y, origin: "center" }}
/>
))}
</Track>
{/* Two rows of buildings, the farther one slower: a third and a half of the move. */}
<Track id="far-row" layout="free" depth={2}>
{FAR_ROW.map(([x, width, height], i) => (
<Shape
key={`far-${x}`}
id={`far-${i}`}
type="rectangle"
start={0}
duration={6}
width={width}
height={height + 140}
fill={FAR}
box={{ x, y: HORIZON - height, origin: "topLeft" }}
/>
))}
</Track>
<Track id="mid-row" layout="free" depth={1}>
{MID_ROW.map(([x, width, height], i) => (
<Shape
key={`mid-${x}`}
id={`mid-${i}`}
type="rectangle"
start={0}
duration={6}
width={width}
height={height + 140}
fill={MID}
box={{ x, y: HORIZON - height, origin: "topLeft" }}
/>
))}
{MID_ROW.map(([x, width, height], i) => (
<Shape
key={`window-${x}`}
id={`window-${i}`}
type="rectangle"
start={0}
duration={6}
width={26}
height={34}
cornerRadius={4}
fill={LIT}
box={{ x: x + width / 2, y: HORIZON - height + 60, origin: "center" }}
/>
))}
</Track>
{/* No depth: the title moves exactly with the camera, as every track did before. */}
<Track id="words" layout="free">
<Title
id="headline"
start={0}
duration={6}
box={{ x: 900, y: 300, origin: "center" }}
style={{ size: 120, weight: 800, color: PAPER, letterSpacing: 4 }}
>
DEPTH
</Title>
<Title
id="line"
start={0}
duration={6}
box={{ x: 900, y: 400, origin: "center" }}
style={{ size: 30, weight: 600, color: STAR, letterSpacing: 6 }}
>
ONE CAMERA, FIVE LAYERS
</Title>
</Track>
{/* Near: in front of the focal plane, the grass takes the move twice over. */}
<Track id="grass" layout="free" depth={-0.5}>
<Shape
id="ground"
type="rectangle"
start={0}
duration={6}
width={3200}
height={200}
fill={GRASS}
box={{ x: -300, y: 610, origin: "topLeft" }}
/>
{TUFTS.map(([x, height], i) => (
<Shape
key={`tuft-${x}`}
id={`tuft-${i}`}
type="ellipse"
start={0}
duration={6}
width={130}
height={height}
fill={BLADE}
box={{ x, y: 630, origin: "center" }}
/>
))}
</Track>
</Camera>
</Composition>
);
}<Camera id="cam" x={[{ at: 0, value: 0 }, { at: 3, value: 400 }]}>
<Track id="sky" depth={3}>...</Track>
<Track id="town" depth={1}>...</Track>
<Track id="hero">...</Track>
<Track id="grass" depth={-0.5}>...</Track>
</Camera>depth is how far behind the camera's focal plane the track sits, in focal lengths. The camera's move reaches the track multiplied by 1 / (1 + depth):
depth | Share of the move | Under a 400 px pan |
|---|---|---|
3 | a quarter | 100 px |
1 | half | 200 px |
0, or left out | all of it | 400 px |
-0.5 | twice | 800 px |
xandyare multiplied by that share.zoomis pulled toward 1 by it, about the frame's centre: under a zoom of 2, a track at depth 1 is shown at 1.5 and one at depth 3 at 1.25. A push-in then grows the foreground more than the background, as a real one does.rotationis the camera's roll, and turns every track alike.- A track with no
depthmoves exactly with the camera, so a file written before depth draws as it did.
Depth changes how a track moves, not what it covers: tracks still draw in the order the file writes them. Write the far tracks first.
A depth is one number for the whole video, and it must be above -1, where the track would be at the lens. It belongs to a track inside a <Camera>; on a track outside one it is an error. A near track under a camera pulled far back stops shrinking at a hundredth of its size.
With a push, each element is held in view through its own track's share of the move. A card on a far track needs a longer pan to come into view than one at the camera's own depth, and the camera pulls back only when no pan holds everything at once.
For layers that drift apart with no camera at all, key each layer's own box.x by a different distance: the parallax card in the motion catalog shows it.
Let the camera make room
Working out each pan and zoom by hand means redoing them whenever a card moves. With push, the camera does it:
<Camera id="cam" push={{ on: ["card-a", "card-b", "card-c"] }}>
<Track id="subject" layout="free">...</Track>
<Track id="cards" layout="free">...</Track>
</Camera>Write each card where it belongs beside the subject, partly or wholly outside the frame. As each element in on starts, the view moves as little as it can to hold it with everything else on the camera's tracks that is on screen then:
- If the element is already in view, nothing moves.
- Else the view pans the shortest way that brings everything inside the margin.
- Only when everything cannot fit does it pull back, and only as far as it must. It never closes in past the camera's own
zoom.
Move a card and the camera's move follows, because the moves are worked out from the file each time it is read.
In push | What it does |
|---|---|
on | The elements to make room for, on the camera's tracks. Ones that start together are one move. |
keep | The only elements that must stay in view, with those in on: a speaker, say. Left out, everything on screen under the camera stays in view. |
margin | How far inside the frame's edge everything sits, in pixels. Left out, a twentieth of the frame's shorter side. |
duration | How long each move takes, from the moment its element starts. 0.3 s when left out. |
easing | How each move goes. snappy when left out. |
With push, the camera's x, y and zoom are numbers: where the view starts. Keys on them beside a push are an error, since two things cannot both set them. rotation is free, and a generator on any of the four goes on top: a drift on zoom closes in slowly while the camera still makes room, so the frame is never still.
The camera makes room for an element's box: a shape's width and height, footage as it is fitted into its box, a title or layer's box.width and box.height. A title with no size in its box counts as the point it is placed at, so give it a box.width and box.height if the camera should make room for all of it. An element's own keys, scale and rotation are not followed: it counts where it stands when it starts. --check-layout still measures the real picture, so anything left cut off is reported.
To change the moves by hand, turn them into keys: camera/bakePush writes them as key lists on x, y and zoom and removes the push. From then on they are the file's, and no longer follow the cards. In the editor, select the camera and choose "Turn its moves into keys".
What stays in screen pixels
A zoom scales where things are and how big they are. It does not scale an effect's own pixel sizes: a blur of 12 is 12 px on screen at any zoom, and so are a cut-out's shrink and feather, a mask's feather and the grain. An adjustment on a track inside the camera still grades the whole frame beneath it.
Checking and editing
--check-layoutmeasures what is drawn, so it sees a title the camera has pushed past the safe zone. Its fix is in the element's own numbers: under a zoom of 2, a title 40 px too far right is told to move itsbox.xby 20. On a track with adepththe numbers are that track's: its own share of the zoom.uberscene inspectgives the camera's four values at each moment, and marks the elements under it. Theirboxandtransformare as written, before the camera. An element on a track with adepthis listed with it, and with the camera'sx,yandzoomas they reach that track.camera/setPushgives a camera a push or takes it away, andcamera/bakePushturns it into keys.- An editor changes the camera with
camera/updateand its keys withkey/addand the other key actions, using the pathsx,y,zoomandrotation. camera/addputs a camera around tracks that are next to each other, andcamera/removetakes it away. Either way the tracks keep their place in the stack.track/reorderandtrack/addcount a camera's tracks in the camera's place. A track moved above one of the camera's joins it, and one moved away leaves; at the camera's edge,camera: trueorfalsedecides. A track that leaves the camera, or whose camera is removed, loses itsdepth; undo puts it back.
Camera or a move on the clip
The motion catalog's push-ins scale one clip. Use those when one shot moves. Use a camera when several things must move as one, or when something outside the move must stay put.
Motion blur (motionBlur on the composition) blurs a camera move as it blurs any other, in the export and in the preview.