Skip to content

🎥 Make videos programmatically with React

Add boolean keyframes and motion blur disable control

Jonny Burgerf10213d96c07
diff --git a/packages/core/src/interpolate-keyframed-status.ts b/packages/core/src/interpolate-keyframed-status.ts
index 1d64efc2ff..f944cc4885 100644
--- a/packages/core/src/interpolate-keyframed-status.ts
+++ b/packages/core/src/interpolate-keyframed-status.ts
@@ -15,6 +15,7 @@ import type {
type InterpolateKeyframedStatusResult =
| number
| string
+ | boolean
| readonly number[]
| null;
@@ -144,7 +145,7 @@ export const interpolateKeyframedStatus = ({
return interpolate(
frame,
inputRange,
- outputs as (number | string | number[])[],
+ outputs as (number | string | boolean | number[])[],
{
easing: easing.map((e) =>
easingToFn({easing: e, forceSpringAllowTail}),
diff --git a/packages/core/src/interpolate.ts b/packages/core/src/interpolate.ts
index 63adb4e76b..a5037a332d 100644
--- a/packages/core/src/interpolate.ts
+++ b/packages/core/src/interpolate.ts
@@ -54,7 +54,7 @@ type TransformOriginAxisValue = {
};
type NumericTuple = readonly [number, ...number[]];
-type InterpolateOutputValue = number | string | readonly number[];
+type InterpolateOutputValue = number | string | boolean | readonly number[];
type WidenNumericTuple<T extends readonly number[]> = {
readonly [Key in keyof T]: number;
};
@@ -989,7 +989,7 @@ const interpolateFontWeight = ({
});
};
-const interpolateDiscreteString = ({
+const interpolateDiscreteValue = <Value extends string | boolean>({
input,
inputRange,
outputRange,
@@ -997,9 +997,9 @@ const interpolateDiscreteString = ({
}: {
input: number;
inputRange: readonly number[];
- outputRange: readonly string[];
+ outputRange: readonly Value[];
options: InterpolateOptions | undefined;
-}): string => {
+}): Value => {
if (inputRange.length === 1) {
return outputRange[0];
}
@@ -1016,7 +1016,9 @@ const interpolateDiscreteString = ({
}) !== Easing.step1
) {
throw new TypeError(
- 'Non-numeric strings can only be interpolated using Easing.step1',
+ typeof outputRange[0] === 'boolean'
+ ? 'Booleans can only be interpolated using Easing.step1'
+ : 'Non-numeric strings can only be interpolated using Easing.step1',
);
}
}
@@ -1032,7 +1034,9 @@ const interpolateDiscreteString = ({
if (resolvedInput < inputMin) {
if (options?.extrapolateLeft === 'identity') {
throw new TypeError(
- 'extrapolateLeft: "identity" is not supported for non-numeric strings',
+ typeof outputRange[0] === 'boolean'
+ ? 'extrapolateLeft: "identity" is not supported for booleans'
+ : 'extrapolateLeft: "identity" is not supported for non-numeric strings',
);
}
@@ -1049,7 +1053,9 @@ const interpolateDiscreteString = ({
if (resolvedInput > inputMax) {
if (options?.extrapolateRight === 'identity') {
throw new TypeError(
- 'extrapolateRight: "identity" is not supported for non-numeric strings',
+ typeof outputRange[0] === 'boolean'
+ ? 'extrapolateRight: "identity" is not supported for booleans'
+ : 'extrapolateRight: "identity" is not supported for non-numeric strings',
);
}
@@ -1257,6 +1263,12 @@ export function interpolate(
outputRange: readonly string[],
options?: InterpolateOptions,
): string;
+export function interpolate(
+ input: number,
+ inputRange: readonly number[],
+ outputRange: readonly boolean[],
+ options?: InterpolateOptions,
+): boolean;
export function interpolate<const Tuple extends NumericTuple>(
input: number,
inputRange: readonly number[],
@@ -1272,15 +1284,15 @@ export function interpolate(
export function interpolate(
input: number,
inputRange: readonly number[],
- outputRange: readonly (number | string | readonly number[])[],
+ outputRange: readonly InterpolateOutputValue[],
options?: InterpolateOptions,
-): number | string | readonly number[];
+): number | string | boolean | readonly number[];
export function interpolate(
input: number,
inputRange: readonly number[],
outputRange: readonly InterpolateOutputValue[],
options?: InterpolateOptions,
-): number | string | readonly number[] {
+): number | string | boolean | readonly number[] {
if (typeof input === 'undefined') {
throw new Error('input can not be undefined');
}
@@ -1320,6 +1332,23 @@ export function interpolate(
}
const outputType = options?.outputType;
+ if (outputRange.some((output) => typeof output === 'boolean')) {
+ if (!outputRange.every((output) => typeof output === 'boolean')) {
+ throw new TypeError('Boolean outputRange must contain only booleans');
+ }
+
+ if (outputType !== undefined) {
+ throw new TypeError('Boolean outputRange cannot use outputType');
+ }
+
+ return interpolateDiscreteValue({
+ input,
+ inputRange,
+ outputRange,
+ options,
+ });
+ }
+
if (outputType === 'font-weight') {
if (
!outputRange.every(
@@ -1384,7 +1413,7 @@ export function interpolate(
throw error;
}
- return interpolateDiscreteString({
+ return interpolateDiscreteValue({
input,
inputRange,
outputRange,
diff --git a/packages/docs/docs/interactivity-schema.mdx b/packages/docs/docs/interactivity-schema.mdx
index e28e07b534..09eb42d6cd 100644
--- a/packages/docs/docs/interactivity-schema.mdx
+++ b/packages/docs/docs/interactivity-schema.mdx
@@ -262,6 +262,8 @@ Controls whether the field can be animated with keyframes.
Default: `true` for `number`, `boolean`, `rotation-css`, `rotation-degrees`, `translate`, `transform-origin`, `scale`, `uv-coordinate` and `color` fields.
+Boolean fields use hold keyframes: their value changes at the next keyframe without blending. Boolean keyframes are available from <AvailableFrom v="4.0.530" inline />.
+
`array` and `font-family` fields are not keyframable. Fields inside an `enum` variant schema can still be keyframed according to their own `keyframable` setting.
`enum` fields are not keyframable by default. From <AvailableFrom v="4.0.509" inline />, set `keyframable: true` to enable hold keyframes. Remotion Studio generates [`Easing.step1`](/docs/easing#step1) segments because enum values cannot be blended.
diff --git a/packages/docs/docs/interpolate.mdx b/packages/docs/docs/interpolate.mdx
index 5b02cdb381..8d77cc2269 100644
--- a/packages/docs/docs/interpolate.mdx
+++ b/packages/docs/docs/interpolate.mdx
@@ -194,6 +194,21 @@ const cursor = interpolate(frame, [0, 100], ['default', 'ne-resize'], {
Every segment must use `Easing.step1`. If `easing` is an array, each entry must be `Easing.step1`.
+## Example: Boolean values<AvailableFrom v="4.0.530" />
+
+Use `Easing.step1` to switch a boolean at a keyframe. The previous value is held until the next keyframe.
+
+```tsx twoslash title="MyComposition.tsx"
+import {Easing, interpolate, useCurrentFrame} from 'remotion';
+
+const frame = useCurrentFrame();
+const disabled = interpolate(frame, [0, 60], [false, true], {
+ easing: Easing.step1,
+});
+```
+
+All output values must be booleans, and every segment must use `Easing.step1`.
+
## Example: Numeric tuples<AvailableFrom v="4.0.473" />
`outputRange` may contain numeric tuples.
diff --git a/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
index 8e4d14e716..d47ef13222 100644
--- a/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
+++ b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
@@ -95,6 +95,11 @@ See [Timing and trimming](/docs/timing) for how these props combine.
How many snapshots are averaged. Default: `8`, min: `1`, max: `64`.
Higher values make the blur smoother but cost more work during preview and rendering.
+### `disabled?`<AvailableFrom v="4.0.530" />
+
+Disable motion blur while keeping the content inside `<HtmlInCanvas>`. Default: `false`.
+When `true`, the component captures one sample at the current frame. You can keyframe this prop in Remotion Studio to turn motion blur on or off without remounting the canvas.
+
### `shutterAngle?`
How long the exposure is, expressed as an angle from `0` to `360`. Default: `180`.
diff --git a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
index 6b8deb976e..245c55ec20 100644
--- a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
+++ b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
@@ -2,11 +2,11 @@ import React, {useCallback} from 'react';
import {
Freeze,
HtmlInCanvas,
- Internals,
+ type HtmlInCanvasOnPaint,
Interactive,
type InteractiveBaseProps,
type InteractivitySchema,
- type HtmlInCanvasOnPaint,
+ Internals,
type SequenceControls,
useCurrentFrame,
useVideoConfig,
@@ -18,6 +18,7 @@ export type HtmlInCanvasMotionBlurProps = InteractiveBaseProps & {
readonly height: number;
readonly shutterAngle?: number;
readonly samples?: number;
+ readonly disabled?: boolean;
};
const htmlInCanvasMotionBlurSchema = {
@@ -42,6 +43,11 @@ const htmlInCanvasMotionBlurSchema = {
hiddenFromList: false,
keyframable: false,
},
+ disabled: {
+ type: 'boolean',
+ default: false,
+ description: 'Disabled',
+ },
} as const satisfies InteractivitySchema;
type MotionBlurSampleProps = {
@@ -103,6 +109,7 @@ const HtmlInCanvasMotionBlurInner: React.FC<
height,
shutterAngle = 180,
samples = 8,
+ disabled = false,
from,
durationInFrames,
trimBefore,
@@ -133,7 +140,8 @@ const HtmlInCanvasMotionBlurInner: React.FC<
);
}
- const actualSamples = shutterAngle === 0 ? 1 : samples;
+ // Keep the first sample mounted when blur is disabled so the canvas stays visible.
+ const actualSamples = disabled || shutterAngle === 0 ? 1 : samples;
const shutterInFrames = (shutterAngle / 360) * (playbackRate ?? 1);
const firstFrame = trimBefore ?? 0;
const visibleDuration = Math.max(
diff --git a/packages/studio-shared/src/keyframe-clipboard-data.ts b/packages/studio-shared/src/keyframe-clipboard-data.ts
index ef4c447a0f..533b19e9b0 100644
--- a/packages/studio-shared/src/keyframe-clipboard-data.ts
+++ b/packages/studio-shared/src/keyframe-clipboard-data.ts
@@ -10,7 +10,7 @@ import type {KeyframeEasing} from './keyframe-easing-presets';
const KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT = {
array: false,
asset: false,
- boolean: false,
+ boolean: true,
'remotion-captions': false,
color: true,
enum: false,
diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.ts
index 807c1b8776..890f7e837b 100644
--- a/packages/studio-shared/src/keyframe-interpolation-function.ts
+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts
@@ -18,7 +18,7 @@ export type KeyframeInterpolationFunction =
const KEYFRAME_FIELD_TYPE_SUPPORT = {
array: false,
asset: false,
- boolean: false,
+ boolean: true,
'remotion-captions': false,
color: true,
enum: true,
@@ -44,7 +44,7 @@ type KeyframeInterpolationStrategy =
const KEYFRAME_FIELD_TYPE_INTERPOLATION = {
array: 'unsupported',
asset: 'unsupported',
- boolean: 'unsupported',
+ boolean: 'interpolate',
'remotion-captions': 'unsupported',
color: 'interpolateColors',
enum: 'interpolate',
@@ -167,6 +167,7 @@ export const isSchemaFieldHoldOnly = ({
}): boolean => {
const field = schema ? findFieldInSchema(schema, key) : undefined;
return (
+ (field?.type === 'boolean' && field.keyframable !== false) ||
(field?.type === 'enum' && field.keyframable === true) ||
(field?.type === 'number' &&
field.integer === true &&
diff --git a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
index 66879f4cb6..9e4fb33c51 100644
--- a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
@@ -33,8 +33,8 @@ import {
} from '../Timeline/call-delete-keyframe';
import {callMoveKeyframes} from '../Timeline/call-move-keyframe';
import {
- getKeyframePlaybackRate,
getKeyframeDisplayOffset,
+ getKeyframePlaybackRate,
getKeyframeSourceFrame,
} from '../Timeline/get-timeline-keyframes';
import {parseKeyframeFieldFromNodePath} from '../Timeline/parse-keyframe-field-from-node-path';
@@ -47,11 +47,11 @@ import {
import {TimelineSequenceKeyframedValue} from '../Timeline/TimelineSequencePropItem';
import {canEditEasingForInterpolationFunction} from '../Timeline/update-selected-easing';
import {
- InspectorQuickActionsSection,
InspectorBackAction,
InspectorDetailRow,
- InspectorQuickAction,
InspectorMessage,
+ InspectorQuickAction,
+ InspectorQuickActionsSection,
} from './common';
import {clampInspectorKeyframeDisplayFrame} from './keyframe-inspector-frame';
import {KeyframeEasingNavigator} from './KeyframeEasingNavigator';
@@ -538,9 +538,12 @@ export const KeyframeInspector: React.FC<{
</InspectorBackAction>
<KeyframeEasingNavigator
currentSelection={selection}
- includeEasings={canEditEasingForInterpolationFunction(
- details.propStatus.interpolationFunction,
- )}
+ includeEasings={
+ details.field.fieldSchema.type !== 'boolean' &&
+ canEditEasingForInterpolationFunction(
+ details.propStatus.interpolationFunction,
+ )
+ }
keyframes={details.propStatus.keyframes.map((keyframe) => ({
...keyframe,
frame:
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index f5617eaf60..b9b13c6fc8 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -1,13 +1,13 @@
-import {
- CanvasInternals,
- getCanvasSelectionItemKey,
- useCanvasSelection,
-} from '@remotion/canvas';
import type {
CanvasSelectionInteraction,
CanvasSelectionItem,
CanvasSelectionSnapshot,
} from '@remotion/canvas';
+import {
+ CanvasInternals,
+ getCanvasSelectionItemKey,
+ useCanvasSelection,
+} from '@remotion/canvas';
import {
canEditEasingForInterpolationFunction,
stringifySequenceExpandedRowKey,
@@ -656,7 +656,11 @@ const getTimelineTreeNodeCanEditEasing = ({
readonly nodePathInfo: SequenceNodePathInfo;
readonly propStatuses: PropStatuses;
}) => {
- if (node.kind !== 'field' || node.field === null) {
+ if (
+ node.kind !== 'field' ||
+ node.field === null ||
+ node.field.fieldSchema.type === 'boolean'
+ ) {
return false;
}
diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
index 52a8bcca5a..7c62cf12ad 100644
--- a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
@@ -83,7 +83,11 @@ const getNodeCanEditEasing = ({
nodePath: Parameters<typeof getNodeKeyframes>[0]['nodePath'];
propStatuses: Parameters<typeof getNodeKeyframes>[0]['propStatuses'];
}) => {
- if (node.kind !== 'field' || node.field === null) {
+ if (
+ node.kind !== 'field' ||
+ node.field === null ||
+ node.field.fieldSchema.type === 'boolean'
+ ) {
return false;
}