Skip to content

🎥 Make videos programmatically with React

Add base render logic

Vlad Mf7f63a3a7dc1
diff --git a/packages/template-ai-video/src/AIVideo.tsx b/packages/template-ai-video/src/AIVideo.tsx
index 1b58e05268..53cb4776f7 100644
--- a/packages/template-ai-video/src/AIVideo.tsx
+++ b/packages/template-ai-video/src/AIVideo.tsx
@@ -1,6 +1,10 @@
-import { AbsoluteFill } from "remotion";
+import { AbsoluteFill, Html5Audio, Sequence } from "remotion";
import { z } from "zod";
import { TimelineSchema } from "./types";
+import { FirstFrameOffset, FPS } from "./constants";
+import { loadFont } from "@remotion/google-fonts/Signika";
+import { Background } from "./components/Background";
+import Subtitle from "./components/Subtitle";
export const aiVideoSchema = z.object({
timeline: TimelineSchema,
@@ -9,7 +13,93 @@ export const aiVideoSchema = z.object({
export const AIVideo: React.FC<z.infer<typeof aiVideoSchema>> = ({
timeline,
- hasWatermark,
}) => {
- return <AbsoluteFill style={{ backgroundColor: "white" }}></AbsoluteFill>;
+ const { fontFamily } = loadFont();
+ const ready = true;
+
+ return (
+ <AbsoluteFill style={{ backgroundColor: "white" }}>
+ {ready && timeline && (
+ <>
+ <Sequence durationInFrames={FirstFrameOffset}>
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ textAlign: "center",
+ display: "flex",
+ zIndex: 10,
+ }}
+ >
+ <div
+ style={{
+ fontSize: 120,
+ lineHeight: "122px",
+ width: "87%",
+ color: "black",
+ fontFamily,
+ textTransform: "uppercase",
+ backgroundColor: "yellow",
+ paddingTop: 20,
+ }}
+ >
+ {timeline.shortTitle}
+ </div>
+ </AbsoluteFill>
+ </Sequence>
+
+ {timeline.elements.map((element, index) => {
+ const elementStartFrame = (element.startMs * FPS) / 1000;
+ const durationInFrames =
+ ((element.endMs - element.startMs) * FPS) / 1000 +
+ (index === 0 ? FirstFrameOffset : 0);
+
+ return (
+ <Sequence
+ key={`element-${index}`}
+ from={elementStartFrame}
+ durationInFrames={durationInFrames}
+ >
+ <Background item={element} />
+ </Sequence>
+ );
+ })}
+
+ {timeline.text.map((element, index) => {
+ const elementStartFrame =
+ (element.startMs * FPS) / 1000 + FirstFrameOffset;
+ const durationInFrames =
+ ((element.endMs - element.startMs) * FPS) / 1000;
+
+ return (
+ <Sequence
+ key={`element-${index}`}
+ from={elementStartFrame}
+ durationInFrames={durationInFrames}
+ >
+ <Subtitle key={index} text={element.text} />;
+ </Sequence>
+ );
+ })}
+
+ {timeline.audio.map((element, index) => {
+ const elementStartFrame =
+ (element.startMs * FPS) / 1000 + FirstFrameOffset;
+ const durationInFrames =
+ ((element.endMs - element.startMs) * FPS) / 1000;
+
+ return (
+ <Sequence
+ key={`element-${index}`}
+ from={elementStartFrame}
+ durationInFrames={durationInFrames}
+ >
+ <Html5Audio src={element.audioUrl} />
+ </Sequence>
+ );
+ })}
+ </>
+ )}
+ </AbsoluteFill>
+ );
};
diff --git a/packages/template-ai-video/src/components/Word.tsx b/packages/template-ai-video/src/components/Word.tsx
index 396561423f..87a44c0698 100644
--- a/packages/template-ai-video/src/components/Word.tsx
+++ b/packages/template-ai-video/src/components/Word.tsx
@@ -42,6 +42,7 @@ export const Word: React.FC<{
]),
fontFamily,
textTransform: "uppercase",
+ textAlign: "center",
}}
>
{text}
diff --git a/packages/template-ai-video/src/constants.ts b/packages/template-ai-video/src/constants.ts
index 0c953139f2..3b3185a13e 100644
--- a/packages/template-ai-video/src/constants.ts
+++ b/packages/template-ai-video/src/constants.ts
@@ -1,3 +1,4 @@
export const FPS = 30;
export const WindowsWidth = 1080;
export const WindowsHeight = 1920;
+export const FirstFrameOffset = 1;