π₯ Make videos programmatically with React
feat(effects): share explicit processing resolution across supported components
Alec Watts81b31b6090c5
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsxindex f2417fe106..53f000a711 100644--- a/packages/core/src/HtmlInCanvas.tsx+++ b/packages/core/src/HtmlInCanvas.tsx@@ -8,7 +8,7 @@ import React, {useRef,} from 'react';import type {SequenceControls} from './CompositionManager.js';-import type {EffectsProp} from './effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from './effects/effect-types.js';import {runEffectChain} from './effects/run-effect-chain.js';import {useEffectChainState} from './effects/use-effect-chain-state.js';import {@@ -450,6 +450,7 @@ export type HtmlInCanvasProps = Omit<InteractiveBaseProps, 'children'> &readonly width: number;readonly height: number;readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;readonly children: React.ReactNode;readonly onPaint?: HtmlInCanvasOnPaint;readonly onInit?: HtmlInCanvasOnInit;@@ -473,6 +474,7 @@ type HtmlInCanvasContentProps = {readonly width: number;readonly height: number;readonly effects: EffectsProp;+ readonly effectsOutputSize: EffectsOutputSize | null;readonly children: React.ReactNode;readonly canvasSiblings: React.ReactNode | null;readonly onPaint: HtmlInCanvasOnPaint | undefined;@@ -491,6 +493,7 @@ const HtmlInCanvasContent = forwardRef<width,height,effects,+ effectsOutputSize,children,canvasSiblings,onPaint,@@ -586,7 +589,7 @@ const HtmlInCanvasContent = forwardRef<[ref, paintTargetMode],);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const memoizedEffects = useMemoizedEffects({effects,@@ -1026,6 +1029,7 @@ const HtmlInCanvasInner = forwardRef<width,height,effects = [],+ effectsOutputSize,children,onPaint,onInit,@@ -1121,6 +1125,7 @@ const HtmlInCanvasInner = forwardRef<width={width}height={height}effects={effects}+ effectsOutputSize={effectsOutputSize ?? null}onPaint={onPaint}onInit={onInit}pixelDensity={pixelDensity}diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsxindex 716f6f653c..07efe8c285 100644--- a/packages/core/src/Img.tsx+++ b/packages/core/src/Img.tsx@@ -14,7 +14,7 @@ import type {CanvasImageProps,} from './canvas-image/props.js';import type {SequenceControls} from './CompositionManager.js';-import type {EffectsProp} from './effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from './effects/effect-types.js';import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';import {Freeze} from './freeze.js';import {getCrossOriginValue} from './get-cross-origin-value.js';@@ -68,6 +68,7 @@ export type ImgProps = NativeImgProps & {readonly onImageError?: (error: Error) => void;readonly src: string;readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;readonly showInTimeline?: boolean;readonly name?: string;} & Omit<InteractiveBaseProps, 'playbackRate'> &@@ -90,6 +91,7 @@ type ImgContentProps = Omit<| 'durationInFrames'| 'freeze'| 'effects'+ | 'effectsOutputSize'| 'premountFor'| 'postmountFor'| 'styleWhilePremounted'@@ -353,7 +355,7 @@ const ImgContent: React.FC<ImgContentProps> = ({);};-type NativeImgInnerProps = Omit<ImgProps, 'effects'> & {+type NativeImgInnerProps = Omit<ImgProps, 'effects' | 'effectsOutputSize'> & {readonly controls: SequenceControls | undefined;};@@ -557,6 +559,7 @@ const ImgInner: React.FC<}> = ({effects = [],+ effectsOutputSize,ref,hidden,name,@@ -648,6 +651,7 @@ const ImgInner: React.FC<height={canvasHeight}fit={canvasFit}effects={effects}+ effectsOutputSize={effectsOutputSize}className={className}style={style}cropLeft={cropLeft}diff --git a/packages/core/src/animated-image/AnimatedImage.tsx b/packages/core/src/animated-image/AnimatedImage.tsxindex 87172bde4e..aa9bd2c15c 100644--- a/packages/core/src/animated-image/AnimatedImage.tsx+++ b/packages/core/src/animated-image/AnimatedImage.tsx@@ -8,7 +8,7 @@ import {useState,} from 'react';import type {SequenceControls} from '../CompositionManager.js';-import type {EffectsProp} from '../effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from '../effects/effect-types.js';import {useMemoizedEffectDefinitions,useMemoizedEffects,@@ -87,6 +87,7 @@ const getCanvasPropsFromSequenceProps = (type AnimatedImageContentProps = RemotionAnimatedImageProps & {readonly effects: EffectsProp;+ readonly effectsOutputSize: EffectsOutputSize | null;readonly controls: SequenceControls | undefined;};@@ -105,6 +106,7 @@ const AnimatedImageContent = forwardRef<fit = 'fill',requestInit,effects,+ effectsOutputSize,controls,...props},@@ -210,6 +212,8 @@ const AnimatedImageContent = forwardRef<continueRender,delayRender,cancelRender,+ effectsOutputSize?.width,+ effectsOutputSize?.height,]);useEffect(() => {@@ -280,6 +284,8 @@ const AnimatedImageContent = forwardRef<width,height,cancelRender,+ effectsOutputSize?.width,+ effectsOutputSize?.height,]);return (@@ -289,6 +295,7 @@ const AnimatedImageContent = forwardRef<height={height}fit={fit}effects={memoizedEffects}+ effectsOutputSize={effectsOutputSize ?? null}{...props}/>);@@ -320,6 +327,7 @@ const AnimatedImageInner = ({cropBottom,requestInit,effects = [],+ effectsOutputSize,controls,ref,...sequenceProps@@ -409,6 +417,7 @@ const AnimatedImageInner = ({{...animatedImageProps}ref={actualRef}effects={effects}+ effectsOutputSize={effectsOutputSize ?? null}controls={controls}/></SequenceContent>diff --git a/packages/core/src/animated-image/canvas.tsx b/packages/core/src/animated-image/canvas.tsxindex fd74e6d856..f2a3c43ac8 100644--- a/packages/core/src/animated-image/canvas.tsx+++ b/packages/core/src/animated-image/canvas.tsx@@ -1,6 +1,9 @@import React, {useCallback, useImperativeHandle, useMemo, useRef} from 'react';import {calculateImageFit} from '../calculate-image-fit.js';-import type {EffectDefinitionAndStack} from '../effects/effect-types.js';+import type {+ EffectDefinitionAndStack,+ EffectsOutputSize,+} from '../effects/effect-types.js';import {runEffectChain} from '../effects/run-effect-chain.js';import {useEffectChainState} from '../effects/use-effect-chain-state.js';import type {AnimatedImageCanvasProps, AnimatedImageFillMode} from './props';@@ -15,6 +18,7 @@ type Props = {readonly style?: React.CSSProperties;readonly effects: EffectDefinitionAndStack<unknown>[];+ readonly effectsOutputSize: EffectsOutputSize | null;} & AnimatedImageCanvasProps;export type AnimatedImageCanvasRef = {@@ -26,9 +30,12 @@ export type AnimatedImageCanvasRef = {const CanvasRefForwardingFunction: React.ForwardRefRenderFunction<AnimatedImageCanvasRef,Props-> = ({width, height, fit, className, style, effects, ...props}, ref) => {+> = (+ {width, height, fit, className, style, effects, effectsOutputSize, ...props},+ ref,+) => {const canvasRef = useRef<HTMLCanvasElement>(null);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const sourceCanvas = useMemo(() => {if (typeof document === 'undefined') {diff --git a/packages/core/src/animated-image/props.ts b/packages/core/src/animated-image/props.tsindex b118d579c0..283bbe1354 100644--- a/packages/core/src/animated-image/props.ts+++ b/packages/core/src/animated-image/props.ts@@ -1,5 +1,5 @@import type {ImageFit} from '../calculate-image-fit.js';-import type {EffectsProp} from '../effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from '../effects/effect-types.js';import type {InteractiveBaseProps,InteractiveCropProps,@@ -33,6 +33,7 @@ export type AnimatedImageProps = InteractiveBaseProps &InteractivePremountProps &RemotionAnimatedImageProps & {readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;};export type AnimatedImageFillMode = ImageFit;diff --git a/packages/core/src/canvas-image/CanvasImage.tsx b/packages/core/src/canvas-image/CanvasImage.tsxindex ff3fe802d9..85ee03290c 100644--- a/packages/core/src/canvas-image/CanvasImage.tsx+++ b/packages/core/src/canvas-image/CanvasImage.tsx@@ -10,7 +10,7 @@ import {} from 'react';import {calculateImageFit} from '../calculate-image-fit.js';import type {SequenceControls} from '../CompositionManager.js';-import type {EffectsProp} from '../effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from '../effects/effect-types.js';import {runEffectChain} from '../effects/run-effect-chain.js';import {useEffectChainState} from '../effects/use-effect-chain-state.js';import {@@ -203,6 +203,7 @@ type CanvasImageContentProps = Pick<| 'width'> & {readonly effects: EffectsProp;+ readonly effectsOutputSize: EffectsOutputSize | null;readonly controls: SequenceControls | undefined;} & CanvasImageCanvasProps;@@ -218,6 +219,7 @@ const CanvasImageContent = forwardRef<height,fit = 'fill',effects,+ effectsOutputSize,controls,onError,className,@@ -238,7 +240,7 @@ const CanvasImageContent = forwardRef<);const [loadedImage, setLoadedImage] = useState<LoadedImage | null>(null);const actualSrc = usePreload(src);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const memoizedEffects = useMemoizedEffects({effects,overrideId: controls?.overrideId ?? null,@@ -529,6 +531,7 @@ const CanvasImageInner = forwardRef<height,fit,effects = [],+ effectsOutputSize,className,style,id,@@ -645,6 +648,7 @@ const CanvasImageInner = forwardRef<height={height}fit={fit}effects={effects}+ effectsOutputSize={effectsOutputSize ?? null}controls={controls}className={className}style={croppedStyle ?? undefined}diff --git a/packages/core/src/canvas-image/props.ts b/packages/core/src/canvas-image/props.tsindex 211f82ff7a..c090cf1886 100644--- a/packages/core/src/canvas-image/props.ts+++ b/packages/core/src/canvas-image/props.ts@@ -1,6 +1,6 @@import type React from 'react';import type {ImageFit} from '../calculate-image-fit.js';-import type {EffectsProp} from '../effects/effect-types.js';+import type {EffectsProp, EffectsOutputSize} from '../effects/effect-types.js';import type {InteractiveBaseProps,InteractiveCropProps,@@ -24,6 +24,7 @@ export type CanvasImageProps = CanvasImageSequenceProps &readonly height?: number;readonly fit?: ImageFit;readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;readonly className?: string;readonly style?: React.CSSProperties;readonly id?: string;diff --git a/packages/core/src/effects/Solid.tsx b/packages/core/src/effects/Solid.tsxindex 38d7ce395c..6bc3077838 100644--- a/packages/core/src/effects/Solid.tsx+++ b/packages/core/src/effects/Solid.tsx@@ -33,7 +33,7 @@ import {useDelayRender} from '../use-delay-render.js';import {usePremounting} from '../use-premounting.js';import type {VideoConfigValues} from '../video-config.js';import {withInteractivitySchema} from '../with-interactivity-schema.js';-import type {EffectsProp} from './effect-types.js';+import type {EffectsProp, EffectsOutputSize} from './effect-types.js';import {runEffectChain} from './run-effect-chain.js';import {useEffectChainState} from './use-effect-chain-state.js';import {@@ -49,6 +49,7 @@ type MandatoryProps = {type OptionalProps = {readonly color: string | undefined;readonly effects: EffectsProp;+ readonly effectsOutputSize: EffectsOutputSize | null;readonly className: string | undefined;readonly style: React.CSSProperties | undefined;readonly pixelDensity: number | undefined;@@ -131,6 +132,7 @@ const SolidInner: React.FC<width,height,effects = [],+ effectsOutputSize = null,className,style,pixelDensity,@@ -165,7 +167,7 @@ const SolidInner: React.FC<return canvas;}, []);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const canvasRef = useCallback((canvas: HTMLCanvasElement | null) => {@@ -271,6 +273,7 @@ const SolidOuter = forwardRef<({effects = [],+ effectsOutputSize = null,controls,color,height,@@ -375,6 +378,7 @@ const SolidOuter = forwardRef<className={className}style={croppedStyle ?? undefined}effects={effects}+ effectsOutputSize={effectsOutputSize}pixelDensity={pixelDensity}/></SequenceContent>diff --git a/packages/core/src/effects/effect-types.ts b/packages/core/src/effects/effect-types.tsindex 8d777f981a..8107990ab6 100644--- a/packages/core/src/effects/effect-types.ts+++ b/packages/core/src/effects/effect-types.ts@@ -84,3 +84,8 @@ export type EffectsProp = ReadonlyArray<EffectDescriptor<unknown>>;export type EffectFactory<P> = {} extends P? (params?: P & {readonly disabled?: boolean}) => EffectDescriptor<unknown>: (params: P & {readonly disabled?: boolean}) => EffectDescriptor<unknown>;++export type EffectsOutputSize = {+ readonly width: number;+ readonly height: number;+};diff --git a/packages/core/src/effects/index.ts b/packages/core/src/effects/index.tsindex f8a2cf5fdc..e1f7440cf1 100644--- a/packages/core/src/effects/index.ts+++ b/packages/core/src/effects/index.ts@@ -7,6 +7,7 @@ export type {EffectDefinitionAndStack,EffectDescriptor,EffectsProp,+ EffectsOutputSize,EffectDefinition,EffectFactory,} from './effect-types.js';diff --git a/packages/core/src/effects/run-effect-chain.ts b/packages/core/src/effects/run-effect-chain.tsindex 9970352b97..4253ac90e6 100644--- a/packages/core/src/effects/run-effect-chain.ts+++ b/packages/core/src/effects/run-effect-chain.ts@@ -7,6 +7,8 @@ import type {import {getGpuDevice} from './gpu-device.js';export type EffectChainState = {+ readonly width: number;+ readonly height: number;pool: CanvasPool;setupCache: WeakMap<EffectDefinition<unknown, unknown>,@@ -25,6 +27,8 @@ export const createEffectChainState = (height: number,): EffectChainState => {const state: EffectChainState = {+ width,+ height,pool: new CanvasPool(width, height, (canvas) => {// The GL objects these setups hold died with the context and stay// invalid on a restored one, so the next run has to recreate them.@@ -104,14 +108,10 @@ export type RunEffectChainOptions = {// Runs the effect pipeline imperatively. Returns `true` if the pipeline// completed and wrote to `output`, `false` if it was superseded by a newer// run (caller should not act on a stale result).-export const runEffectChain = async ({- state,- source,- effects,- output,- width,- height,-}: RunEffectChainOptions): Promise<boolean> => {+const runEffectChainWithoutResize = async (+ {state, source, effects, output, width, height}: RunEffectChainOptions,+ initialFlipSourceY: boolean,+): Promise<boolean> => {const runId = ++state.currentRunId;const isCancelled = () => state.currentRunId !== runId;@@ -160,7 +160,7 @@ export const runEffectChain = async ({// Canvas sources are DOM-oriented. Flip them when uploading into WebGL so// texture coordinates match clip-space output. `ImageBitmap` bridges below// opt out because they are already oriented for upload.- let flipWebGLSourceY = true;+ let flipWebGLSourceY = initialFlipSourceY;for (let runIndex = 0; runIndex < runs.length; runIndex++) {const run = runs[runIndex];@@ -182,8 +182,8 @@ export const runEffectChain = async ({target: dst,state: setupState,params: eff.params,- width,- height,+ width: state.width,+ height: state.height,gpuDevice,flipSourceY: run.backend === 'webgl2' ? flipWebGLSourceY : false,});@@ -242,3 +242,40 @@ export const runEffectChain = async ({outCtx.drawImage(lastTarget, 0, 0, width, height);return true;};++// Keep ownership of the optional resized source until the existing chain settles.+export const runEffectChain = async (+ options: RunEffectChainOptions,+): Promise<boolean> => {+ const {state, source, width, height, effects} = options;+ if (+ (state.width === width && state.height === height) ||+ !effects.some((effect) => !(effect.params as {disabled?: boolean}).disabled)+ ) {+ return runEffectChainWithoutResize(options, true);+ }++ const runId = ++state.currentRunId;+ const firstEnabledEffect = effects.find(+ (effect) => !(effect.params as {disabled?: boolean}).disabled,+ )!;+ const resized = await createImageBitmap(source as ImageBitmapSource, {+ resizeWidth: state.width,+ resizeHeight: state.height,+ // WebGL ignores UNPACK_FLIP_Y_WEBGL for ImageBitmap uploads.+ imageOrientation:+ firstEnabledEffect.definition.backend === 'webgl2' ? 'flipY' : 'none',+ });+ try {+ if (state.currentRunId !== runId) {+ return false;+ }++ return await runEffectChainWithoutResize(+ {...options, source: resized},+ false,+ );+ } finally {+ resized.close();+ }+};diff --git a/packages/core/src/effects/use-effect-chain-state.ts b/packages/core/src/effects/use-effect-chain-state.tsindex 22d7309bbb..298c665934 100644--- a/packages/core/src/effects/use-effect-chain-state.ts+++ b/packages/core/src/effects/use-effect-chain-state.ts@@ -1,13 +1,32 @@import {useEffect, useMemo, useRef} from 'react';+import {validateDimension} from '../validation/validate-dimensions.js';+import type {EffectsOutputSize} from './effect-types.js';import type {EffectChainState} from './run-effect-chain.js';import {cleanupEffectChainState,createEffectChainState,} from './run-effect-chain.js';-export const useEffectChainState = (): {+export const useEffectChainState = (+ effectsOutputSize: EffectsOutputSize | null = null,+): {get: (width: number, height: number) => EffectChainState | null;} => {+ const effectWidth = effectsOutputSize?.width;+ const effectHeight = effectsOutputSize?.height;+ if (effectsOutputSize) {+ validateDimension(+ effectWidth,+ 'effectsOutputSize.width',+ 'on an effect-capable component',+ );+ validateDimension(+ effectHeight,+ 'effectsOutputSize.height',+ 'on an effect-capable component',+ );+ }+const chainStateRef = useRef<EffectChainState | null>(null);const sizeRef = useRef<{width: number; height: number} | null>(null);const unmountedRef = useRef(false);@@ -30,6 +49,8 @@ export const useEffectChainState = (): {return useMemo(() => ({get: (width, height) => {+ width = effectWidth ?? width;+ height = effectHeight ?? height;// Async work such as a late decoded video frame can still get here// after unmount. Nothing would release a pool created at this point.if (unmountedRef.current) {@@ -52,6 +73,6 @@ export const useEffectChainState = (): {return chainStateRef.current;},}),- [],+ [effectWidth, effectHeight],);};diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 19aab89a8d..ba1618585e 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -157,6 +157,7 @@ export {type EffectDescriptor,type EffectFactory,type EffectsProp,+ type EffectsOutputSize,} from './effects/index.js';/*** @description Renders a solid-color rectangle on a `<canvas>`.diff --git a/packages/core/src/test/effect-internals.test.ts b/packages/core/src/test/effect-internals.test.tsindex 0ed07c8fa6..f57c66d0de 100644--- a/packages/core/src/test/effect-internals.test.ts+++ b/packages/core/src/test/effect-internals.test.ts@@ -48,6 +48,37 @@ const memoizeEffects = (}));};+// PR #11436: a size change or unmount can cancel an asynchronous source resize.+test('closes a resized effect source after its chain is cancelled', async () => {+ const originalBitmap = globalThis.createImageBitmap;+ let finishResize!: (bitmap: ImageBitmap) => void;+ const close = mock(() => undefined);+ globalThis.createImageBitmap = mock(+ () =>+ new Promise<ImageBitmap>((resolve) => {+ finishResize = resolve;+ }),+ ) as typeof createImageBitmap;+ const state = createEffectChainState(2, 2);+ try {+ const rendering = runEffectChain({+ state,+ source: document.createElement('canvas'),+ output: document.createElement('canvas'),+ width: 4,+ height: 4,+ effects: memoizeEffects([makeDesc('cancelled', '2d')]),+ });+ cleanupEffectChainState(state);+ finishResize({close} as unknown as ImageBitmap);+ expect(await rendering).toBe(false);+ expect(close).toHaveBeenCalledTimes(1);+ } finally {+ globalThis.createImageBitmap = originalBitmap;+ cleanupEffectChainState(state);+ }+});+test('groupByBackend collapses adjacent same-backend effects', () => {const effects = [makeDesc('a', '2d'),@@ -97,25 +128,6 @@ test('groupByBackend returns one run per backend transition', () => {expect(runs.map((r) => r.backend)).toEqual(['2d', 'webgl2', '2d', 'webgl2']);});-test('runEffectChain filters disabled effects before grouping', () => {- // Mirror of the filter in `runEffectChain` β kept here as a regression- // guard so the behavior is asserted independently of the canvas-bound- // chain runner.- const all: EffectDescriptor<unknown>[] = [- {...makeDesc('a', '2d'), params: {disabled: false}},- {...makeDesc('b', '2d'), params: {disabled: true}},- {...makeDesc('c', 'webgl2'), params: {}},- {...makeDesc('d', 'webgl2'), params: {disabled: true}},- ];- const enabled = all.filter(- (e) => !(e.params as {disabled?: boolean}).disabled,- );- const runs = groupByBackend(memoizeEffects(enabled));- expect(runs).toHaveLength(2);- expect(runs[0].effects.map((e) => e.definition.type)).toEqual(['a']);- expect(runs[1].effects.map((e) => e.definition.type)).toEqual(['c']);-});-test.each(['2d', 'webgl2'] as const)('runEffectChain allocates only needed %s targets and releases them',async (backend) => {diff --git a/packages/docs/docs/effects/index.mdx b/packages/docs/docs/effects/index.mdxindex cff6fc6767..d15f222e2a 100644--- a/packages/docs/docs/effects/index.mdx+++ b/packages/docs/docs/effects/index.mdx@@ -35,6 +35,29 @@ Pass effects through the `effects` prop of these components:- [`<Heart>`](/docs/shapes/heart)- [`<Arrow>`](/docs/shapes/arrow)+## Effect resolution<AvailableFrom v="4.0.535" />++Use `effectsOutputSize` on any supported component to choose the pixel dimensions used by its effect chain:++```tsx twoslash+import {Video} from '@remotion/media';+import {pixelate} from '@remotion/effects/pixelate';+// ---cut---+<Video+ src="https://example.com/video.mp4"+ effects={[pixelate({blockSize: 12})]}+ effectsOutputSize={{width: 1920, height: 1080}}+/>;+```++Both dimensions must be positive integers. The source is resized to this resolution before the effects run, and the result is composited back into the component's existing output canvas. CSS layout, cropping, and the output video's dimensions stay the same.++This is useful when switching between an original video and a smaller proxy: keeping the effect resolution fixed keeps pixel-based parameters, such as pixelation block sizes, in the same coordinate space. It also applies to images, animated images, GIFs, Rive canvases, solids, HTML-in-canvas, and shapes.++Omitting `effectsOutputSize` preserves the existing effect resolution. Empty or entirely disabled effect chains do not resize the source. To change the resolution, update the numeric width and height; passing a new object with the same values does not recreate the effect chain. Video previews redraw the current frame when these values change without restarting their decoder.++A larger effect resolution increases processing and canvas memory. Resizing a low-resolution source cannot restore missing detail. This prop controls effect processing; [`maxCanvasSinkFrameSize`](/docs/media/video#maxcanvassinkframesize) separately controls decoded preview frame size.+## Effects<TableOfContents />diff --git a/packages/gif/src/Gif.tsx b/packages/gif/src/Gif.tsxindex f8ded44b4d..c1886ffeef 100644--- a/packages/gif/src/Gif.tsx+++ b/packages/gif/src/Gif.tsx@@ -77,6 +77,7 @@ const GifInner = ({cropBottom,controls,effects = [],+ effectsOutputSize,ref,...sequenceProps}: GifProps & {@@ -137,6 +138,7 @@ const GifInner = ({requestInit,style: croppedStyle ?? undefined,effects: memoizedEffects,+ effectsOutputSize,};const inner = env.isRendering ? (diff --git a/packages/gif/src/GifForDevelopment.tsx b/packages/gif/src/GifForDevelopment.tsxindex 769b8e402b..652f244c40 100644--- a/packages/gif/src/GifForDevelopment.tsx+++ b/packages/gif/src/GifForDevelopment.tsx@@ -28,6 +28,7 @@ export const GifForDevelopment = forwardRef<fit = 'fill',requestInit,effects,+ effectsOutputSize = null,...props},ref,@@ -133,6 +134,7 @@ export const GifForDevelopment = forwardRef<width={width}height={height}effects={effects}+ effectsOutputSize={effectsOutputSize}{...props}ref={ref}/>diff --git a/packages/gif/src/GifForRendering.tsx b/packages/gif/src/GifForRendering.tsxindex d116bfabca..fc390b2a69 100644--- a/packages/gif/src/GifForRendering.tsx+++ b/packages/gif/src/GifForRendering.tsx@@ -29,6 +29,7 @@ export const GifForRendering = forwardRef<delayRenderTimeoutInMilliseconds,requestInit,effects,+ effectsOutputSize = null,...props},ref,@@ -165,6 +166,7 @@ export const GifForRendering = forwardRef<width={width}height={height}effects={effects}+ effectsOutputSize={effectsOutputSize}{...props}ref={ref}/>diff --git a/packages/gif/src/canvas.tsx b/packages/gif/src/canvas.tsxindex c98797826d..103a89f07c 100644--- a/packages/gif/src/canvas.tsx+++ b/packages/gif/src/canvas.tsx@@ -7,7 +7,7 @@ import {useRef,useState,} from 'react';-import type {EffectDefinitionAndStack} from 'remotion';+import type {EffectDefinitionAndStack, EffectsOutputSize} from 'remotion';import {Internals, useDelayRender} from 'remotion';import type {GifFillMode} from './props';import {useElementSize} from './use-element-size';@@ -108,11 +108,22 @@ type Props = {readonly className?: string;readonly style?: React.CSSProperties;readonly effects: EffectDefinitionAndStack<unknown>[];+ readonly effectsOutputSize: EffectsOutputSize | null;};export const Canvas = forwardRef((- {index, frames, width, height, fit, className, style, effects}: Props,+ {+ index,+ frames,+ width,+ height,+ fit,+ className,+ style,+ effects,+ effectsOutputSize,+ }: Props,ref,) => {const canvasRef = useRef<HTMLCanvasElement>(null);@@ -136,7 +147,7 @@ export const Canvas = forwardRef(return document.createElement('canvas');}, []);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const {delayRender, continueRender, cancelRender} = useDelayRender();const size = useElementSize(canvasRef);diff --git a/packages/gif/src/props.ts b/packages/gif/src/props.tsindex 517ca006c9..56e5d04e2d 100644--- a/packages/gif/src/props.ts+++ b/packages/gif/src/props.ts@@ -1,9 +1,11 @@+import type {EffectsOutputSize} from 'remotion';export type GifLoopBehavior =| 'loop'| 'pause-after-finish'| 'unmount-after-finish';export type RemotionGifProps = {+ effectsOutputSize?: EffectsOutputSize;src: string;width?: number;height?: number;diff --git a/packages/media/src/video/props.ts b/packages/media/src/video/props.tsindex 140fef1d59..c77084e2cd 100644--- a/packages/media/src/video/props.ts+++ b/packages/media/src/video/props.ts@@ -2,6 +2,7 @@ import type React from 'react';import type {EffectDefinitionAndStack,EffectsProp,+ EffectsOutputSize,InteractiveBaseProps,InteractiveCropProps,InteractivePremountProps,@@ -87,6 +88,7 @@ type OptionalVideoProps = {maxCanvasSinkFrameSize: MaxCanvasSinkFrameSize | null;_experimentalInitiallyDrawCachedFrame: boolean;effects: EffectsProp;+ effectsOutputSize: EffectsOutputSize | null;};export type NativeVideoProps = Omit<diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsxindex b44a47ae47..6d202a3495 100644--- a/packages/media/src/video/video-for-preview.tsx+++ b/packages/media/src/video/video-for-preview.tsx@@ -6,6 +6,7 @@ import React, {useRef,useState,} from 'react';+import type {EffectsOutputSize} from 'remotion';import type {EffectDefinitionAndStack,LogLevel,@@ -81,6 +82,7 @@ type VideoForPreviewProps = NativeVideoProps & {readonly setMediaDurationInSeconds: (durationInSeconds: number) => void;readonly _experimentalInitiallyDrawCachedFrame: boolean;readonly effects: EffectDefinitionAndStack<unknown>[];+ readonly effectsOutputSize: EffectsOutputSize | null;};type VideoForPreviewAssertedShowingProps = VideoForPreviewProps;@@ -115,6 +117,7 @@ const VideoForPreviewAssertedShowing: React.FC<maxCanvasSinkFrameSize,_experimentalInitiallyDrawCachedFrame,effects,+ effectsOutputSize,setMediaDurationInSeconds,...props}) => {@@ -172,7 +175,7 @@ const VideoForPreviewAssertedShowing: React.FC<warnAboutTooHighVolume(userPreferredVolume);- const effectChainState = useEffectChainState();+ const effectChainState = useEffectChainState(effectsOutputSize);const effectsRef = useRef(effects);effectsRef.current = effects;@@ -545,7 +548,13 @@ const VideoForPreviewAssertedShowing: React.FC<mediaPlayer.redrawVideoEffects().catch(() => {// Player may have been disposed between layout and the async redraw.});- }, [effects, mediaPlayerReady, mediaPlayerRef]);+ }, [+ effects,+ effectsOutputSize?.width,+ effectsOutputSize?.height,+ mediaPlayerReady,+ mediaPlayerRef,+ ]);const actualStyle: React.CSSProperties = useMemo(() => {return {diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsxindex ab4a1164f9..6815664fd0 100644--- a/packages/media/src/video/video-for-rendering.tsx+++ b/packages/media/src/video/video-for-rendering.tsx@@ -5,6 +5,7 @@ import React, {useRef,useState,} from 'react';+import type {EffectsOutputSize} from 'remotion';import type {EffectDefinitionAndStack,LogLevel,@@ -61,6 +62,7 @@ type InnerVideoProps = NativeVideoProps & {readonly requestInit: MediaRequestInit | undefined;readonly objectFit: VideoObjectFit;readonly effects: EffectDefinitionAndStack<unknown>[];+ readonly effectsOutputSize: EffectsOutputSize | null;};type FallbackToOffthreadVideo = {@@ -93,6 +95,7 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({requestInit,objectFit: objectFitProp,effects,+ effectsOutputSize,...props}) => {if (!src) {@@ -149,7 +152,7 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({const maxCacheSize = useMaxMediaCacheSize(logLevel);const mediaCache = useRenderMediaCache(logLevel);- const effectChainState = Internals.useEffectChainState();+ const effectChainState = Internals.useEffectChainState(effectsOutputSize);const [error, setError] = useState<Error | null>(null);diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsxindex ad62935dad..52582df109 100644--- a/packages/media/src/video/video.tsx+++ b/packages/media/src/video/video.tsx@@ -111,6 +111,7 @@ const InnerVideo: React.FC<maxCanvasSinkFrameSize,_experimentalInitiallyDrawCachedFrame,effects,+ effectsOutputSize = null,setMediaDurationInSeconds,...props}) => {@@ -174,6 +175,7 @@ const InnerVideo: React.FC<requestInit={requestInit}objectFit={objectFit}effects={effects}+ effectsOutputSize={effectsOutputSize}/>);}@@ -225,6 +227,7 @@ const InnerVideo: React.FC<objectFit={objectFit}maxCanvasSinkFrameSize={maxCanvasSinkFrameSize}effects={effects}+ effectsOutputSize={effectsOutputSize}_experimentalInitiallyDrawCachedFrame={_experimentalInitiallyDrawCachedFrame}@@ -267,6 +270,7 @@ const VideoInner: React.FC<maxCanvasSinkFrameSize,_experimentalInitiallyDrawCachedFrame,effects,+ effectsOutputSize = null,durationInFrames,from,freeze,@@ -452,6 +456,7 @@ const VideoInner: React.FC<_experimentalInitiallyDrawCachedFrame ?? false}effects={memoizedEffects}+ effectsOutputSize={effectsOutputSize}setMediaDurationInSeconds={setMediaDurationInSeconds}/></Internals.SequenceContent>diff --git a/packages/rive/src/RemotionRiveCanvas.tsx b/packages/rive/src/RemotionRiveCanvas.tsxindex b1bcef58e0..8c52a595a8 100644--- a/packages/rive/src/RemotionRiveCanvas.tsx+++ b/packages/rive/src/RemotionRiveCanvas.tsx@@ -18,6 +18,7 @@ import React, {} from 'react';import type {EffectsProp,+ EffectsOutputSize,InteractiveBaseProps,InteractivePremountProps,InteractiveCropProps,@@ -61,6 +62,7 @@ type RemotionRiveCanvasOwnProps = {readonly className?: string;readonly style?: React.CSSProperties;readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;};export type RemotionRiveCanvasProps = RemotionRiveCanvasOwnProps &@@ -124,12 +126,13 @@ export const riveCanvasSchema: InteractivitySchema = {type RemotionRiveCanvasContentProps = Omit<RemotionRiveCanvasOwnProps,- 'effects'+ 'effects' | 'effectsOutputSize'> & {readonly fit: RemotionRiveCanvasFit;readonly alignment: RemotionRiveCanvasAlignment;readonly enableRiveAssetCdn: boolean;readonly effects: EffectsProp;+ readonly effectsOutputSize: EffectsOutputSize | null;readonly controls: SequenceControls | undefined;readonly canvasRef: React.RefObject<HTMLCanvasElement | null>;};@@ -150,6 +153,7 @@ const RemotionRiveCanvasContentForwardRefFunction: React.ForwardRefRenderFunctioclassName,style,effects,+ effectsOutputSize,controls,canvasRef,},@@ -176,7 +180,7 @@ const RemotionRiveCanvasContentForwardRefFunction: React.ForwardRefRenderFunctioreturn document.createElement('canvas');}, []);- const chainState = useEffectChainState();+ const chainState = useEffectChainState(effectsOutputSize);const memoizedEffects = useMemoizedEffects({effects,@@ -476,6 +480,7 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<className,style,effects = [],+ effectsOutputSize,controls,durationInFrames,name,@@ -568,6 +573,7 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<className={className}style={croppedStyle ?? undefined}effects={effects}+ effectsOutputSize={effectsOutputSize ?? null}controls={controls}canvasRef={canvasRef}/>diff --git a/packages/shapes/src/components/render-svg.tsx b/packages/shapes/src/components/render-svg.tsxindex d2e6de35a4..104b803b17 100644--- a/packages/shapes/src/components/render-svg.tsx+++ b/packages/shapes/src/components/render-svg.tsx@@ -7,6 +7,7 @@ import {Sequence,Internals,type EffectsProp,+ type EffectsOutputSize,type HtmlInCanvasPixelDensity,type HtmlInCanvasProps,type InteractiveBaseProps,@@ -34,6 +35,7 @@ export type AllShapesProps = Omit<ShapeSequenceProps & {readonly debug?: boolean;readonly effects?: EffectsProp;+ readonly effectsOutputSize?: EffectsOutputSize;readonly pathStyle?: React.CSSProperties;readonly pixelDensity?: HtmlInCanvasPixelDensity;};@@ -127,6 +129,7 @@ export const RenderSvg = ({transformOrigin,debug,effects = [],+ effectsOutputSize,instructions,pixelDensity,durationInFrames,@@ -271,6 +274,7 @@ export const RenderSvg = ({width={Math.ceil(width)}height={Math.ceil(height)}effects={effects}+ effectsOutputSize={effectsOutputSize}pixelDensity={pixelDensity}showInTimeline={false}style={actualStyle}