Skip to content

🎥 Make videos programmatically with React

move to google fonts and structure template

Jonny Burger36311609d580
diff --git a/packages/template-audiogram/package.json b/packages/template-audiogram/package.json
index 04dcc0a196..bccd086ffa 100644
--- a/packages/template-audiogram/package.json
+++ b/packages/template-audiogram/package.json
@@ -16,6 +16,7 @@
"@remotion/media-utils": "workspace:*",
"@remotion/captions": "workspace:*",
"@remotion/zod-types": "workspace:*",
+ "@remotion/google-fonts": "workspace:*",
"react": "19.0.0",
"react-dom": "19.0.0",
"remotion": "workspace:*",
diff --git a/packages/template-audiogram/src/AudioViz.tsx b/packages/template-audiogram/src/Audiogram/AudioViz.tsx
similarity index 100%
rename from packages/template-audiogram/src/AudioViz.tsx
rename to packages/template-audiogram/src/Audiogram/AudioViz.tsx
diff --git a/packages/template-audiogram/src/Captions.tsx b/packages/template-audiogram/src/Audiogram/Captions.tsx
similarity index 80%
rename from packages/template-audiogram/src/Captions.tsx
rename to packages/template-audiogram/src/Audiogram/Captions.tsx
index e3b38013de..731bd68e0b 100644
--- a/packages/template-audiogram/src/Captions.tsx
+++ b/packages/template-audiogram/src/Audiogram/Captions.tsx
@@ -1,24 +1,25 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import {
- cancelRender,
continueRender,
delayRender,
useCurrentFrame,
useCurrentScale,
} from "remotion";
-import { ensureFont } from "./ensure-font";
import { Word } from "./Word";
import { Caption } from "@remotion/captions";
-import { msToFrame } from "./helpers/ms-to-frame";
-
-const useWindowedFrameCaptions = (
- src: Caption[],
- options: { windowStart: number; windowEnd: number },
-) => {
- const { windowStart, windowEnd } = options;
+import { msToFrame } from "../helpers/ms-to-frame";
+const useWindowedFrameCaptions = ({
+ captions,
+ windowStart,
+ windowEnd,
+}: {
+ captions: Caption[];
+ windowStart: number;
+ windowEnd: number;
+}) => {
return useMemo(() => {
- return src
+ return captions
.map((item) => {
const start = msToFrame(item.startMs);
const end = msToFrame(item.endMs);
@@ -34,7 +35,7 @@ const useWindowedFrameCaptions = (
end,
};
}, []);
- }, [src, windowEnd, windowStart]);
+ }, [captions, windowEnd, windowStart]);
};
export const PaginatedCaptions: React.FC<{
@@ -59,9 +60,8 @@ export const PaginatedCaptions: React.FC<{
const frame = useCurrentFrame();
const windowRef = useRef<HTMLDivElement>(null);
const [handle] = useState(() => delayRender());
- const [fontHandle] = useState(() => delayRender());
- const [fontLoaded, setFontLoaded] = useState(false);
- const windowedFrameSubs = useWindowedFrameCaptions(captions, {
+ const windowedFrameSubs = useWindowedFrameCaptions({
+ captions,
windowStart: startFrame,
windowEnd: endFrame,
});
@@ -90,9 +90,6 @@ export const PaginatedCaptions: React.FC<{
}, [frame, onlyDisplayCurrentSentence, windowedFrameSubs]);
useEffect(() => {
- if (!fontLoaded) {
- return;
- }
const linesRendered =
(windowRef.current?.getBoundingClientRect().height as number) /
(subtitlesLineHeight * currentScale);
@@ -101,7 +98,6 @@ export const PaginatedCaptions: React.FC<{
continueRender(handle);
}, [
currentScale,
- fontLoaded,
frame,
handle,
linesPerPage,
@@ -109,17 +105,6 @@ export const PaginatedCaptions: React.FC<{
subtitlesZoomMeasurerSize,
]);
- useEffect(() => {
- ensureFont()
- .then(() => {
- continueRender(fontHandle);
- setFontLoaded(true);
- })
- .catch((err) => {
- cancelRender(err);
- });
- }, [fontHandle, fontLoaded]);
-
const currentFrameSentences = currentAndFollowingSentences.filter((word) => {
return word.start < frame;
});
diff --git a/packages/template-audiogram/src/Main.tsx b/packages/template-audiogram/src/Audiogram/Main.tsx
similarity index 93%
rename from packages/template-audiogram/src/Main.tsx
rename to packages/template-audiogram/src/Audiogram/Main.tsx
index 3a1828512a..4b83db99b5 100644
--- a/packages/template-audiogram/src/Main.tsx
+++ b/packages/template-audiogram/src/Audiogram/Main.tsx
@@ -1,10 +1,16 @@
import React from "react";
import { AbsoluteFill, Audio, Img, Sequence, useVideoConfig } from "remotion";
+import { loadFont, fontFamily } from "@remotion/google-fonts/IBMPlexSans";
+import "./style.css";
import { PaginatedCaptions } from "./Captions";
import { AudioViz } from "./AudioViz";
import { AudiogramCompositionSchemaType } from "./schema";
+loadFont("normal", {
+ weights: ["500"],
+});
+
export const Main: React.FC<AudiogramCompositionSchemaType> = ({
audioFileName,
coverImgFileName,
@@ -40,7 +46,7 @@ export const Main: React.FC<AudiogramCompositionSchemaType> = ({
<div
className="container"
style={{
- fontFamily: "IBM Plex Sans",
+ fontFamily,
}}
>
<div className="row">
diff --git a/packages/template-audiogram/src/Word.tsx b/packages/template-audiogram/src/Audiogram/Word.tsx
similarity index 94%
rename from packages/template-audiogram/src/Word.tsx
rename to packages/template-audiogram/src/Audiogram/Word.tsx
index a83fcf1ad9..8ed0e474b7 100644
--- a/packages/template-audiogram/src/Word.tsx
+++ b/packages/template-audiogram/src/Audiogram/Word.tsx
@@ -2,7 +2,7 @@ import { Easing } from "remotion";
import { interpolate } from "remotion";
import React from "react";
import { Caption } from "@remotion/captions";
-import { msToFrame } from "./helpers/ms-to-frame";
+import { msToFrame } from "../helpers/ms-to-frame";
export const Word: React.FC<{
readonly item: Caption;
diff --git a/packages/template-audiogram/src/schema.ts b/packages/template-audiogram/src/Audiogram/schema.ts
similarity index 100%
rename from packages/template-audiogram/src/schema.ts
rename to packages/template-audiogram/src/Audiogram/schema.ts
diff --git a/packages/template-audiogram/src/style.css b/packages/template-audiogram/src/Audiogram/style.css
similarity index 91%
rename from packages/template-audiogram/src/style.css
rename to packages/template-audiogram/src/Audiogram/style.css
index 9b3cc5a28e..3f7fe01b41 100644
--- a/packages/template-audiogram/src/style.css
+++ b/packages/template-audiogram/src/Audiogram/style.css
@@ -1,7 +1,4 @@
:root {
- --remotion-font: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
- Noto Sans, sans-serif, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,
- "Apple Color Emoji", "Segoe UI Emoji";
--base-size: 48px;
}
@@ -28,7 +25,6 @@
color: white;
padding: var(--base-size);
background-color: black;
- font-family: var(--remotion-font);
}
.row {
diff --git a/packages/template-audiogram/src/Root.tsx b/packages/template-audiogram/src/Root.tsx
index d06b91f1cc..e9baa19be9 100644
--- a/packages/template-audiogram/src/Root.tsx
+++ b/packages/template-audiogram/src/Root.tsx
@@ -1,7 +1,6 @@
import { Composition, staticFile } from "remotion";
-import { Main } from "./Main";
-import "./style.css";
-import { audiogramSchema } from "./schema";
+import { Main } from "./Audiogram/Main";
+import { audiogramSchema } from "./Audiogram/schema";
import { getAudioDurationInSeconds } from "@remotion/media-utils";
import { getSubtitles } from "./helpers/fetch-captions";
import { FPS } from "./helpers/ms-to-frame";
diff --git a/packages/template-audiogram/src/ensure-font.ts b/packages/template-audiogram/src/ensure-font.ts
deleted file mode 100644
index f6e72c0702..0000000000
--- a/packages/template-audiogram/src/ensure-font.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-export const ensureFont = () => {
- if (typeof window !== "undefined" && "FontFace" in window) {
- const font = new FontFace(
- "IBM Plex Sans",
- "url(https://fonts.gstatic.com/s/ibmplexsans/v14/zYX9KVElMYYaJe8bpLHnCwDKjQ76AIFsdP3pBms.woff2)",
- );
- return font.load().then(() => {
- document.fonts.add(font);
- });
- }
-
- throw new Error("browser does not support FontFace");
-};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a1b8ebee61..5e7fb293e8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1979,15 +1979,15 @@ importers:
'@remotion/cli':
specifier: workspace:*
version: link:../cli
+ '@remotion/google-fonts':
+ specifier: workspace:*
+ version: link:../google-fonts
'@remotion/media-utils':
specifier: workspace:*
version: link:../media-utils
'@remotion/zod-types':
specifier: workspace:*
version: link:../zod-types
- parse-srt:
- specifier: 1.0.0-alpha
- version: 1.0.0-alpha
react:
specifier: 19.0.0
version: 19.0.0
@@ -24108,10 +24108,6 @@ packages:
resolution: {integrity: sha512-twN+njEipszzlMJd4ONUYgSfZPDxgHhT9Ahed5uTigpQn90FggW4SA/AIPq/6a149fTbE9qBEcSwE3FAEp6wQQ==}
dev: false
- resolution: {integrity: sha1-hePGDTHk3Qkk+vVB6oWhiPw0T2E=}
- dev: false
-
resolution: {integrity: sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==}
dependencies: