π₯ Make videos programmatically with React
fonts
Jonny Burgerc6b7ad968132
diff --git a/packages/skills/skills/assets/SKILL.md b/packages/skills/skills/assets/SKILL.mdnew file mode 100644index 0000000000..e18422d92b--- /dev/null+++ b/packages/skills/skills/assets/SKILL.md@@ -0,0 +1,112 @@+---+name: assets+description: Importing images, videos, audio, and fonts into Remotion+metadata:+ impact: HIGH+ tags: assets, staticFile, images, fonts, public+---++# Importing assets in Remotion++## The public folder++Place assets in the `public/` folder at your project root:++```+my-video/+ββ public/+β ββ logo.png+β ββ background.mp4+β ββ music.mp3+β ββ font.woff2+ββ src/+ββ package.json+```++## Using staticFile()++You MUST use `staticFile()` to reference files from the `public/` folder:++```tsx+import { Img, staticFile } from "remotion";++export const MyComposition = () => {+ return <Img src={staticFile("logo.png")} />;+};+```++The function returns an encoded URL that works correctly when deploying to subdirectories.++## Supported formats++**Images:** PNG, SVG, JPG, JPEG, WEBP, GIF, BMP+**Videos:** WEBM, MOV, MP4+**Audio:** MP3, WAV, AAC, M4A+**Fonts:** WOFF, WOFF2, OTF, TTF, EOT++## Using with components++**Images:**++```tsx+import { Img, staticFile } from "remotion";++<Img src={staticFile("photo.png")} />+```++**Videos:**++```tsx+import { Video } from "@remotion/media";+import { staticFile } from "remotion";++<Video src={staticFile("clip.mp4")} />+```++**Audio:**++```tsx+import { Audio } from "@remotion/media";+import { staticFile } from "remotion";++<Audio src={staticFile("music.mp3")} />+```++**Fonts:**++```tsx+import { staticFile } from "remotion";++const fontFamily = new FontFace("MyFont", `url(${staticFile("font.woff2")})`);+await fontFamily.load();+document.fonts.add(fontFamily);+```++## Remote URLs++Remote URLs can be used directly without `staticFile()`:++```tsx+<Img src="https://example.com/image.png" />+<Video src="https://example.com/video.mp4" />+```++## Dynamic asset paths++Use template literals for dynamic file references:++```tsx+const frame = useCurrentFrame();++// Image sequence+<Img src={staticFile(`/frames/frame${frame}.png`)} />++// Selecting based on props+<Img src={staticFile(`/avatars/${props.userId}.png`)} />+```++## Important notes++- Assets must exist in `public/` before bundling - files added after bundling are not accessible+- Remotion components (`<Img>`, `<Video>`, `<Audio>`) ensure assets are fully loaded before rendering+- Special characters in filenames (`#`, `?`, `&`) are automatically encodeddiff --git a/packages/skills/skills/fonts/SKILL.md b/packages/skills/skills/fonts/SKILL.mdnew file mode 100644index 0000000000..73013b2d3f--- /dev/null+++ b/packages/skills/skills/fonts/SKILL.md@@ -0,0 +1,141 @@+---+name: fonts+description: Loading Google Fonts and local fonts in Remotion+metadata:+ impact: HIGH+ tags: fonts, google-fonts, typography, text+---++# Using fonts in Remotion++## Google Fonts with @remotion/google-fonts++The recommended way to use Google Fonts. It's type-safe and automatically blocks rendering until the font is ready.++```tsx+import { loadFont } from "@remotion/google-fonts/Lobster";++const { fontFamily } = loadFont();++export const MyComposition = () => {+ return <div style={{ fontFamily }}>Hello World</div>;+};+```++Preferrably, specify only needed weights and subsets to reduce file size:++```tsx+import { loadFont } from "@remotion/google-fonts/Roboto";++const { fontFamily } = loadFont("normal", {+ weights: ["400", "700"],+ subsets: ["latin"],+});+```++### Waiting for font to load++Use `waitUntilDone()` if you need to know when the font is ready:++```tsx+import { loadFont } from "@remotion/google-fonts/Lobster";++const { fontFamily, waitUntilDone } = loadFont();++await waitUntilDone();+```++## Local fonts with @remotion/fonts++For local font files, use the `@remotion/fonts` package.++### Prerequisites++First, install @remotion/fonts:++```bash+npx remotion add @remotion/fonts # If project uses npm+bunx remotion add @remotion/fonts # If project uses bun+yarn remotion add @remotion/fonts # If project uses yarn+pnpm exec remotion add @remotion/fonts # If project uses pnpm+```++### Loading a local font++Place your font file in the `public/` folder and use `loadFont()`:++```tsx+import { loadFont } from "@remotion/fonts";+import { staticFile } from "remotion";++await loadFont({+ family: "MyFont",+ url: staticFile("MyFont-Regular.woff2"),+});++export const MyComposition = () => {+ return <div style={{ fontFamily: "MyFont" }}>Hello World</div>;+};+```++### Loading multiple weights++Load each weight separately with the same family name:++```tsx+import { loadFont } from "@remotion/fonts";+import { staticFile } from "remotion";++await Promise.all([+ loadFont({+ family: "Inter",+ url: staticFile("Inter-Regular.woff2"),+ weight: "400",+ }),+ loadFont({+ family: "Inter",+ url: staticFile("Inter-Bold.woff2"),+ weight: "700",+ }),+]);+```++### Available options++```tsx+loadFont({+ family: "MyFont", // Required: name to use in CSS+ url: staticFile("font.woff2"), // Required: font file URL+ format: "woff2", // Optional: auto-detected from extension+ weight: "400", // Optional: font weight+ style: "normal", // Optional: normal or italic+ display: "block", // Optional: font-display behavior+});+```++## Using in components++Call `loadFont()` at the top level of your component or in a separate file that's imported early:++```tsx+import { loadFont } from "@remotion/google-fonts/Montserrat";++const { fontFamily } = loadFont("normal", {+ weights: ["400", "700"],+ subsets: ["latin"],+});++export const Title: React.FC<{ text: string }> = ({ text }) => {+ return (+ <h1+ style={{+ fontFamily,+ fontSize: 80,+ fontWeight: "bold",+ }}+ >+ {text}+ </h1>+ );+};+```