Fix Missing Fonts and Tofu Boxes in Remotion
Visual/CLI symptom: Programmatic Remotion or FFmpeg videos render Times New Roman fallback text, empty □□□ tofu rectangles on accents/CJK/emojis, or fail with "Fontconfig error: Cannot load default config file" Your programmatic Remotion React video template or FFmpeg subtitle batch looks razor-sharp on your MacBook—then renders ugly fallback serif fonts, missing □□□ square boxes on emojis/Japanese/German characters, or blank lower-thirds the moment you run it inside Linux CI, Docker, or AWS Lambda.
Headless Linux workers ship minimal system font catalogs (often zero CJK/Arabic/emoji/brand faces), Remotion captures frame 0 before asynchronous web fonts finish downloading unless explicitly awaited via delayRender(), and FFmpeg libass/drawtext fails silently whenever Fontconfig cannot locate the exact font family file.
Copy-Paste Verified Fix
// src/lib/load-brand-fonts.ts — Drop into any Remotion project
import { loadFont } from '@remotion/fonts';
import { continueRender, delayRender, staticFile } from 'remotion';
let loaded = false;
export function ensureBrandFontsLoaded() {
if (loaded) return;
const handle = delayRender('Loading self-hosted brand & Unicode fonts');
Promise.all([
loadFont({ family: 'BrandSans', url: staticFile('fonts/Inter-Regular.woff2'), weight: '400' }),
loadFont({ family: 'BrandSans', url: staticFile('fonts/Inter-SemiBold.woff2'), weight: '600' }),
loadFont({ family: 'BrandMono', url: staticFile('fonts/JetBrainsMono-Medium.woff2'), weight: '500' }),
])
.then(() => {
loaded = true;
continueRender(handle);
})
.catch((err) => {
console.error('Fatal font load failure:', err);
throw err;
});
}
// Mandatory CLI canary check before batching 50 MP4 variants:
// npx remotion still src/index.ts AdVariant out/canary_f45.png --frame=45
// Visually inspect out/canary_f45.png -> confirm crisp BrandSans & zero □□□ boxes! Before vs. After (Broken Pattern vs. Verified Fix)
// Remotion: Unawaited remote stylesheet -> races Frame 0 & fails offline
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@600" rel="stylesheet" />
# FFmpeg: Relies on missing Linux OS fonts -> falls back or draws □□□ tofu boxes
ffmpeg -i clip.mp4 -vf "ass=captions_ja.ass" out.mp4 // Remotion: Self-hosted public/fonts/ + explicit loadFont() gate before frame 0
import { loadFont } from '@remotion/fonts';
import { staticFile } from 'remotion';
await loadFont({ family: 'BrandSans', url: staticFile('fonts/Inter-SemiBold.woff2'), weight: '600' });
# FFmpeg: Explicit local fontsdir with full Noto Sans Unicode .ttf files
ffmpeg -y -i clip.mp4 -vf "ass=captions_ja.ass:fontsdir=./fonts" -c:v libx264 -crf 18 -pix_fmt yuv420p -movflags +faststart out_verified.mp4 Why this works: Bundling exact .woff2 and .ttf files inside Git and declaring explicit load gates removes all OS and CDN nondeterminism across macOS, Docker, and AWS Lambda.
Why This Failure Happens in Real Pipelines
When Remotion spins up headless Chromium to capture frames concurrently, Chromium paints Frame 0 immediately unless your React component pauses rendering with delayRender() until @remotion/fonts loadFont() (or document.fonts.ready) resolves. Relying on live Google Fonts URLs during a 50-variant batch also triggers sporadic network timeouts that randomly corrupt Variant #19 with system fallback fonts.
In pure FFmpeg ASS/SRT caption pipelines, libass looks up the requested Style: Default,Inter,... family name through Fontconfig. If that exact font file is absent on a Linux container—or lacks Unicode glyphs for Japanese (日本語), Arabic (العربية), or emojis—libass silently substitutes a fallback glyph or draws empty □□□ rectangles unless you pass fontsdir=./fonts explicitly pointing to bundled .ttf/.otf files.
Step-by-Step Resolution & Verification
- 01
Commit self-hosted .woff2 (Remotion) and .ttf (FFmpeg) fonts inside your repo
Place licensed brand weights plus Noto Sans JP/KR/Arabic (for multilingual batches) in public/fonts/ and fonts/ so Docker and CI containers never touch external font CDNs.
- 02
Await loadFont() via delayRender() and replace emojis with SVGO icons
Call ensureBrandFontsLoaded() at composition mount, strip raw Unicode emojis from JSON copy feeds, and render crisp inline SVG badges instead.
- 03
Pass fontsdir=./fonts to FFmpeg libass and inspect a single canary PNG first
Always render Frame 45 (headline visible) and Frame 405 (CTA visible) on Variant #1 before launching a 50-video batch render.
npx remotion still src/index.ts AdVariant out/canary_f45.png --frame=45 && ls -lh out/canary_f45.png out/canary_f45.png created cleanly; visual inspection shows exact BrandSans glyph metrics and zero tofu boxes How to Prevent This Error From Recurring
Never rely on live Google Fonts URLs inside headless CI or Docker batches
One transient 503 or slow DNS lookup silently corrupts paid video exports with fallback serif typography.
Prefer crisp Recraft V4.1 / SVGO inline icons over system color emojis
Color emoji tables (Apple Color Emoji vs Noto Color Emoji) differ wildly across macOS and Linux—SVG icons render identically on every machine.
Audit every batch with a 1-frame canary PNG + @ad-localization-qa
Catches missing accents, clipped long German lines, and font mismatches in 3 seconds instead of after 50 renders.
Troubleshooting FAQs
- Why does Remotion look right in Remotion Studio on my Mac but render the wrong font in Docker?
- Your Mac already has local desktop fonts and Apple Color Emoji installed globally. Inside a minimal Linux Docker container or AWS Lambda worker, only fonts explicitly bundled in your repo and loaded with loadFont() are guaranteed to exist.
- How do I fix missing Japanese or Arabic characters in FFmpeg ASS subtitle burns?
- Download the matching Google Noto Sans JP or Noto Sans Arabic .ttf file into
./fonts/, name that exact family inside your.assStyle header, and pass-vf "ass=subs.ass:fontsdir=./fonts"so libass loads the bundled glyphs directly. - Why does Remotion still occasionally flash a fallback font on Frame 0 even with @font-face CSS?
- CSS @font-face loads asynchronously unless explicitly blocked by Remotion’s delayRender() / continueRender() lifecycle. Using @remotion/fonts
loadFont()wrapped indelayRender()guarantees Chromium never captures Frame 0 until font bytes finish parsing.