🎥 Make videos programmatically with React
pretty cool
JonnyBurger68795285a4c0
diff --git a/packages/canvas-effects/src/blur/blur-horizontal.ts b/packages/canvas-effects/src/blur/blur-horizontal.tsindex 4a10d26422..471228004c 100644--- a/packages/canvas-effects/src/blur/blur-horizontal.ts+++ b/packages/canvas-effects/src/blur/blur-horizontal.ts@@ -13,6 +13,7 @@ export type BlurHorizontalParams = {const blurHorizontalDef = defineEffect<BlurHorizontalParams, BlurState>({type: 'remotion/blur-horizontal',+ label: 'Blur (horizontal)',backend: 'webgl2',setup: (target) => setupBlur(target, BLUR_FS_HORIZONTAL),apply: ({source, width, height, params, state}) => {diff --git a/packages/canvas-effects/src/blur/blur-vertical.ts b/packages/canvas-effects/src/blur/blur-vertical.tsindex 7f9e3338d4..af299e3004 100644--- a/packages/canvas-effects/src/blur/blur-vertical.ts+++ b/packages/canvas-effects/src/blur/blur-vertical.ts@@ -13,6 +13,7 @@ export type BlurVerticalParams = {const blurVerticalDef = defineEffect<BlurVerticalParams, BlurState>({type: 'remotion/blur-vertical',+ label: 'Blur (vertical)',backend: 'webgl2',setup: (target) => setupBlur(target, BLUR_FS_VERTICAL),apply: ({source, width, height, params, state}) => {diff --git a/packages/canvas-effects/src/halftone.ts b/packages/canvas-effects/src/halftone.tsindex 6603aefde0..7ec356d8cb 100644--- a/packages/canvas-effects/src/halftone.ts+++ b/packages/canvas-effects/src/halftone.ts@@ -1,7 +1,47 @@+import type {SequenceSchema} from 'remotion';import {createDescriptor, defineEffect} from 'remotion';const SHADE_OUTSIDE_DOT_SCALE = 0.5;+export const halftoneSchema = {+ dotSize: {+ type: 'number',+ min: 1,+ max: 200,+ step: 1,+ default: 20,+ description: 'Dot size',+ },+ dotSpacing: {+ type: 'number',+ min: 1,+ max: 200,+ step: 1,+ default: 20,+ description: 'Dot spacing',+ },+ rotation: {+ type: 'number',+ min: -180,+ max: 180,+ step: 1,+ default: 0,+ description: 'Rotation',+ },+ offsetX: {+ type: 'number',+ step: 1,+ default: 0,+ description: 'Offset X',+ },+ offsetY: {+ type: 'number',+ step: 1,+ default: 0,+ description: 'Offset Y',+ },+} as const satisfies SequenceSchema;+export type HalftoneShape = 'circle' | 'square' | 'line';export type HalftoneSampling = 'bilinear' | 'nearest';@@ -223,6 +263,7 @@ const parseColorRgba = (const halftoneDef = defineEffect<HalftoneParams, HalftoneState>({type: 'remotion/halftone',+ label: 'Halftone',backend: 'webgl2',setup: (target) => {const gl = target.getContext('webgl2', {@@ -365,7 +406,7 @@ const halftoneDef = defineEffect<HalftoneParams, HalftoneState>({gl.deleteVertexArray(vao);gl.deleteTexture(texture);},- schema: null,+ schema: halftoneSchema,});// Halftone effect (WebGL2). Converts luminance into a grid of dots, squares,diff --git a/packages/canvas-effects/src/tint.ts b/packages/canvas-effects/src/tint.tsindex 9468b86f4a..f24a6e3c48 100644--- a/packages/canvas-effects/src/tint.ts+++ b/packages/canvas-effects/src/tint.ts@@ -19,6 +19,7 @@ export type TintParams = {const tintDef = defineEffect<TintParams, null>({type: 'remotion/tint',+ label: 'Tint',backend: '2d',setup: () => null,apply: ({source, target, width, height, params}) => {diff --git a/packages/canvas-effects/src/wave.ts b/packages/canvas-effects/src/wave.tsindex bdc6a57c2c..be4c255e87 100644--- a/packages/canvas-effects/src/wave.ts+++ b/packages/canvas-effects/src/wave.ts@@ -26,6 +26,7 @@ const resolve = (p: WaveParams): WaveResolved => ({const waveDef = defineEffect<WaveParams, null>({type: 'remotion/wave',+ label: 'Wave',backend: '2d',setup: () => null,apply: ({source, target, frame, width, height, params}) => {diff --git a/packages/core/src/canvas-effects/effect-types.ts b/packages/core/src/canvas-effects/effect-types.tsindex 986f6f306d..f9a1df900b 100644--- a/packages/core/src/canvas-effects/effect-types.ts+++ b/packages/core/src/canvas-effects/effect-types.ts@@ -32,6 +32,7 @@ export type EffectApplyParams<P, S> = {export type EffectDefinition<P, S = unknown> = {readonly type: string;+ readonly label: string;readonly backend: Backend;readonly setup: (target: HTMLCanvasElement) => S | Promise<S>;readonly apply: (params: EffectApplyParams<P, S>) => void | Promise<void>;diff --git a/packages/core/src/test/effect-internals.test.ts b/packages/core/src/test/effect-internals.test.tsindex f32d6ee60a..e4b25024bc 100644--- a/packages/core/src/test/effect-internals.test.ts+++ b/packages/core/src/test/effect-internals.test.ts@@ -14,6 +14,7 @@ const makeDef = (backend: Backend,): EffectDefinition<unknown, unknown> => ({type,+ label: type,backend,setup: () => null,apply: () => undefined,diff --git a/packages/example/src/NewVideo.tsx b/packages/example/src/NewVideo.tsxindex 39390b315c..d6f46a0a4c 100644--- a/packages/example/src/NewVideo.tsx+++ b/packages/example/src/NewVideo.tsx@@ -24,7 +24,7 @@ export const Component = () => {<Videosrc={src}debugOverlay- effects={[halftone(), tint({color: 'green', amount: 0.1})]}+ effects={[halftone(), tint({color: 'green', amount: 1})]}/>);};diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsxindex d3be8c63e4..0108b68460 100644--- a/packages/studio/src/components/Timeline/Timeline.tsx+++ b/packages/studio/src/components/Timeline/Timeline.tsx@@ -92,7 +92,7 @@ const TimelineInner: React.FC = () => {getTimelineLayerHeight(track.sequence.type) +Number(TIMELINE_ITEM_BORDER_BOTTOM) +(isExpanded- ? getExpandedTrackHeight(track.sequence.controls) ++ ? getExpandedTrackHeight(track.sequence, expandedTracks) +TIMELINE_ITEM_BORDER_BOTTOM: 0));diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsxindex fca0b6b40f..54d9c99a89 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx@@ -1,19 +1,26 @@import type {SequenceNodePath} from '@remotion/studio-shared';-import React, {useMemo} from 'react';+import React, {useCallback, useContext, useMemo} from 'react';import type {TSequence} from 'remotion';import type {CodePosition,OriginalPosition,} from '../../error-overlay/react-overlay/utils/get-source-map';import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';+import type {TimelineTreeNode} from '../../helpers/timeline-layout';import {+ buildTimelineTree,+ EXPANDED_SECTION_PADDING_LEFT,+ EXPANDED_SECTION_PADDING_RIGHT,+ flattenVisibleTreeNodes,getExpandedTrackHeight,getSchemaFields,+ getTreeRowHeight,+ TREE_GROUP_ROW_HEIGHT,+ TREE_INDENT_PER_LEVEL,} from '../../helpers/timeline-layout';+import {ExpandedTracksContext} from '../ExpandedTracksProvider';import {TimelineFieldRow} from './TimelineFieldRow';--export const EXPANDED_SECTION_PADDING_LEFT = 28;-export const EXPANDED_SECTION_PADDING_RIGHT = 10;+import {SPACING} from './TimelineListItem';const expandedSectionBase: React.CSSProperties = {color: 'white',@@ -29,17 +36,70 @@ const separator: React.CSSProperties = {backgroundColor: TIMELINE_TRACK_SEPARATOR,};+const arrowButtonBase: React.CSSProperties = {+ background: 'none',+ border: 'none',+ color: 'white',+ cursor: 'pointer',+ padding: 0,+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ width: 12,+ height: 12,+ flexShrink: 0,+ fontSize: 8,+ marginRight: 6,+ userSelect: 'none',+ outline: 'none',+ lineHeight: 1,+};++const groupRowBase: React.CSSProperties = {+ height: TREE_GROUP_ROW_HEIGHT,+ display: 'flex',+ alignItems: 'center',+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+ cursor: 'pointer',+};++const rowLabel: React.CSSProperties = {+ fontSize: 12,+ color: 'rgba(255, 255, 255, 0.8)',+ userSelect: 'none',+};++const labelOnlyRowBase: React.CSSProperties = {+ display: 'flex',+ alignItems: 'center',+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+};++const Arrow: React.FC<{readonly isExpanded: boolean}> = ({isExpanded}) => {+ return (+ <svg+ width="12"+ height="12"+ viewBox="0 0 8 8"+ style={{+ display: 'block',+ transform: isExpanded ? 'rotate(90deg)' : 'rotate(0deg)',+ }}+ >+ <path d="M2 1L6 4L2 7Z" fill="white" />+ </svg>+ );+};+export const TimelineExpandedSection: React.FC<{readonly sequence: TSequence;readonly originalLocation: OriginalPosition | null;readonly nestedDepth: number;readonly nodePath: SequenceNodePath | null;}> = ({sequence, originalLocation, nestedDepth, nodePath}) => {+ const {expandedTracks, toggleTrack} = useContext(ExpandedTracksContext);+const overrideId = sequence.controls?.overrideId ?? sequence.id;- const schemaFields = useMemo(- () => getSchemaFields(sequence.controls),- [sequence.controls],- );const validatedLocation: CodePosition | null = useMemo(() => {if (@@ -57,11 +117,29 @@ export const TimelineExpandedSection: React.FC<{};}, [originalLocation]);+ const tree = useMemo(() => buildTimelineTree(sequence), [sequence]);++ const flat = useMemo(+ () => flattenVisibleTreeNodes(tree, expandedTracks),+ [tree, expandedTracks],+ );+const expandedHeight = useMemo(- () => getExpandedTrackHeight(sequence.controls),- [sequence.controls],+ () => getExpandedTrackHeight(sequence, expandedTracks),+ [sequence, expandedTracks],);+ const sequenceOffsetPx = SPACING * 3 * nestedDepth;++ const keysToObserve = useMemo(() => {+ const fields = getSchemaFields(sequence.controls);+ if (!fields) {+ return [];+ }++ return fields.map((f) => f.key);+ }, [sequence.controls]);+const style = useMemo(() => {return {...expandedSectionBase,@@ -69,33 +147,81 @@ export const TimelineExpandedSection: React.FC<{};}, [expandedHeight]);- const keysToObserve = useMemo(() => {- if (!schemaFields) {- return [];- }+ const renderRow = useCallback(+ (node: TimelineTreeNode, depth: number) => {+ const paddingLeft =+ EXPANDED_SECTION_PADDING_LEFT ++ depth * TREE_INDENT_PER_LEVEL ++ sequenceOffsetPx;++ if (node.kind === 'group') {+ const isExpanded = expandedTracks[node.id] ?? false;+ return (+ <div+ role="button"+ tabIndex={0}+ style={{...groupRowBase, paddingLeft}}+ onClick={() => toggleTrack(node.id)}+ aria-expanded={isExpanded}+ >+ <span style={arrowButtonBase}>+ <Arrow isExpanded={isExpanded} />+ </span>+ <span style={rowLabel}>{node.label}</span>+ </div>+ );+ }++ if (node.field) {+ return (+ <TimelineFieldRow+ field={node.field}+ overrideId={overrideId}+ validatedLocation={validatedLocation}+ paddingLeft={paddingLeft}+ nodePath={nodePath}+ keysToObserve={keysToObserve}+ />+ );+ }++ return (+ <div+ style={{+ ...labelOnlyRowBase,+ height: getTreeRowHeight(node),+ paddingLeft,+ }}+ >+ <span style={rowLabel}>{node.label}</span>+ </div>+ );+ },+ [+ expandedTracks,+ keysToObserve,+ nodePath,+ overrideId,+ sequenceOffsetPx,+ toggleTrack,+ validatedLocation,+ ],+ );- return schemaFields.map((f) => f.key);- }, [schemaFields]);+ if (flat.length === 0) {+ return <div style={style}>No schema</div>;+ }return (<div style={style}>- {schemaFields- ? schemaFields.map((field, i) => {- return (- <React.Fragment key={field.key}>- {i > 0 ? <div style={separator} /> : null}- <TimelineFieldRow- field={field}- overrideId={overrideId}- validatedLocation={validatedLocation}- nestedDepth={nestedDepth}- nodePath={nodePath}- keysToObserve={keysToObserve}- />- </React.Fragment>- );- })- : 'No schema'}+ {flat.map(({node, depth}, i) => {+ return (+ <React.Fragment key={node.id}>+ {i > 0 ? <div style={separator} /> : null}+ {renderRow(node, depth)}+ </React.Fragment>+ );+ })}</div>);};diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsxindex 569f46db59..5e3c3518cd 100644--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx@@ -1,19 +1,13 @@import type {SequenceNodePath} from '@remotion/studio-shared';import React, {useCallback, useContext, useMemo} from 'react';-import {Internals} from 'remotion';import type {CanUpdateSequencePropStatus} from 'remotion';+import {Internals} from 'remotion';import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';import type {SchemaFieldInfo} from '../../helpers/timeline-layout';+import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';import {callApi} from '../call-api';-import {- EXPANDED_SECTION_PADDING_LEFT,- EXPANDED_SECTION_PADDING_RIGHT,-} from './TimelineExpandedSection';-import {SPACING} from './TimelineListItem';import {TimelineFieldValue} from './TimelineSchemaField';-const FIELD_ROW_PADDING_LEFT = 24;-const fieldRowBase: React.CSSProperties = {display: 'flex',alignItems: 'center',@@ -39,14 +33,14 @@ export const TimelineFieldRow: React.FC<{readonly field: SchemaFieldInfo;readonly overrideId: string;readonly validatedLocation: CodePosition | null;- readonly nestedDepth: number;+ readonly paddingLeft: number;readonly nodePath: SequenceNodePath | null;readonly keysToObserve: string[];}> = ({field,overrideId,validatedLocation,- nestedDepth,+ paddingLeft,nodePath,keysToObserve,}) => {@@ -141,12 +135,9 @@ export const TimelineFieldRow: React.FC<{return {...fieldRowBase,height: field.rowHeight,- paddingLeft:- EXPANDED_SECTION_PADDING_LEFT +- FIELD_ROW_PADDING_LEFT +- SPACING * 3 * nestedDepth,+ paddingLeft,};- }, [field.rowHeight, nestedDepth]);+ }, [field.rowHeight, paddingLeft]);return (<div style={style}>diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsxindex 6685bd877b..3b1aea27c7 100644--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx@@ -244,6 +244,9 @@ export const TimelineListItem: React.FC<{};}, [isExpanded]);+ const hasExpandableContent =+ Boolean(sequence.controls) || sequence.effects.length > 0;+const trackRow = (<div style={outer}><TimelineLayerEye@@ -254,7 +257,7 @@ export const TimelineListItem: React.FC<{<div style={padder} />{sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}{visualModeActive ? (- sequence.controls ? (+ hasExpandableContent ? (<buttontype="button"style={arrowStyle}@@ -290,7 +293,7 @@ export const TimelineListItem: React.FC<{) : (trackRow)}- {visualModeActive && isExpanded && sequence.controls ? (+ {visualModeActive && isExpanded && hasExpandableContent ? (<TimelineExpandedSectionsequence={sequence}originalLocation={originalLocation}diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsxindex 928ae0ad3c..8839329c8e 100644--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx@@ -1,5 +1,5 @@import React, {useContext, useMemo} from 'react';-import type {SequenceControls} from 'remotion';+import type {TSequence} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';import {@@ -25,9 +25,12 @@ const timelineContent: React.CSSProperties = {};const getExpandedPlaceholderStyle = (- controls: SequenceControls | null,+ sequence: TSequence,+ expandedTracks: Record<string, boolean>,): React.CSSProperties => ({- height: getExpandedTrackHeight(controls) + TIMELINE_ITEM_BORDER_BOTTOM,+ height:+ getExpandedTrackHeight(sequence, expandedTracks) ++ TIMELINE_ITEM_BORDER_BOTTOM,});export const TimelineTracks: React.FC<{@@ -71,7 +74,10 @@ export const TimelineTracks: React.FC<{</div>{visualModeEnabled && isExpanded ? (<div- style={getExpandedPlaceholderStyle(track.sequence.controls)}+ style={getExpandedPlaceholderStyle(+ track.sequence,+ expandedTracks,+ )}/>) : null}</div>diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.tsindex 4811530275..d81c5f2a2c 100644--- a/packages/studio/src/helpers/timeline-layout.ts+++ b/packages/studio/src/helpers/timeline-layout.ts@@ -1,4 +1,9 @@-import type {SequenceControls, SequenceFieldSchema} from 'remotion';+import type {+ EffectDefinitionAndStack,+ SequenceControls,+ SequenceFieldSchema,+ TSequence,+} from 'remotion';export const TIMELINE_PADDING = 16;export const TIMELINE_BORDER = 1;@@ -8,6 +13,10 @@ export const TIMELINE_TRACK_EXPANDED_HEIGHT = 100;export const SCHEMA_FIELD_ROW_HEIGHT = 22;export const UNSUPPORTED_FIELD_ROW_HEIGHT = 22;+export const TREE_GROUP_ROW_HEIGHT = 22;+export const TREE_INDENT_PER_LEVEL = 16;+export const EXPANDED_SECTION_PADDING_LEFT = 28;+export const EXPANDED_SECTION_PADDING_RIGHT = 10;const SUPPORTED_SCHEMA_TYPES = new Set(['number',@@ -50,16 +59,133 @@ export const getSchemaFields = (});};+export type EffectSchemaFieldLabel = {+ key: string;+ description: string | undefined;+};++export const getEffectSchemaLabels = (+ effect: EffectDefinitionAndStack<unknown>,+): EffectSchemaFieldLabel[] => {+ if (!effect.definition.schema) {+ return [];+ }++ return Object.entries(effect.definition.schema).map(([key, fieldSchema]) => ({+ key,+ description: fieldSchema.description,+ }));+};++export type TimelineTreeNode =+ | {+ readonly kind: 'group';+ readonly id: string;+ readonly label: string;+ readonly children: TimelineTreeNode[];+ }+ | {+ readonly kind: 'field';+ readonly id: string;+ readonly label: string;+ readonly field: SchemaFieldInfo | null;+ };++export const buildTimelineTree = (sequence: TSequence): TimelineTreeNode[] => {+ const roots: TimelineTreeNode[] = [];++ if (sequence.effects.length > 0) {+ roots.push({+ kind: 'group',+ id: `${sequence.id}::effects`,+ label: 'Effects',+ children: sequence.effects.map((effect, i): TimelineTreeNode => {+ const effectId = `${sequence.id}::effects::${i}`;+ return {+ kind: 'group',+ id: effectId,+ label: effect.definition.label,+ children: getEffectSchemaLabels(effect).map(+ (label): TimelineTreeNode => ({+ kind: 'field',+ id: `${effectId}::${label.key}`,+ label: label.description ?? label.key,+ field: null,+ }),+ ),+ };+ }),+ });+ }++ const controlFields = getSchemaFields(sequence.controls);+ if (controlFields && controlFields.length > 0) {+ roots.push({+ kind: 'group',+ id: `${sequence.id}::controls`,+ label: 'Controls',+ children: controlFields.map(+ (f): TimelineTreeNode => ({+ kind: 'field',+ id: `${sequence.id}::controls::${f.key}`,+ label: f.description ?? f.key,+ field: f,+ }),+ ),+ });+ }++ return roots;+};++export type FlatTreeRow = {+ readonly node: TimelineTreeNode;+ readonly depth: number;+};++export const flattenVisibleTreeNodes = (+ nodes: TimelineTreeNode[],+ expandedTracks: Record<string, boolean>,+ depth = 0,+): FlatTreeRow[] => {+ const out: FlatTreeRow[] = [];+ for (const node of nodes) {+ out.push({node, depth});+ if (node.kind === 'group' && (expandedTracks[node.id] ?? false)) {+ out.push(+ ...flattenVisibleTreeNodes(node.children, expandedTracks, depth + 1),+ );+ }+ }++ return out;+};++export const getTreeRowHeight = (node: TimelineTreeNode): number => {+ if (node.kind === 'field' && node.field) {+ return node.field.rowHeight;+ }++ return TREE_GROUP_ROW_HEIGHT;+};+export const getExpandedTrackHeight = (- controls: SequenceControls | null,+ sequence: TSequence,+ expandedTracks: Record<string, boolean>,): number => {- const fields = getSchemaFields(controls);- if (!fields || fields.length === 0) {+ const tree = buildTimelineTree(sequence);+ const flat = flattenVisibleTreeNodes(tree, expandedTracks);++ if (flat.length === 0) {return TIMELINE_TRACK_EXPANDED_HEIGHT;}- const separators = Math.max(0, fields.length - 1);- return fields.reduce((sum, f) => sum + f.rowHeight, 0) + separators;+ const totalRowsHeight = flat.reduce(+ (sum, {node}) => sum + getTreeRowHeight(node),+ 0,+ );+ const separators = Math.max(0, flat.length - 1);+ return totalRowsHeight + separators;};export const TIMELINE_LAYER_HEIGHT_VIDEO = 75;