Skip to content

🎥 Make videos programmatically with React

@remotion/effects: Add translate effects (#7671)

Jonny Burgerbee11d03e734
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 2dcae06ded..ed3ac378d7 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -11,14 +11,13 @@ import {
bookFlipPresentationDemo,
circleDemo,
clockWipePresentationDemo,
- crossZoomPresentationDemo,
crosswarpPresentationDemo,
+ crossZoomPresentationDemo,
cubePresentationDemo,
customPresentationDemo,
customTimingDemo,
dissolvePresentationDemo,
dreamyZoomPresentationDemo,
- ellipseDemo,
effectsBarrelDistortionDemo,
effectsBlurDemo,
effectsBrightnessDemo,
@@ -31,7 +30,10 @@ import {
effectsSaturationDemo,
effectsScaleDemo,
effectsTintDemo,
+ effectsUvTranslateDemo,
effectsWaveDemo,
+ effectsXyTranslateDemo,
+ ellipseDemo,
fadePresentationDemo,
filmBurnPresentationDemo,
flipPresentationDemo,
@@ -93,6 +95,8 @@ const demos: DemoType[] = [
effectsTintDemo,
effectsMirrorDemo,
effectsScaleDemo,
+ effectsXyTranslateDemo,
+ effectsUvTranslateDemo,
effectsBarrelDistortionDemo,
effectsBlurDemo,
effectsWaveDemo,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 4afa71c88e..81325ed4bb 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -11,6 +11,10 @@ import {EffectsMirrorPreview} from '../effects/effects-mirror-preview';
import {EffectsSaturationPreview} from '../effects/effects-saturation-preview';
import {EffectsScalePreview} from '../effects/effects-scale-preview';
import {EffectsTintPreview} from '../effects/effects-tint-preview';
+import {
+ EffectsUvTranslatePreview,
+ EffectsXyTranslatePreview,
+} from '../effects/effects-translate-preview';
import {EffectsWavePreview} from '../effects/effects-wave-preview';
import {
ClockWipeDemo,
@@ -1659,6 +1663,70 @@ export const effectsScaleDemo: DemoType = {
],
};
+export const effectsXyTranslateDemo: DemoType = {
+ comp: EffectsXyTranslatePreview,
+ compHeight: 720,
+ compWidth: 1280,
+ durationInFrames: 1,
+ fps: 30,
+ id: 'effects-xy-translate',
+ autoPlay: false,
+ controls: false,
+ logLevel: 'info',
+ options: [
+ {
+ name: 'x',
+ type: 'numeric',
+ min: -640,
+ max: 640,
+ step: 1,
+ default: 180,
+ optional: 'no',
+ },
+ {
+ name: 'y',
+ type: 'numeric',
+ min: -360,
+ max: 360,
+ step: 1,
+ default: 90,
+ optional: 'no',
+ },
+ ],
+};
+
+export const effectsUvTranslateDemo: DemoType = {
+ comp: EffectsUvTranslatePreview,
+ compHeight: 720,
+ compWidth: 1280,
+ durationInFrames: 1,
+ fps: 30,
+ id: 'effects-uv-translate',
+ autoPlay: false,
+ controls: false,
+ logLevel: 'info',
+ options: [
+ {
+ name: 'u',
+ type: 'numeric',
+ min: -1,
+ max: 1,
+ step: 0.01,
+ default: 0.15,
+ optional: 'no',
+ },
+ {
+ name: 'v',
+ type: 'numeric',
+ min: -1,
+ max: 1,
+ step: 0.01,
+ default: 0.125,
+ optional: 'no',
+ },
+ ],
+};
+
export const effectsBarrelDistortionDemo: DemoType = {
comp: EffectsBarrelDistortionPreview,
compHeight: 720,
diff --git a/packages/docs/components/effects/effects-translate-preview.tsx b/packages/docs/components/effects/effects-translate-preview.tsx
new file mode 100644
index 0000000000..29ae1baf03
--- /dev/null
+++ b/packages/docs/components/effects/effects-translate-preview.tsx
@@ -0,0 +1,32 @@
+import {uvTranslate, xyTranslate} from '@remotion/effects/translate';
+import React from 'react';
+import {CanvasImage} from 'remotion';
+import {EFFECTS_PREVIEW_IMAGE_SRC} from './effects-preview-image';
+
+export const EffectsXyTranslatePreview: React.FC<{
+ readonly x: number;
+ readonly y: number;
+}> = ({x, y}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ effects={[xyTranslate({x, y})]}
+ />
+ );
+};
+
+export const EffectsUvTranslatePreview: React.FC<{
+ readonly u: number;
+ readonly v: number;
+}> = ({u, v}) => {
+ return (
+ <CanvasImage
+ src={EFFECTS_PREVIEW_IMAGE_SRC}
+ width={1280}
+ height={720}
+ effects={[uvTranslate({u, v})]}
+ />
+ );
+};
diff --git a/packages/docs/docs/effects/table-of-contents.tsx b/packages/docs/docs/effects/table-of-contents.tsx
index 5ef3c3b672..c9fb10d6eb 100644
--- a/packages/docs/docs/effects/table-of-contents.tsx
+++ b/packages/docs/docs/effects/table-of-contents.tsx
@@ -85,6 +85,20 @@ const categories: {
name: 'scale()',
description: 'Scale transform effect',
},
+ {
+ link: '/docs/effects/xy-translate',
+ preview: '/img/effects-xy-translate-preview.jpg',
+ alt: 'XY translate effect preview',
+ name: 'xyTranslate()',
+ description: 'Pixel-based translate effect',
+ },
+ {
+ link: '/docs/effects/uv-translate',
+ preview: '/img/effects-uv-translate-preview.jpg',
+ alt: 'UV translate effect preview',
+ name: 'uvTranslate()',
+ description: 'UV-based translate effect',
+ },
],
},
{
diff --git a/packages/docs/docs/effects/uv-translate.mdx b/packages/docs/docs/effects/uv-translate.mdx
new file mode 100644
index 0000000000..037636b60f
--- /dev/null
+++ b/packages/docs/docs/effects/uv-translate.mdx
@@ -0,0 +1,65 @@
+---
+image: /generated/articles-docs-effects-uv-translate.png
+slug: /effects/uv-translate
+title: uvTranslate()
+sidebar_label: uvTranslate()
+crumb: '@remotion/effects'
+---
+
+# uvTranslate()<AvailableFrom v="4.0.467" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+A translate effect that moves a canvas-based component by normalized UV coordinates.
+
+It can be applied to components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).
+
+## Preview
+
+<Demo type="effects-uv-translate" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill} from 'remotion';
+import {Video} from '@remotion/media';
+import {uvTranslate} from '@remotion/effects/translate';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[uvTranslate({u: 0.1, v: 0.05})]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `uvTranslate()` without arguments.
+
+### `u?`
+
+Horizontal offset in UV coordinates. Defaults to `0`.
+
+`1` equals the full canvas width. Positive values move the image to the right, negative values move it to the left.
+
+### `v?`
+
+Vertical offset in UV coordinates. Defaults to `0`.
+
+`1` equals the full canvas height. Positive values move the image down, negative values move it up.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`xyTranslate()`](/docs/effects/xy-translate)
+- [`scale()`](/docs/effects/scale)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/translate/index.ts)
diff --git a/packages/docs/docs/effects/xy-translate.mdx b/packages/docs/docs/effects/xy-translate.mdx
new file mode 100644
index 0000000000..f953e95783
--- /dev/null
+++ b/packages/docs/docs/effects/xy-translate.mdx
@@ -0,0 +1,65 @@
+---
+image: /generated/articles-docs-effects-xy-translate.png
+slug: /effects/xy-translate
+title: xyTranslate()
+sidebar_label: xyTranslate()
+crumb: '@remotion/effects'
+---
+
+# xyTranslate()<AvailableFrom v="4.0.467" />
+
+_Part of the [`@remotion/effects`](/docs/effects/api) package._
+
+A translate effect that moves a canvas-based component by an absolute pixel offset.
+
+It can be applied to components such as [`<Video>`](/docs/media/video), [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) and [`<Solid>`](/docs/solid).
+
+## Preview
+
+<Demo type="effects-xy-translate" />
+
+## Example
+
+```tsx twoslash title="MyComp.tsx"
+import {AbsoluteFill} from 'remotion';
+import {Video} from '@remotion/media';
+import {xyTranslate} from '@remotion/effects/translate';
+
+export const MyComp: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Video
+ src="https://remotion.media/video.mp4"
+ effects={[xyTranslate({x: 120, y: 80})]}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+## API
+
+Pass an object with the following properties. You can also call `xyTranslate()` without arguments.
+
+### `x?`
+
+Horizontal offset in pixels. Defaults to `0`.
+
+Positive values move the image to the right, negative values move it to the left.
+
+### `y?`
+
+Vertical offset in pixels. Defaults to `0`.
+
+Positive values move the image down, negative values move it up.
+
+### `disabled?`
+
+When `true`, the effect is skipped. Defaults to `false`.
+
+## See also
+
+- [`@remotion/effects`](/docs/effects/api)
+- [`uvTranslate()`](/docs/effects/uv-translate)
+- [`scale()`](/docs/effects/scale)
+- [Source code for this effect](https://github.com/remotion-dev/remotion/blob/main/packages/effects/src/translate/index.ts)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 101ebfc952..84531cb19d 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -280,7 +280,9 @@ const sidebars: SidebarsConfig = {
'effects/saturation',
'effects/scale',
'effects/tint',
+ 'effects/uv-translate',
'effects/wave',
+ 'effects/xy-translate',
],
},
{
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 62a2b0125a..181f76c09f 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1835,6 +1835,15 @@ export const articles = [
noAi: false,
slug: 'effects/tint',
},
+ {
+ id: 'effects/uv-translate',
+ title: 'uvTranslate()',
+ relativePath: 'docs/effects/uv-translate.mdx',
+ compId: 'articles-docs-effects-uv-translate',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/uv-translate',
+ },
{
id: 'effects/wave',
title: 'wave()',
@@ -1844,6 +1853,15 @@ export const articles = [
noAi: false,
slug: 'effects/wave',
},
+ {
+ id: 'effects/xy-translate',
+ title: 'xyTranslate()',
+ relativePath: 'docs/effects/xy-translate.mdx',
+ compId: 'articles-docs-effects-xy-translate',
+ crumb: '@remotion/effects',
+ noAi: false,
+ slug: 'effects/xy-translate',
+ },
{
id: 'electron',
title: 'Using Remotion in Electron',
diff --git a/packages/docs/static/generated/articles-docs-effects-uv-translate.png b/packages/docs/static/generated/articles-docs-effects-uv-translate.png
new file mode 100644
index 0000000000..c79cde6341
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-uv-translate.png differ
diff --git a/packages/docs/static/generated/articles-docs-effects-xy-translate.png b/packages/docs/static/generated/articles-docs-effects-xy-translate.png
new file mode 100644
index 0000000000..f55a1e5869
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-effects-xy-translate.png differ
diff --git a/packages/docs/static/img/effects-uv-translate-preview.jpg b/packages/docs/static/img/effects-uv-translate-preview.jpg
new file mode 100644
index 0000000000..9ef05c23cb
Binary files /dev/null and b/packages/docs/static/img/effects-uv-translate-preview.jpg differ
diff --git a/packages/docs/static/img/effects-xy-translate-preview.jpg b/packages/docs/static/img/effects-xy-translate-preview.jpg
new file mode 100644
index 0000000000..172873672c
Binary files /dev/null and b/packages/docs/static/img/effects-xy-translate-preview.jpg differ
diff --git a/packages/effects/bundle.ts b/packages/effects/bundle.ts
index 7a20109307..184407d65f 100644
--- a/packages/effects/bundle.ts
+++ b/packages/effects/bundle.ts
@@ -19,6 +19,7 @@ const effectEntrypoints = [
'src/saturation.ts',
'src/scale.ts',
'src/tint.ts',
+ 'src/translate.ts',
'src/wave.ts',
];
diff --git a/packages/effects/package.json b/packages/effects/package.json
index 8cb6a44704..ada7421ad7 100644
--- a/packages/effects/package.json
+++ b/packages/effects/package.json
@@ -92,6 +92,11 @@
"module": "./dist/esm/tint.mjs",
"import": "./dist/esm/tint.mjs"
},
+ "./translate": {
+ "types": "./dist/translate.d.ts",
+ "module": "./dist/esm/translate.mjs",
+ "import": "./dist/esm/translate.mjs"
+ },
"./wave": {
"types": "./dist/wave.d.ts",
"module": "./dist/esm/wave.mjs",
@@ -137,6 +142,9 @@
"tint": [
"dist/tint.d.ts"
],
+ "translate": [
+ "dist/translate.d.ts"
+ ],
"wave": [
"dist/wave.d.ts"
]
diff --git a/packages/effects/src/test/effect-params.test.ts b/packages/effects/src/test/effect-params.test.ts
index 382d973c7a..e3512b1a45 100644
--- a/packages/effects/src/test/effect-params.test.ts
+++ b/packages/effects/src/test/effect-params.test.ts
@@ -11,6 +11,7 @@ import {mirror} from '../mirror.js';
import {saturation} from '../saturation.js';
import {scale} from '../scale.js';
import {tint} from '../tint.js';
+import {uvTranslate, xyTranslate} from '../translate.js';
import {wave} from '../wave/index.js';
test('@remotion/effects expose documentation links', () => {
@@ -50,6 +51,12 @@ test('@remotion/effects expose documentation links', () => {
expect(tint({color: '#fff'}).definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/tint',
);
+ expect(uvTranslate().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/uv-translate',
+ );
+ expect(xyTranslate().definition.documentationLink).toBe(
+ 'https://www.remotion.dev/docs/effects/xy-translate',
+ );
expect(wave().definition.documentationLink).toBe(
'https://www.remotion.dev/docs/effects/wave',
);
@@ -452,3 +459,49 @@ test('scale() axis flags produce distinct effect keys', () => {
];
expect(new Set(keys).size).toBe(keys.length);
});
+
+test('xyTranslate() accepts default params', () => {
+ expect(() => xyTranslate()).not.toThrow();
+});
+
+test('xyTranslate() rejects non-finite offsets', () => {
+ expect(() => xyTranslate({x: Number.NaN})).toThrow(
+ '"x" must be a finite number',
+ );
+ expect(() => xyTranslate({y: Number.NaN})).toThrow(
+ '"y" must be a finite number',
+ );
+});
+
+test('xyTranslate() offsets produce distinct effect keys', () => {
+ const centered = xyTranslate();
+ const shiftedX = xyTranslate({x: 10});
+ const shiftedY = xyTranslate({y: 10});
+
+ expect(
+ new Set([centered.effectKey, shiftedX.effectKey, shiftedY.effectKey]).size,
+ ).toBe(3);
+});
+
+test('uvTranslate() accepts default params', () => {
+ expect(() => uvTranslate()).not.toThrow();
+});
+
+test('uvTranslate() rejects non-finite offsets', () => {
+ expect(() => uvTranslate({u: Number.NaN})).toThrow(
+ '"u" must be a finite number',
+ );
+ expect(() => uvTranslate({v: Number.NaN})).toThrow(
+ '"v" must be a finite number',
+ );
+});
+
+test('uvTranslate() offsets produce distinct effect keys', () => {
+ const centered = uvTranslate();
+ const shiftedU = uvTranslate({u: 0.1});
+ const shiftedV = uvTranslate({v: 0.1});
+
+ expect(
+ new Set([centered.effectKey, shiftedU.effectKey, shiftedV.effectKey]).size,
+ ).toBe(3);
+});
diff --git a/packages/effects/src/test/translate.test.ts b/packages/effects/src/test/translate.test.ts
new file mode 100644
index 0000000000..7d7a62fca3
--- /dev/null
+++ b/packages/effects/src/test/translate.test.ts
@@ -0,0 +1,76 @@
+import {describe, expect, it} from 'bun:test';
+import {uvTranslate, xyTranslate} from '../translate.js';
+
+describe('xyTranslate', () => {
+ it('should accept default params', () => {
+ expect(() => xyTranslate()).not.toThrow();
+ });
+
+ it('should accept x and y offsets', () => {
+ expect(() => xyTranslate({x: 120, y: -40})).not.toThrow();
+ });
+
+ it('should reject non-finite x offsets', () => {
+ expect(() => xyTranslate({x: Number.NaN})).toThrow(
+ '"x" must be a finite number',
+ );
+ });
+
+ it('should reject non-finite y offsets', () => {
+ expect(() => xyTranslate({y: Number.POSITIVE_INFINITY})).toThrow(
+ '"y" must be a finite number',
+ );
+ });
+
+ it('should produce distinct effect keys for different offsets', () => {
+ const centered = xyTranslate();
+ const shiftedX = xyTranslate({x: 10});
+ const shiftedY = xyTranslate({y: 10});
+
+ expect(
+ new Set([centered.effectKey, shiftedX.effectKey, shiftedY.effectKey])
+ .size,
+ ).toBe(3);
+ });
+
+ it('should default to no translation', () => {
+ expect(xyTranslate().effectKey).toBe(xyTranslate({x: 0, y: 0}).effectKey);
+ });
+});
+
+describe('uvTranslate', () => {
+ it('should accept default params', () => {
+ expect(() => uvTranslate()).not.toThrow();
+ });
+
+ it('should accept u and v offsets', () => {
+ expect(() => uvTranslate({u: 0.25, v: -0.1})).not.toThrow();
+ });
+
+ it('should reject non-finite u offsets', () => {
+ expect(() => uvTranslate({u: Number.NaN})).toThrow(
+ '"u" must be a finite number',
+ );
+ });
+
+ it('should reject non-finite v offsets', () => {
+ expect(() => uvTranslate({v: Number.NEGATIVE_INFINITY})).toThrow(
+ '"v" must be a finite number',
+ );
+ });
+
+ it('should produce distinct effect keys for different offsets', () => {
+ const centered = uvTranslate();
+ const shiftedU = uvTranslate({u: 0.1});
+ const shiftedV = uvTranslate({v: 0.1});
+
+ expect(
+ new Set([centered.effectKey, shiftedU.effectKey, shiftedV.effectKey])
+ .size,
+ ).toBe(3);
+ });
+
+ it('should default to no translation', () => {
+ expect(uvTranslate().effectKey).toBe(uvTranslate({u: 0, v: 0}).effectKey);
+ });
+});
diff --git a/packages/effects/src/translate.ts b/packages/effects/src/translate.ts
new file mode 100644
index 0000000000..01be325dff
--- /dev/null
+++ b/packages/effects/src/translate.ts
@@ -0,0 +1,6 @@
+export {
+ uvTranslate,
+ xyTranslate,
+ type UvTranslateParams,
+ type XyTranslateParams,
+} from './translate/index.js';
diff --git a/packages/effects/src/translate/index.ts b/packages/effects/src/translate/index.ts
new file mode 100644
index 0000000000..2af7cf77ea
--- /dev/null
+++ b/packages/effects/src/translate/index.ts
@@ -0,0 +1,164 @@
+import type {SequenceSchema} from 'remotion';
+import {Internals} from 'remotion';
+import {assertOptionalFiniteNumber} from '../color-utils.js';
+import {assertEffectParamsObject} from '../validate-effect-param.js';
+
+const {createEffect} = Internals;
+
+const xyTranslateSchema = {
+ x: {
+ type: 'number',
+ step: 1,
+ default: 0,
+ description: 'X',
+ },
+ y: {
+ type: 'number',
+ step: 1,
+ default: 0,
+ description: 'Y',
+ },
+} as const satisfies SequenceSchema;
+
+const uvTranslateSchema = {
+ u: {
+ type: 'number',
+ step: 0.01,
+ default: 0,
+ description: 'U',
+ },
+ v: {
+ type: 'number',
+ step: 0.01,
+ default: 0,
+ description: 'V',
+ },
+} as const satisfies SequenceSchema;
+
+export type XyTranslateParams = {
+ /** Horizontal offset in pixels. Defaults to `0`. */
+ readonly x?: number;
+ /** Vertical offset in pixels. Defaults to `0`. */
+ readonly y?: number;
+};
+
+export type UvTranslateParams = {
+ /** Horizontal offset in UV coordinates. `1` equals the full canvas width. Defaults to `0`. */
+ readonly u?: number;
+ /** Vertical offset in UV coordinates. `1` equals the full canvas height. Defaults to `0`. */
+ readonly v?: number;
+};
+
+type XyTranslateResolved = {
+ readonly x: number;
+ readonly y: number;
+};
+
+type UvTranslateResolved = {
+ readonly u: number;
+ readonly v: number;
+};
+
+const resolveXyTranslate = (
+ params: XyTranslateParams,
+): XyTranslateResolved => ({
+ x: params.x ?? 0,
+ y: params.y ?? 0,
+});
+
+const resolveUvTranslate = (
+ params: UvTranslateParams,
+): UvTranslateResolved => ({
+ u: params.u ?? 0,
+ v: params.v ?? 0,
+});
+
+const validateXyTranslateParams = (params: XyTranslateParams): void => {
+ assertEffectParamsObject(params, 'xyTranslate');
+ assertOptionalFiniteNumber(params.x, 'x');
+ assertOptionalFiniteNumber(params.y, 'y');
+};
+
+const validateUvTranslateParams = (params: UvTranslateParams): void => {
+ assertEffectParamsObject(params, 'uvTranslate');
+ assertOptionalFiniteNumber(params.u, 'u');
+ assertOptionalFiniteNumber(params.v, 'v');
+};
+
+const applyTranslate = ({
+ source,
+ target,
+ width,
+ height,
+ x,
+ y,
+}: {
+ readonly source: CanvasImageSource;
+ readonly target: HTMLCanvasElement;
+ readonly width: number;
+ readonly height: number;
+ readonly x: number;
+ readonly y: number;
+}) => {
+ const ctx = target.getContext('2d');
+ if (!ctx) {
+ throw new Error(
+ 'Failed to acquire 2D context for translate effect. The canvas may have been assigned a different context type.',
+ );
+ }
+
+ ctx.clearRect(0, 0, width, height);
+ ctx.drawImage(source, x, y, width, height);
+};
+
+export const xyTranslate = createEffect<XyTranslateParams, null>({
+ type: 'remotion/xy-translate',
+ label: 'XY Translate',
+ documentationLink: 'https://www.remotion.dev/docs/effects/xy-translate',
+ backend: '2d',
+ calculateKey: (params) => {
+ const r = resolveXyTranslate(params);
+ return `xy-translate-${r.x}-${r.y}`;
+ },
+ setup: () => null,
+ apply: ({source, target, width, height, params}) => {
+ const r = resolveXyTranslate(params);
+ applyTranslate({
+ source,
+ target,
+ width,
+ height,
+ x: r.x,
+ y: r.y,
+ });
+ },
+ cleanup: () => undefined,
+ schema: xyTranslateSchema,
+ validateParams: validateXyTranslateParams,
+});
+
+export const uvTranslate = createEffect<UvTranslateParams, null>({
+ type: 'remotion/uv-translate',
+ label: 'UV Translate',
+ documentationLink: 'https://www.remotion.dev/docs/effects/uv-translate',
+ backend: '2d',
+ calculateKey: (params) => {
+ const r = resolveUvTranslate(params);
+ return `uv-translate-${r.u}-${r.v}`;
+ },
+ setup: () => null,
+ apply: ({source, target, width, height, params}) => {
+ const r = resolveUvTranslate(params);
+ applyTranslate({
+ source,
+ target,
+ width,
+ height,
+ x: r.u * width,
+ y: r.v * height,
+ });
+ },
+ cleanup: () => undefined,
+ schema: uvTranslateSchema,
+ validateParams: validateUvTranslateParams,
+});
diff --git a/packages/example/src/HtmlInCanvas/effects-uv-translate-preview.tsx b/packages/example/src/HtmlInCanvas/effects-uv-translate-preview.tsx
new file mode 100644
index 0000000000..9e064957fc
--- /dev/null
+++ b/packages/example/src/HtmlInCanvas/effects-uv-translate-preview.tsx
@@ -0,0 +1,23 @@
+import {uvTranslate} from '@remotion/effects/translate';
+import React from 'react';
+import {HtmlInCanvas, useVideoConfig} from 'remotion';
+import {EffectsPreviewImage} from './effects-preview-image';
+
+export const EffectsUvTranslatePreview: React.FC = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <HtmlInCanvas
+ width={width}
+ height={height}
+ effects={[
+ uvTranslate({
+ u: 0.15,
+ v: 0.125,
+ }),
+ ]}
+ >
+ <EffectsPreviewImage />
+ </HtmlInCanvas>
+ );
+};
diff --git a/packages/example/src/HtmlInCanvas/effects-xy-translate-preview.tsx b/packages/example/src/HtmlInCanvas/effects-xy-translate-preview.tsx
new file mode 100644
index 0000000000..7c64e98f22
--- /dev/null
+++ b/packages/example/src/HtmlInCanvas/effects-xy-translate-preview.tsx
@@ -0,0 +1,23 @@
+import {xyTranslate} from '@remotion/effects/translate';
+import React from 'react';
+import {HtmlInCanvas, useVideoConfig} from 'remotion';
+import {EffectsPreviewImage} from './effects-preview-image';
+
+export const EffectsXyTranslatePreview: React.FC = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <HtmlInCanvas
+ width={width}
+ height={height}
+ effects={[
+ xyTranslate({
+ x: 180,
+ y: 90,
+ }),
+ ]}
+ >
+ <EffectsPreviewImage />
+ </HtmlInCanvas>
+ );
+};
diff --git a/packages/example/src/HtmlInCanvas/index.tsx b/packages/example/src/HtmlInCanvas/index.tsx
index f38fe26d4c..c7561a2ba8 100644
--- a/packages/example/src/HtmlInCanvas/index.tsx
+++ b/packages/example/src/HtmlInCanvas/index.tsx
@@ -24,10 +24,6 @@ export {
DissolveTransitionDocThumb,
} from './dissolve-doc';
export {HtmlInCanvasDocsDemo2DBlur} from './docs-demo-2d-blur';
-export {
- FilmBurnTransitionDoc,
- FilmBurnTransitionDocThumb,
-} from './film-burn-doc';
export {EffectsBlurPreview} from './effects-blur-preview';
export {EffectsBrightnessPreview} from './effects-brightness-preview';
export {EffectsContrastPreview} from './effects-contrast-preview';
@@ -37,13 +33,19 @@ export {EffectsHuePreview} from './effects-hue-preview';
export {EffectsInvertPreview} from './effects-invert-preview';
export {EffectsSaturationPreview} from './effects-saturation-preview';
export {EffectsTintPreview} from './effects-tint-preview';
+export {EffectsUvTranslatePreview} from './effects-uv-translate-preview';
export {EffectsWavePreview} from './effects-wave-preview';
-export {HtmlInCanvasDocsMinimalWebGL} from './minimal-docs-webgl';
-export {HtmlInCanvasDocsMinimalWebGPU} from './minimal-docs-webgpu';
+export {EffectsXyTranslatePreview} from './effects-xy-translate-preview';
+export {
+ FilmBurnTransitionDoc,
+ FilmBurnTransitionDocThumb,
+} from './film-burn-doc';
export {
LinearBlurTransitionDoc,
LinearBlurTransitionDocThumb,
} from './linear-blur-doc';
+export {HtmlInCanvasDocsMinimalWebGL} from './minimal-docs-webgl';
+export {HtmlInCanvasDocsMinimalWebGPU} from './minimal-docs-webgpu';
export {HtmlInCanvasPrivacy} from './privacy';
export {HtmlInCanvasReactSvg} from './react-svg';
export {RippleTransitionDoc, RippleTransitionDocThumb} from './ripple-doc';
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 4eb97c8bfc..bb11039291 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -56,8 +56,6 @@ import {
CrosswarpTransitionDocThumb,
DissolveTransitionDoc,
DissolveTransitionDocThumb,
- FilmBurnTransitionDoc,
- FilmBurnTransitionDocThumb,
EffectsBlurPreview,
EffectsBrightnessPreview,
EffectsContrastPreview,
@@ -67,7 +65,11 @@ import {
EffectsInvertPreview,
EffectsSaturationPreview,
EffectsTintPreview,
+ EffectsUvTranslatePreview,
EffectsWavePreview,
+ EffectsXyTranslatePreview,
+ FilmBurnTransitionDoc,
+ FilmBurnTransitionDocThumb,
HtmlInCanvasComplexText,
HtmlInCanvasComposeAsyncBitmap,
HtmlInCanvasComposeWebGL,
@@ -1182,6 +1184,22 @@ export const Index: React.FC = () => {
width={1080}
durationInFrames={1}
/>
+ <Composition
+ id="html-in-canvas-effects-xy-translate-preview"
+ component={EffectsXyTranslatePreview}
+ fps={30}
+ height={720}
+ width={1080}
+ durationInFrames={1}
+ />
+ <Composition
+ id="html-in-canvas-effects-uv-translate-preview"
+ component={EffectsUvTranslatePreview}
+ fps={30}
+ height={720}
+ width={1080}
+ durationInFrames={1}
+ />
<Composition
id="zoom-in-out-transition-doc"
component={ZoomInOutTransitionDoc}