Skip to content

🎥 Make videos programmatically with React

Add word and subtitle components

Vlad M93104aca312c
diff --git a/bun.lock b/bun.lock
index 5582cae690..3f4f3fc6c2 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1320,7 +1320,10 @@
"name": "template-ai-video",
"version": "1.0.0",
"dependencies": {
+ "@remotion/animation-utils": "workspace:*",
"@remotion/cli": "workspace:*",
+ "@remotion/google-fonts": "workspace:*",
+ "@remotion/layout-utils": "workspace:*",
"@remotion/zod-types": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
diff --git a/packages/template-ai-video/package.json b/packages/template-ai-video/package.json
index 515e5a549b..8d61492d7f 100644
--- a/packages/template-ai-video/package.json
+++ b/packages/template-ai-video/package.json
@@ -13,6 +13,9 @@
"dependencies": {
"@remotion/cli": "workspace:*",
"@remotion/zod-types": "workspace:*",
+ "@remotion/layout-utils": "workspace:*",
+ "@remotion/animation-utils": "workspace:*",
+ "@remotion/google-fonts": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
"remotion": "workspace:*",
diff --git a/packages/template-ai-video/src/components/Subtitle.tsx b/packages/template-ai-video/src/components/Subtitle.tsx
new file mode 100644
index 0000000000..389ec762a3
--- /dev/null
+++ b/packages/template-ai-video/src/components/Subtitle.tsx
@@ -0,0 +1,35 @@
+import React from "react";
+import {
+ AbsoluteFill,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+import { Word } from "./Word";
+
+const Subtitle: React.FC<{ text: string }> = ({ text }) => {
+ const frame = useCurrentFrame();
+ const { fps } = useVideoConfig();
+
+ const enter = spring({
+ frame,
+ fps,
+ config: {
+ damping: 200,
+ },
+ durationInFrames: 5,
+ });
+
+ return (
+ <AbsoluteFill>
+ <AbsoluteFill>
+ <Word stroke enterProgress={enter} text={text} />
+ </AbsoluteFill>
+ <AbsoluteFill>
+ <Word enterProgress={enter} text={text} stroke={false} />
+ </AbsoluteFill>
+ </AbsoluteFill>
+ );
+};
+
+export default Subtitle;
diff --git a/packages/template-ai-video/src/components/Word.tsx b/packages/template-ai-video/src/components/Word.tsx
new file mode 100644
index 0000000000..396561423f
--- /dev/null
+++ b/packages/template-ai-video/src/components/Word.tsx
@@ -0,0 +1,51 @@
+import type React from "react";
+import { AbsoluteFill, interpolate, useVideoConfig } from "remotion";
+import { fitText } from "@remotion/layout-utils";
+import { makeTransform, scale, translateY } from "@remotion/animation-utils";
+import { loadFont } from "@remotion/google-fonts/Rowdies";
+
+export const Word: React.FC<{
+ enterProgress: number;
+ text: string;
+ stroke: boolean;
+}> = ({ enterProgress, text, stroke }) => {
+ const { fontFamily } = loadFont();
+ const { width } = useVideoConfig();
+ const desiredFontSize = 120;
+
+ const fittedText = fitText({
+ fontFamily,
+ text,
+ withinWidth: width * 0.8,
+ });
+
+ const fontSize = Math.min(desiredFontSize, fittedText.fontSize);
+
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ top: undefined,
+ bottom: 350,
+ height: 150,
+ }}
+ >
+ <div
+ style={{
+ fontSize,
+ color: "white",
+ WebkitTextStroke: stroke ? "20px black" : undefined,
+ transform: makeTransform([
+ scale(interpolate(enterProgress, [0, 1], [0.8, 1])),
+ translateY(interpolate(enterProgress, [0, 1], [50, 0])),
+ ]),
+ fontFamily,
+ textTransform: "uppercase",
+ }}
+ >
+ {text}
+ </div>
+ </AbsoluteFill>
+ );
+};