@motionhub/remotion 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -12
- package/film.js +34 -5
- package/index.d.ts +10 -3
- package/index.js +9 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Use a motion from [motionhub.dev](https://motionhub.dev) in Remotion. Its React components (`react/parts/`) run as they are, drawn by Remotion's frame; its tokens become Remotion values for anything you draw yourself.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx @motionhub/cli get @
|
|
6
|
+
npx @motionhub/cli get @motionhub/stage-light # into ./motions/@motionhub/stage-light/
|
|
7
7
|
npm i @motionhub/remotion @motionhub/runtime
|
|
8
8
|
```
|
|
9
9
|
|
|
@@ -13,9 +13,9 @@ Wrap the composition once, outside every `<Sequence>`, with the motion's tokens,
|
|
|
13
13
|
import {Sequence, interpolate, useCurrentFrame} from 'remotion';
|
|
14
14
|
import {Caption} from '@motionhub/runtime';
|
|
15
15
|
import {MotionFonts, MotionProvider} from '@motionhub/remotion';
|
|
16
|
-
import tokens from '../motions/@
|
|
17
|
-
import {Plate} from '../motions/@
|
|
18
|
-
import {Numeral} from '../motions/@
|
|
16
|
+
import tokens from '../motions/@motionhub/stage-light/tokens.json';
|
|
17
|
+
import {Plate} from '../motions/@motionhub/stage-light/react/parts/plate.tsx';
|
|
18
|
+
import {Numeral} from '../motions/@motionhub/stage-light/react/parts/numeral.tsx';
|
|
19
19
|
|
|
20
20
|
export const Film = () => {
|
|
21
21
|
const frame = useCurrentFrame();
|
|
@@ -80,8 +80,22 @@ outside the `Series`, so its frames are the film's. Each sound is a `Sequence` f
|
|
|
80
80
|
file (a URL, or a path in `public/`), trimmed, looped and faded as the film says, its level in dB a gain. Above 0 dB, Remotion amplifies
|
|
81
81
|
when it renders; its preview and Player hold a volume at 1 unless `useWebAudioApi` is set, which needs the file served with CORS, so the
|
|
82
82
|
binding leaves it off. A sound without `dur` that does not loop plays its file to its end or to the end of where it sits; its fade out is
|
|
83
|
-
heard only when it lasts that long, since the binding does not read the file.
|
|
84
|
-
|
|
83
|
+
heard only when it lasts that long, since the binding does not read the file. `filmSounds(Main, film)` gives the same in frames, for code
|
|
84
|
+
of your own.
|
|
85
|
+
|
|
86
|
+
A narrated film (`<Film voice>`, `@motionhub/runtime` 0.8) gives each spoken line's speech by id, `{seconds, words, src}`: the engine
|
|
87
|
+
that spoke it knows them (Open Motion Studio keeps them in a project's `voice/`). Pass it to the provider, which times the lines by it, and
|
|
88
|
+
in the `film` that `filmMetadata` and `<FilmAudio>` read, so the scenes' lengths and the sound agree:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import voice from './voice.json'; // {"intro-1": {"seconds": 1.8, "words": [...], "src": "voice/9f86d081884c7d65.mp3"}}
|
|
92
|
+
const film = {fps: 30, width: 1920, height: 1080, voice};
|
|
93
|
+
// <MotionProvider tokens={{}} voice={voice}> … <FilmAudio component={Main} film={film} /> … </MotionProvider>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`<FilmAudio>` then plays each voiced line's clip (`src`, a path in `public/`) from where the line is said until it ends, and a sound with
|
|
97
|
+
`duck` sinks that many dB under it, down over 0.12 s before a line and back over 0.5 s after it (`DUCK`, `ducked(spans, t)`), as Open
|
|
98
|
+
Motion Studio mixes it. It needs Remotion 4.0.530 or later, the first whose
|
|
85
99
|
`<Html5Audio>` takes `durationInFrames`.
|
|
86
100
|
|
|
87
101
|
## A component's parameters in Remotion Studio
|
|
@@ -93,8 +107,8 @@ them; `paramDefaults(meta)` gives its `defaultProps`. Pass your project's `zod`
|
|
|
93
107
|
import {z} from 'zod';
|
|
94
108
|
import {Composition} from 'remotion';
|
|
95
109
|
import {MotionProvider, paramDefaults, paramsSchema} from '@motionhub/remotion';
|
|
96
|
-
import tokens from '../motions/@
|
|
97
|
-
import {CurveArrow, meta} from '../motions/@
|
|
110
|
+
import tokens from '../motions/@motionhub/lab-notebook/tokens.json';
|
|
111
|
+
import {CurveArrow, meta} from '../motions/@motionhub/lab-notebook/react/parts/arrow.tsx';
|
|
98
112
|
|
|
99
113
|
const Arrow = (props) => <MotionProvider tokens={tokens}><CurveArrow {...props} /></MotionProvider>;
|
|
100
114
|
|
|
@@ -117,10 +131,10 @@ A film can change motion from scene to scene, or hold two in one frame ([a proje
|
|
|
117
131
|
import {Sequence} from 'remotion';
|
|
118
132
|
import {MotionScope} from '@motionhub/runtime';
|
|
119
133
|
import {MotionFonts, MotionProvider} from '@motionhub/remotion';
|
|
120
|
-
import notebook from '../motions/@
|
|
121
|
-
import pencil from '../motions/@
|
|
122
|
-
import {Opening} from '../motions/@
|
|
123
|
-
import {Headline} from '../motions/@
|
|
134
|
+
import notebook from '../motions/@motionhub/lab-notebook/tokens.json';
|
|
135
|
+
import pencil from '../motions/@motionhub/red-pencil/tokens.json';
|
|
136
|
+
import {Opening} from '../motions/@motionhub/lab-notebook/react/parts/opening.tsx';
|
|
137
|
+
import {Headline} from '../motions/@motionhub/red-pencil/react/parts/headline.tsx';
|
|
124
138
|
|
|
125
139
|
export const Film = () => (
|
|
126
140
|
<MotionProvider tokens={notebook} root={false}>
|
package/film.js
CHANGED
|
@@ -4,10 +4,10 @@ import {createElement} from 'react';
|
|
|
4
4
|
import {renderToStaticMarkup} from 'react-dom/server';
|
|
5
5
|
import {MotionRuntimeProvider} from '@motionhub/runtime';
|
|
6
6
|
|
|
7
|
-
/** The structure of the <Film> a component draws */
|
|
8
|
-
function outlineOf(Component, {fps = 30, width = 1920, height = 1080, props = {}}) {
|
|
7
|
+
/** The structure of the <Film> a component draws, its voiced lines timed by their speech */
|
|
8
|
+
function outlineOf(Component, {fps = 30, width = 1920, height = 1080, props = {}, voice}) {
|
|
9
9
|
let outline = null;
|
|
10
|
-
const value = {useTime: () => 0, useCompositionTime: () => 0, fps, width, height, tokens: {}, Video: () => null, onFilm: (o) => { outline = o; }};
|
|
10
|
+
const value = {useTime: () => 0, useCompositionTime: () => 0, fps, width, height, tokens: {}, Video: () => null, onFilm: (o) => { outline = o; }, ...(voice ? {voice} : {})};
|
|
11
11
|
try {
|
|
12
12
|
renderToStaticMarkup(createElement(MotionRuntimeProvider, {value}, createElement(Component, props)));
|
|
13
13
|
} catch (error) {
|
|
@@ -80,8 +80,37 @@ export function soundPlan(sound, fps) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
83
|
+
/** How a sound with `duck` sinks under the narration: down over `attack` s before a line is said, back over `release` s after it */
|
|
84
|
+
export const DUCK = {attack: 0.12, release: 0.5};
|
|
85
|
+
|
|
86
|
+
/** How far a ducking sound is down at `t`, the film's seconds, from 0 to 1 (its whole `duck`), by the narration's spans */
|
|
87
|
+
export function ducked(spans, t) {
|
|
88
|
+
let level = 0;
|
|
89
|
+
for (const {at, until} of spans) {
|
|
90
|
+
const rise = Math.min(1, Math.max(0, (t - (at - DUCK.attack)) / DUCK.attack));
|
|
91
|
+
const fall = Math.min(1, Math.max(0, (until + DUCK.release - t) / DUCK.release));
|
|
92
|
+
level = Math.max(level, Math.min(rise, fall));
|
|
93
|
+
}
|
|
94
|
+
return level;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Every <Sound> of the <Film> a component draws, the film's own and its scenes', as soundPlan gives it; then, with `film.voice` (each line's
|
|
99
|
+
* speech by id, `{seconds, words, src}`), each voiced line's clip from where it is said until it ends, and every sound with `duck` sunk under
|
|
100
|
+
* them by that many dB.
|
|
101
|
+
*/
|
|
84
102
|
export function filmSounds(Component, film = {}) {
|
|
103
|
+
const fps = film.fps ?? 30;
|
|
85
104
|
const outline = outlineOf(Component, film);
|
|
86
|
-
|
|
105
|
+
const spoken = outline.scenes.flatMap((scene) => scene.lines ?? []).filter((line) => line.voiced && film.voice?.[line.id]?.src);
|
|
106
|
+
const spans = spoken.map((line) => ({at: line.start, until: line.end}));
|
|
107
|
+
const sounds = [...(outline.sounds ?? []), ...outline.scenes.flatMap((scene) => scene.sounds ?? [])].map((sound) => {
|
|
108
|
+
const plan = soundPlan(sound, fps);
|
|
109
|
+
if (!sound.duck || !spans.length) return plan;
|
|
110
|
+
const floor = 10 ** (-sound.duck / 20);
|
|
111
|
+
const level = plan.volume;
|
|
112
|
+
return {...plan, volume: (frame) => level(frame) * (1 - (1 - floor) * ducked(spans, (plan.from + frame) / fps))};
|
|
113
|
+
});
|
|
114
|
+
const speech = spoken.map((line) => soundPlan({src: film.voice[line.id].src, at: line.start, dur: null, until: line.end, trim: 0, loop: false, volume: 0, fadeIn: 0, fadeOut: 0}, fps));
|
|
115
|
+
return [...sounds, ...speech];
|
|
87
116
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type {FC, ReactNode} from 'react';
|
|
2
2
|
import type {Tokens} from '@motionhub/runtime';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** A voiced line's speech: its length, its words' times into it, and, for <FilmAudio>, its clip (a URL, or a path in public/) */
|
|
5
|
+
export type LineSpeech = {seconds: number; words: {text: string; start: number; end: number}[]; src?: string};
|
|
6
|
+
export declare const MotionProvider: FC<{tokens: unknown; root?: boolean; voice?: Record<string, LineSpeech>; children?: ReactNode}>;
|
|
5
7
|
/** A component's meta, as SPEC.md §12 has it */
|
|
6
8
|
type MetaOf = {params?: Record<string, {type: string; doc: string; default?: unknown}>};
|
|
7
9
|
/** The types of the vocabulary (SPEC.md §12, Parameters) a schema field is made for */
|
|
@@ -12,7 +14,8 @@ export declare function paramChoices(type: string): string[] | null;
|
|
|
12
14
|
export declare function paramsSchema<Z>(meta: MetaOf, z: Z): any;
|
|
13
15
|
/** A composition's defaultProps for a component: every param's default, where it has one */
|
|
14
16
|
export declare function paramDefaults(meta: MetaOf): Record<string, unknown>;
|
|
15
|
-
|
|
17
|
+
/** The film as drawn: its frame, the component's props, and each line's speech by id when it is narrated (<Film voice>) */
|
|
18
|
+
type FilmOf<P> = {fps?: number; width?: number; height?: number; props?: P; voice?: Record<string, LineSpeech>};
|
|
16
19
|
/** Each scene of the <Film> a component draws, by id, in whole frames that meet end to end */
|
|
17
20
|
export declare function sceneFrames<P extends object>(Component: FC<P>, film?: FilmOf<P>): Record<string, number>;
|
|
18
21
|
/** A composition's metadata for a component that draws a <Film>: its length in frames from the scenes; with `ids`, the scenes must be those, in order */
|
|
@@ -20,7 +23,11 @@ export declare function filmMetadata<P extends object>(Component: FC<P>, film?:
|
|
|
20
23
|
/** A <Sound> of a film in Remotion's frames: a Sequence from `from` for `durationInFrames`, the file from `trimBefore` frames, `sourceFrames` of it (null: the rest), looped or once, at `volume(frame)` */
|
|
21
24
|
export type SoundPlan = {src: string; from: number; durationInFrames: number; trimBefore: number; sourceFrames: number | null; loop: boolean; volume(frame: number): number};
|
|
22
25
|
export declare function soundPlan(sound: import('@motionhub/runtime').FilmSound, fps: number): SoundPlan;
|
|
23
|
-
/**
|
|
26
|
+
/** How a sound with `duck` sinks under the narration, in seconds */
|
|
27
|
+
export declare const DUCK: {attack: number; release: number};
|
|
28
|
+
/** How far a ducking sound is down at `t` (the film's seconds), 0 to 1, by the narration's spans */
|
|
29
|
+
export declare function ducked(spans: {at: number; until: number}[], t: number): number;
|
|
30
|
+
/** Every <Sound> of the <Film> a component draws, as soundPlan gives it; with `film.voice`, the voiced lines' clips too, and `duck` applied */
|
|
24
31
|
export declare function filmSounds<P extends object>(Component: FC<P>, film?: FilmOf<P>): SoundPlan[];
|
|
25
32
|
/** The film's sounds on Remotion's: place it once, outside the Series of scenes */
|
|
26
33
|
export declare const FilmAudio: FC<{component: FC<any>; film?: FilmOf<any>}>;
|
package/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// (@motionhub/runtime) from Remotion's own frame, so they run unchanged; <MotionFonts> loads its faces; useMotion() turns its
|
|
3
3
|
// tokens into Remotion values (frames, Easing) for anything you draw yourself. For a film of scenes (@motionhub/runtime's <Film>),
|
|
4
4
|
// sceneFrames() and filmMetadata() give each scene and the composition their length in frames, from the scenes, and <FilmAudio>
|
|
5
|
-
// plays its sounds (<Sound>, @motionhub/runtime 0.7).
|
|
5
|
+
// plays its sounds (<Sound>, @motionhub/runtime 0.7) and its narration (<Film voice>, 0.8).
|
|
6
6
|
import {Fragment, createElement, useEffect, useMemo, useState} from 'react';
|
|
7
7
|
import {Easing, Html5Audio, OffthreadVideo, Sequence, continueRender, delayRender, interpolate, staticFile, useCurrentFrame, useVideoConfig} from 'remotion';
|
|
8
8
|
import {MotionRoot, MotionRuntimeProvider, resolveTokens, useTokens} from '@motionhub/runtime';
|
|
9
9
|
|
|
10
|
-
export {filmMetadata, filmSounds, sceneFrames, soundPlan} from './film.js';
|
|
10
|
+
export {DUCK, ducked, filmMetadata, filmSounds, sceneFrames, soundPlan} from './film.js';
|
|
11
11
|
import {filmSounds} from './film.js';
|
|
12
12
|
export {PARAM_TYPES, paramChoices, paramDefaults, paramsSchema} from './params.js';
|
|
13
13
|
|
|
@@ -24,13 +24,14 @@ const RemotionVideo = ({src, startAt = 0, trimBefore = 0, playbackRate = 1, obje
|
|
|
24
24
|
/**
|
|
25
25
|
* Wrap the composition in it once, outside every <Sequence>, with the motion's tokens.json: `import tokens from '../motion/tokens.json'`. Its components
|
|
26
26
|
* then draw by Remotion's frame: useTime() inside a <Sequence> counts from its start. `root={false}` leaves out the full-frame root that sets the
|
|
27
|
-
* tokens' custom properties (--color-*, --font-*).
|
|
27
|
+
* tokens' custom properties (--color-*, --font-*). `voice`, each line's speech by id (`{seconds, words}`), times a <Film voice>'s lines by it, as
|
|
28
|
+
* the film given to filmMetadata and <FilmAudio> must.
|
|
28
29
|
*/
|
|
29
|
-
export const MotionProvider = ({tokens, root = true, children}) => {
|
|
30
|
+
export const MotionProvider = ({tokens, root = true, voice, children}) => {
|
|
30
31
|
const frame = useCurrentFrame();
|
|
31
32
|
const {fps, width, height} = useVideoConfig();
|
|
32
33
|
const resolved = useMemo(() => resolveTokens(tokens), [tokens]);
|
|
33
|
-
const value = {useTime: sequenceSeconds, useCompositionTime: () => frame / fps, fps, width, height, tokens: resolved, Video: RemotionVideo};
|
|
34
|
+
const value = {useTime: sequenceSeconds, useCompositionTime: () => frame / fps, fps, width, height, tokens: resolved, Video: RemotionVideo, ...(voice ? {voice} : {})};
|
|
34
35
|
return createElement(MotionRuntimeProvider, {value}, root ? createElement(MotionRoot, {tokens: resolved}, children) : children);
|
|
35
36
|
};
|
|
36
37
|
|
|
@@ -122,8 +123,9 @@ const NO_FILM = Object.freeze({});
|
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
125
|
* The sounds of the <Film> a component draws (@motionhub/runtime 0.7's <Sound>), on Remotion's: each in a Sequence from its start, an
|
|
125
|
-
* <Html5Audio> of its file (a URL, or a path in public/) trimmed, looped and faded as the film says
|
|
126
|
-
* outside the Series of scenes, so its frames are the film's:
|
|
126
|
+
* <Html5Audio> of its file (a URL, or a path in public/) trimmed, looped and faded as the film says; with `film.voice`, its narration too,
|
|
127
|
+
* the sounds with `duck` sunk under it. Place it once in the composition, outside the Series of scenes, so its frames are the film's:
|
|
128
|
+
* `<FilmAudio component={Main} film={film} />`.
|
|
127
129
|
*/
|
|
128
130
|
export const FilmAudio = ({component, film = NO_FILM}) => {
|
|
129
131
|
const plans = useMemo(() => filmSounds(component, film), [component, film]);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionhub/remotion",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Use a motion from motionhub.dev in Remotion: its React components as they are, and its tokens as Remotion values.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/motionhubdev/motionhub.git",
|
|
9
9
|
"directory": "packages/remotion"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://motionhub.dev",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@motionhub/runtime": "^0.6.0 || ^0.7.0",
|
|
29
|
+
"@motionhub/runtime": "^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0",
|
|
30
30
|
"react-dom": ">=18",
|
|
31
31
|
"react": ">=18",
|
|
32
32
|
"remotion": ">=4.0.530"
|