🎥 Make videos programmatically with React
import {expect, test} from 'bun:test';
import {CanvasInternals} from '@remotion/sdk';
import type {TSequence} from 'remotion';
const getStack = () => null;
const withoutKeyframeDisplayOffset = <
T extends {
keyframeDisplayOffset: number;
keyframePlaybackRate: number;
sequenceFrameOffset: number;
cascadedStart: number;
localStart: number;
},
>(
tracks: T[],
) =>
tracks.map(
({
keyframeDisplayOffset,
keyframePlaybackRate,
sequenceFrameOffset,
cascadedStart,
localStart,
...track
}) => {
expect(keyframeDisplayOffset).toBe(0);
expect(sequenceFrameOffset).toBeGreaterThanOrEqual(0);
expect(typeof cascadedStart).toBe('number');
expect(typeof localStart).toBe('number');
return track;
},
);
test('Should calculate sequences correctly', () => {
const calculate = CanvasInternals.createTimelineCalculator();
const timeline = calculate({
sequences,
overrideIdsToNodePaths: {},
}).tracks;
expect(withoutKeyframeDisplayOffset(timeline)).toEqual([
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: null,
sequence: {
from: 0,
trimBefore: null,
duration: 486,
id: '0.3922623481128855',
displayName: 'Sequence',
documentationLink: null,
parent: null,
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
depth: 0,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
from: 0,
trimBefore: null,
duration: 486,
id: '0.9202813365252485',
displayName: 'SynchronizedCode',
documentationLink: null,
parent: '0.3922623481128855',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
depth: 1,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
from: 0,
trimBefore: null,
duration: 0,
id: '0.3568245565495358',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
depth: 2,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
from: 0,
trimBefore: null,
duration: 486,
id: '0.08739205010419449',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
depth: 2,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
type: 'video',
src: 'http://localhost:5000/codep1-2.mp4',
id: '0.640722264073593',
duration: 486,
from: 0,
trimBefore: null,
parent: '0.08739205010419449',
displayName: 'codep1-2.mp4',
documentationLink: null,
loopDisplay: undefined,
premountDisplay: null,
postmountDisplay: null,
controls: null,
playbackRate: 1,
frozenMediaFrame: null,
mediaFrameAtSequenceZero: null,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
showInTimeline: true,
timelineOrder: null,
startMediaFrom: 0,
muted: false,
getStack,
refForOutline: null,
isInsideSeries: false,
},
depth: 3,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
loopDisplay: undefined,
from: 0,
trimBefore: null,
duration: 486,
id: '0.12517304081486258',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
depth: 2,
},
{
nodePathInfo: null,
parentVisibleStart: 0,
parentVisibleEnd: 486,
sequence: {
loopDisplay: undefined,
type: 'video',
src: 'http://localhost:5000/screen3.mp4',
id: '0.5529201074994525',
duration: 486,
from: 0,
trimBefore: null,
parent: '0.12517304081486258',
displayName: 'screen3.mp4',
documentationLink: null,
premountDisplay: null,
postmountDisplay: null,
controls: null,
playbackRate: 1,
frozenMediaFrame: null,
mediaFrameAtSequenceZero: null,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
showInTimeline: true,
timelineOrder: null,
startMediaFrom: 330,
muted: false,
getStack,
refForOutline: null,
isInsideSeries: false,
},
depth: 3,
},
]);
});
const sequences: TSequence[] = [
{
from: 0,
trimBefore: null,
duration: 486,
id: '0.3922623481128855',
displayName: 'Sequence',
documentationLink: null,
parent: null,
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
{
from: 0,
trimBefore: null,
duration: 12000,
id: '0.3568245565495358',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
{
type: 'video',
src: 'http://localhost:5000/codep1-2.mp4',
id: '0.640722264073593',
duration: 10736,
from: 0,
trimBefore: null,
parent: '0.08739205010419449',
displayName: 'codep1-2.mp4',
documentationLink: null,
premountDisplay: null,
postmountDisplay: null,
controls: null,
playbackRate: 1,
frozenMediaFrame: null,
mediaFrameAtSequenceZero: null,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
showInTimeline: true,
timelineOrder: null,
startMediaFrom: 0,
muted: false,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
},
{
from: 12000,
trimBefore: null,
duration: 10736,
id: '0.08739205010419449',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
{
type: 'video',
src: 'http://localhost:5000/screen3.mp4',
id: '0.5529201074994525',
duration: 23066,
from: 0,
trimBefore: null,
parent: '0.12517304081486258',
displayName: 'screen3.mp4',
documentationLink: null,
premountDisplay: null,
postmountDisplay: null,
controls: null,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
playbackRate: 1,
frozenMediaFrame: null,
mediaFrameAtSequenceZero: null,
showInTimeline: true,
timelineOrder: null,
startMediaFrom: 330,
muted: false,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
},
{
from: -330,
trimBefore: null,
duration: 23066,
id: '0.12517304081486258',
displayName: 'Video',
documentationLink: null,
parent: '0.9202813365252485',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
{
from: -22250,
trimBefore: null,
duration: 22736,
id: '0.9202813365252485',
displayName: 'SynchronizedCode',
documentationLink: null,
parent: '0.3922623481128855',
type: 'sequence',
premountDisplay: null,
postmountDisplay: null,
controls: null,
showInTimeline: true,
timelineOrder: null,
getStack,
refForOutline: null,
isInsideSeries: false,
loopDisplay: undefined,
effects: [],
effectRuntimeValues: null,
sequencePlaybackRate: 1,
frozenFrame: null,
},
];