Skip to content

🎥 Make videos programmatically with React

Docs: Add page about posterization (#8135)

Jonny Burger0242d42653cc
diff --git a/packages/docs/docs/posterization.mdx b/packages/docs/docs/posterization.mdx
new file mode 100644
index 0000000000..cc4797c44a
--- /dev/null
+++ b/packages/docs/docs/posterization.mdx
@@ -0,0 +1,73 @@
+---
+image: /generated/articles-docs-posterization.png
+title: Posterization
+id: posterization
+crumb: 'Designing visuals'
+---
+
+# Posterization<AvailableFrom v="4.0.470" />
+
+Posterization makes an animation update in steps instead of changing on every frame.
+Use it for stop-motion, low-frame-rate motion, or a choppy graphic style.
+
+<video
+ src="/img/posterization-comparison.mp4"
+ autoPlay
+ loop
+ muted
+ playsInline
+ style={{width: '100%', borderRadius: 'var(--ifm-global-radius)', marginBottom: 0, aspectRatio: '3 / 1'}}
+/>
+
+## Using `interpolate()`
+
+Pass `posterize` to [`interpolate()`](/docs/interpolate).
+If the input value is the current frame, `posterize: 3` samples the animation every 3 frames.
+
+```tsx twoslash title="MyComposition.tsx"
+import React from 'react';
+import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';
+
+export const MyComposition: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill style={{justifyContent: 'center', alignItems: 'center'}}>
+ <div
+ style={{
+ width: 120,
+ height: 120,
+ borderRadius: 24,
+ backgroundColor: '#0b84f3',
+ translate: interpolate(frame, [0, 60], ['-200px', '200px'], {
+ posterize: 3,
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+`posterize` quantizes the input before interpolation.
+With `posterize: 3`, frames `0` through `2` use the value for frame `0`, frames `3` through `5` use the value for frame `3`, and so on.
+
+## Colors and styles
+
+[`interpolateColors()`](/docs/interpolate-colors) also accepts `posterize`.
+The same option is available for [`interpolateStyles()`](/docs/animation-utils/interpolate-styles) from [`@remotion/animation-utils`](/docs/animation-utils).
+
+## Studio
+
+When a prop or effect parameter is keyframed in [Remotion Studio](/docs/studio), a `posterize` option in the source interpolation is respected by the preview and timeline data.
+This works for values created with [`interpolate()`](/docs/interpolate) and [`interpolateColors()`](/docs/interpolate-colors).
+
+To edit posterization visually, right-click a keyframed sequence or effect prop in the timeline and click **Keyframe settings...**.
+
+## See also
+
+- [`interpolate()`](/docs/interpolate)
+- [`interpolateColors()`](/docs/interpolate-colors)
+- [`interpolateStyles()`](/docs/animation-utils/interpolate-styles)
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index ece9a61a61..e50286fa2e 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1010,6 +1010,7 @@ const sidebars: SidebarsConfig = {
'using-randomness',
'maps',
'animation-math',
+ 'posterization',
'html-in-canvas',
'noise-visualization',
'shaders',
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 013f897b7c..22af89832a 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -4942,6 +4942,15 @@ export const articles = [
noAi: false,
slug: 'player/thumbnail',
},
+ {
+ id: 'posterization',
+ title: 'Posterization',
+ relativePath: 'docs/posterization.mdx',
+ compId: 'articles-docs-posterization',
+ crumb: 'Designing visuals',
+ noAi: false,
+ slug: 'posterization',
+ },
{
id: 'prefetch',
title: 'prefetch()',
diff --git a/packages/docs/static/generated/articles-docs-posterization.png b/packages/docs/static/generated/articles-docs-posterization.png
new file mode 100644
index 0000000000..9a593a4c22
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-posterization.png differ
diff --git a/packages/docs/static/img/posterization-comparison.mp4 b/packages/docs/static/img/posterization-comparison.mp4
new file mode 100644
index 0000000000..8439e2049f
Binary files /dev/null and b/packages/docs/static/img/posterization-comparison.mp4 differ
diff --git a/packages/example/src/KeyframedPropsTest.tsx b/packages/example/src/KeyframedPropsTest.tsx
index 31c29a9472..d315e5be3c 100644
--- a/packages/example/src/KeyframedPropsTest.tsx
+++ b/packages/example/src/KeyframedPropsTest.tsx
@@ -67,6 +67,7 @@ const ShiftedEffect = () => {
height: 200,
borderRadius: 24,
overflow: 'hidden',
+ translate: '254.854512px 393.565342px',
}}
effects={[
blur({
diff --git a/packages/example/src/Posterization/index.tsx b/packages/example/src/Posterization/index.tsx
new file mode 100644
index 0000000000..642a591044
--- /dev/null
+++ b/packages/example/src/Posterization/index.tsx
@@ -0,0 +1,157 @@
+import React from 'react';
+import {
+ AbsoluteFill,
+ interpolate,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+const accentColor = '#0b84f3';
+
+const PosterizationPanel: React.FC<{
+ readonly index: number;
+ readonly label: string;
+ readonly posterize: number | undefined;
+}> = ({index, label, posterize}) => {
+ const frame = useCurrentFrame();
+ const {durationInFrames} = useVideoConfig();
+
+ const progress = interpolate(frame, [0, durationInFrames - 1], [0, 1], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ ...(posterize === undefined ? {} : {posterize}),
+ });
+
+ const translate = interpolate(
+ progress,
+ [0, 0.5, 1],
+ ['-185px 80px', '0px -95px', '185px 80px'],
+ );
+ const rotate = interpolate(progress, [0, 1], [-10, 350]);
+ const scale = interpolate(progress, [0, 0.5, 1], [0.94, 1.12, 0.94]);
+ const dotSize = interpolate(progress, [0, 0.5, 1], [72, 92, 72]);
+
+ return (
+ <div
+ style={{
+ flex: 1,
+ height: '100%',
+ position: 'relative',
+ overflow: 'hidden',
+ borderRight:
+ index === 2 ? undefined : '2px solid rgba(15, 23, 42, 0.08)',
+ }}
+ >
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ position: 'absolute',
+ width: 410,
+ height: 2,
+ backgroundColor: 'rgba(15, 23, 42, 0.24)',
+ top: 372,
+ }}
+ />
+ {[0, 1, 2, 3, 4, 5].map((marker) => {
+ return (
+ <div
+ key={marker}
+ style={{
+ position: 'absolute',
+ left: 95 + marker * 82,
+ top: 365,
+ width: 2,
+ height: 14,
+ borderRadius: 999,
+ backgroundColor: 'rgba(15, 23, 42, 0.18)',
+ }}
+ />
+ );
+ })}
+ <div
+ style={{
+ position: 'absolute',
+ width: dotSize,
+ height: dotSize,
+ borderRadius: 26,
+ backgroundColor: accentColor,
+ translate,
+ rotate: `${rotate}deg`,
+ scale,
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ ></div>
+ </AbsoluteFill>
+ <div
+ style={{
+ position: 'absolute',
+ left: 46,
+ right: 46,
+ top: 42,
+ color: '#0f172a',
+ }}
+ >
+ <div
+ style={{
+ fontSize: 32,
+ fontWeight: 500,
+ fontFeatureSettings: "'ss03' 1",
+ letterSpacing: -1.4,
+ lineHeight: 1,
+ fontFamily: 'GT Planar, sans-serif',
+ }}
+ >
+ {label}
+ </div>
+ </div>
+ <div
+ style={{
+ position: 'absolute',
+ left: 46,
+ right: 46,
+ bottom: 38,
+ height: 10,
+ borderRadius: 999,
+ backgroundColor: 'rgba(15, 23, 42, 0.08)',
+ overflow: 'hidden',
+ }}
+ >
+ <div
+ style={{
+ width: `${progress * 100}%`,
+ height: '100%',
+ borderRadius: 999,
+ backgroundColor: accentColor,
+ }}
+ />
+ </div>
+ </div>
+ );
+};
+
+export const PosterizationComparison: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ flexDirection: 'row',
+ fontFamily: 'GT Planar, sans-serif',
+ background: 'white',
+ }}
+ >
+ <PosterizationPanel
+ index={0}
+ label="posterize: 0"
+ posterize={undefined}
+ />
+ <PosterizationPanel index={1} label="posterize: 3" posterize={3} />
+ <PosterizationPanel index={2} label="posterize: 8" posterize={8} />
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 2b2512ed91..c94455032b 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -95,6 +95,7 @@ import {OffthreadVideoToCanvas} from './OffthreadVideoToCanvas';
import {OrbScene} from './Orb';
import {ShapesMorph} from './Paths/ShapesMorph';
import {SlicePath} from './Paths/SlicePath';
+import {PosterizationComparison} from './Posterization';
import {
PostmountExample,
PostmountWithStyles,
@@ -549,6 +550,16 @@ export const Index: React.FC = () => {
durationInFrames={100}
/>
</Folder>
+ <Folder name="documentation">
+ <Composition
+ id="posterization-comparison"
+ component={PosterizationComparison}
+ width={1800}
+ height={600}
+ fps={30}
+ durationInFrames={120}
+ />
+ </Folder>
<Folder name="easing">
<Composition
id="easing-visualizer"