Skip to content

🎥 Make videos programmatically with React

nice progress

JonnyBurgera160ae8aff41
diff --git a/bun.lock b/bun.lock
index 6aed60584d..2eedbbff7b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -363,6 +363,7 @@
"@remotion/promo-pages": "workspace:*",
"@remotion/renderer": "workspace:*",
"@remotion/rive": "workspace:*",
+ "@remotion/rounded-text-box": "workspace:*",
"@remotion/shapes": "workspace:*",
"@remotion/skia": "workspace:*",
"@remotion/studio": "workspace:*",
@@ -4150,7 +4151,7 @@
"bun": ["[email protected]", "", { "optionalDependencies": { "@oven/bun-darwin-aarch64": "1.3.0", "@oven/bun-darwin-x64": "1.3.0", "@oven/bun-darwin-x64-baseline": "1.3.0", "@oven/bun-linux-aarch64": "1.3.0", "@oven/bun-linux-aarch64-musl": "1.3.0", "@oven/bun-linux-x64": "1.3.0", "@oven/bun-linux-x64-baseline": "1.3.0", "@oven/bun-linux-x64-musl": "1.3.0", "@oven/bun-linux-x64-musl-baseline": "1.3.0", "@oven/bun-windows-x64": "1.3.0", "@oven/bun-windows-x64-baseline": "1.3.0" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "x64", "arm64", ], "bin": { "bun": "bin/bun.exe", "bunx": "bin/bunx.exe" } }, "sha512-YI7mFs7iWc/VsGsh2aw6eAPD2cjzn1j+LKdYVk09x1CrdTWKYIHyd+dG5iQoN9//3hCDoZj8U6vKpZzEf5UARA=="],
- "bun-plugin-tailwind": ["[email protected]", "", { "peerDependencies": { "typescript": "5.8.2" } }, "sha512-qtAXMNGG4R0UGGI8zWrqm2B7BdXqx48vunJXBPzfDOHPA5WkRUZdTSbE7TFwO4jLhYqSE23YMWsM9NhE6ovobw=="],
+ "bun-plugin-tailwind": ["[email protected]", "", { "dependencies": { "tailwindcss": "4.0.0-beta.9" }, "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-rTbzx+pK3F3cqgbtfbYibfWfKSWdcMNjdPTHgm+BbPhZWzMkBR6NpGqmKExJuIvdKRZgqoA0vd2/lke6rwZqMA=="],
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-u8X0thhx+yJ0KmkxuEo9HAtdfgCBaM/aI9K90VQcQioAmkVp3SG3FkwWGibUFz3WdXAdcsqOcbU40lK7tbHdkQ=="],
@@ -7720,6 +7721,8 @@
"@remotion/media/vitest": ["[email protected]", "", { "dependencies": { "@types/chai": "5.2.2", "@vitest/expect": "3.2.4", "@vitest/mocker": "3.2.4", "@vitest/pretty-format": "3.2.4", "@vitest/runner": "3.2.4", "@vitest/snapshot": "3.2.4", "@vitest/spy": "3.2.4", "@vitest/utils": "3.2.4", "chai": "5.3.3", "debug": "4.4.1", "expect-type": "1.2.2", "magic-string": "0.30.17", "pathe": "2.0.3", "picomatch": "4.0.2", "std-env": "3.9.0", "tinybench": "2.9.0", "tinyexec": "0.3.2", "tinyglobby": "0.2.14", "tinypool": "1.1.1", "tinyrainbow": "2.0.0", "vite": "5.4.20", "vite-node": "3.2.4", "why-is-node-running": "2.3.0" }, "peerDependencies": { "@vitest/browser": "3.2.4" }, "optionalPeers": ["@vitest/browser"], "bin": { "vitest": "vitest.mjs" } }, "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A=="],
+ "@remotion/promo-pages/bun-plugin-tailwind": ["[email protected]", "", { "peerDependencies": { "typescript": "5.8.2" } }, "sha512-qtAXMNGG4R0UGGI8zWrqm2B7BdXqx48vunJXBPzfDOHPA5WkRUZdTSbE7TFwO4jLhYqSE23YMWsM9NhE6ovobw=="],
+
"@remotion/promo-pages/hls.js": ["[email protected]", "", {}, "sha512-C020dKWEJcyvLnrqsFKW4q6D/6IEzKWdhktIS5bgoyEFE8lHgrFBq4RIngdy113abJOlIruhv8qjg7UX8hwxOw=="],
"@remotion/promo-pages/tailwindcss": ["[email protected]", "", {}, "sha512-QNbdmeS979Efzim2g/bEvfuh+fTcIdp1y7gA+sb6OYSW74rt7Cr7M78AKdf6HqWT3d5AiTb7SwTT3sLQxr4/qw=="],
@@ -8010,6 +8013,8 @@
"browserify-zlib/pako": ["[email protected]", "", {}, "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA=="],
+ "bun-plugin-tailwind/tailwindcss": ["[email protected]", "", {}, "sha512-96KpsfQi+/sFIOfyFnGzyy5pobuzf1iMBD9NVtelerPM/lPI2XUS4Kikw9yuKRniXXw77ov1sl7gCSKLsn6CJA=="],
+
"cacache/fs-minipass": ["[email protected]", "", { "dependencies": { "minipass": "7.1.2" } }, "sha512-XUBA9XClHbnJWSfBzjkm6RvPsyg3sryZt06BEQoXcF7EK/xpGaQYJgQKDJSUH5SGZ76Y7pFx1QBnXz09rU5Fbw=="],
"cacache/lru-cache": ["[email protected]", "", {}, "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA=="],
diff --git a/packages/docs/components/demos/RoundedTextBox.tsx b/packages/docs/components/demos/RoundedTextBox.tsx
new file mode 100644
index 0000000000..dbfc402af2
--- /dev/null
+++ b/packages/docs/components/demos/RoundedTextBox.tsx
@@ -0,0 +1,111 @@
+import {fitTextOnNLines, measureText} from '@remotion/layout-utils';
+import type {TextAlign} from '@remotion/rounded-text-box';
+import {createRoundedTextBox} from '@remotion/rounded-text-box';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+type Props = {
+ readonly textAlign: TextAlign;
+ readonly maxLines: number;
+ readonly borderRadius: number;
+ readonly horizontalPadding: number;
+};
+
+const TIKTOK_TEXT_BOX_HORIZONTAL_PADDING = 20;
+const text =
+ 'No matter how much text I am adding, the text always fits on 3 lines and there is corner rounding like on TikTok.';
+
+const boxWidth = 1500;
+const fontFamily = 'Proxima Nova';
+const fontWeight = 400;
+const lineHeight = 1.5;
+const maxFontSize = 200;
+
+export const RoundedTextBox: React.FC<Props> = ({
+ textAlign,
+ maxLines,
+ borderRadius,
+ horizontalPadding,
+}) => {
+ const {fontSize, lines} = fitTextOnNLines({
+ maxLines,
+ maxBoxWidth: boxWidth - TIKTOK_TEXT_BOX_HORIZONTAL_PADDING * 2,
+ fontFamily,
+ text,
+ fontWeight,
+ maxFontSize,
+ });
+
+ const textMeasurements = lines.map((t) =>
+ measureText({
+ text: t,
+ fontFamily,
+ fontSize,
+ additionalStyles: {
+ lineHeight,
+ },
+ fontVariantNumeric: 'normal',
+ fontWeight,
+ letterSpacing: 'normal',
+ textTransform: 'none',
+ validateFontIsLoaded: true,
+ }),
+ );
+ const {d, boundingBox} = createRoundedTextBox({
+ textMeasurements,
+ textAlign,
+ horizontalPadding,
+ borderRadius,
+ });
+
+ const lineStyle = React.useMemo<React.CSSProperties>(
+ () => ({
+ fontSize,
+ fontWeight,
+ fontFamily,
+ lineHeight,
+ textAlign,
+ paddingLeft: horizontalPadding,
+ paddingRight: horizontalPadding,
+ color: 'white',
+ }),
+ [fontSize, textAlign, horizontalPadding],
+ );
+
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: 'var(--background)',
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: boundingBox.width,
+ height: boundingBox.height,
+ }}
+ >
+ <svg
+ viewBox={boundingBox.viewBox}
+ style={{
+ position: 'absolute',
+ width: boundingBox.width,
+ height: boundingBox.height,
+ overflow: 'visible',
+ }}
+ >
+ <path fill="black" d={d} />
+ </svg>
+ <div style={{position: 'relative'}}>
+ {lines.map((line, i) => (
+ // eslint-disable-next-line react/no-array-index-key
+ <div key={i} style={lineStyle}>
+ {line}
+ </div>
+ ))}
+ </div>
+ </div>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index d492c23ebb..3d26ea8a2d 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -24,6 +24,7 @@ import {
polygonDemo,
rectDemo,
rotateDemo,
+ roundedTextBoxDemo,
scaleDemo,
skewDemo,
slidePresentationDemo,
@@ -69,6 +70,7 @@ const demos: DemoType[] = [
irisPresentationDemo,
cubePresentationDemo,
animationMathDemo,
+ roundedTextBoxDemo,
];
export const Demo: React.FC<{
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 8fce577cec..891626055b 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -18,6 +18,7 @@ import {NoiseComp} from './NoiseDemo';
import {PieDemo} from './Pie';
import {PolygonDemo} from './Polygon';
import {RectDemo} from './Rect';
+import {RoundedTextBox} from './RoundedTextBox';
import {StarDemo} from './Star';
import {AnimationMath} from './SubtractAnimations';
import {
@@ -691,6 +692,52 @@ export const wipePresentationDemo: DemoType = {
],
};
+export const roundedTextBoxDemo: DemoType = {
+ comp: RoundedTextBox,
+ compHeight: 1080,
+ compWidth: 1920,
+ durationInFrames: 60,
+ fps: 30,
+ id: 'rounded-text-box',
+ autoPlay: true,
+ options: [
+ {
+ type: 'enum',
+ name: 'textAlign',
+ default: 'center',
+ optional: 'no',
+ values: ['left', 'center', 'right'],
+ },
+ {
+ type: 'numeric',
+ name: 'maxLines',
+ default: 3,
+ max: 10,
+ step: 1,
+ min: 1,
+ optional: 'no',
+ },
+ {
+ type: 'numeric',
+ name: 'borderRadius',
+ default: 20,
+ max: 100,
+ step: 1,
+ min: 0,
+ optional: 'no',
+ },
+ {
+ type: 'numeric',
+ name: 'horizontalPadding',
+ default: 30,
+ max: 100,
+ step: 1,
+ min: 0,
+ optional: 'no',
+ },
+ ],
+};
+
export const clockWipePresentationDemo: DemoType = {
comp: ClockWipeDemo,
compHeight: 280,
diff --git a/packages/docs/docs/rounded-text-box/create-rounded-text-box.mdx b/packages/docs/docs/rounded-text-box/create-rounded-text-box.mdx
index 5d1df85f99..24a447c989 100644
--- a/packages/docs/docs/rounded-text-box/create-rounded-text-box.mdx
+++ b/packages/docs/docs/rounded-text-box/create-rounded-text-box.mdx
@@ -6,6 +6,8 @@ crumb: '@remotion/rounded-text-box'
_Part of the [`@remotion/rounded-text-box`](/docs/rounded-text-box) package._
+<Demo type="rounded-text-box" />
+
## API
_object_ <TsType type="CreateRoundedTextBoxProps" source="@remotion/rounded-text-box" />
diff --git a/packages/docs/package.json b/packages/docs/package.json
index 035a797c7a..26176235a6 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -55,6 +55,7 @@
"@remotion/motion-blur": "workspace:*",
"@remotion/noise": "workspace:*",
"@remotion/paths": "workspace:*",
+ "@remotion/rounded-text-box": "workspace:*",
"@remotion/player": "workspace:*",
"@remotion/openai-whisper": "workspace:*",
"@remotion/preload": "workspace:*",