Skip to content

πŸŽ₯ Make videos programmatically with React

new cards

Jonny Burger638208763986
diff --git a/packages/docs/docs/captions/displaying.mdx b/packages/docs/docs/captions/displaying.mdx
index 8883e24cce..4567c76e80 100644
--- a/packages/docs/docs/captions/displaying.mdx
+++ b/packages/docs/docs/captions/displaying.mdx
@@ -2,14 +2,13 @@
image: /generated/articles-docs-captions-displaying.png
sidebar_label: Displaying
title: Displaying captions
-crumb: '@remotion/captions'
+crumb: Captions
---
# Displaying captions
This guide explains how to display captions in Remotion, assuming you already have captions in the [`Caption`](/docs/captions/caption) format - see [Transcribing audio](/docs/captions/transcribing) for how to generate them.
-
## Fetching captions
First, fetch your captions JSON file. Use [`useDelayRender()`](/docs/use-delay-render) to hold the render until the captions are loaded:
@@ -85,9 +84,7 @@ const SWITCH_CAPTIONS_EVERY_MS = 1200;
const pages: TikTokPage[] = [];
-const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => (
- <div>{page.text}</div>
-);
+const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => <div>{page.text}</div>;
// ---cut---
@@ -99,10 +96,7 @@ const CaptionedContent: React.FC = () => {
{pages.map((page, index) => {
const nextPage = pages[index + 1] ?? null;
const startFrame = (page.startMs / 1000) * fps;
- const endFrame = Math.min(
- nextPage ? (nextPage.startMs / 1000) * fps : Infinity,
- startFrame + (SWITCH_CAPTIONS_EVERY_MS / 1000) * fps,
- );
+ const endFrame = Math.min(nextPage ? (nextPage.startMs / 1000) * fps : Infinity, startFrame + (SWITCH_CAPTIONS_EVERY_MS / 1000) * fps);
const durationInFrames = endFrame - startFrame;
if (durationInFrames <= 0) {
@@ -110,11 +104,7 @@ const CaptionedContent: React.FC = () => {
}
return (
- <Sequence
- key={index}
- from={startFrame}
- durationInFrames={durationInFrames}
- >
+ <Sequence key={index} from={startFrame} durationInFrames={durationInFrames}>
<CaptionPage page={page} />
</Sequence>
);
@@ -160,8 +150,7 @@ const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => {
}}
>
{page.tokens.map((token) => {
- const isActive =
- token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
+ const isActive = token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
return (
<span
@@ -187,14 +176,7 @@ const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => {
```tsx twoslash title="Full captioned video example"
import {useState, useEffect, useCallback, useMemo} from 'react';
-import {
- AbsoluteFill,
- Sequence,
- staticFile,
- useCurrentFrame,
- useDelayRender,
- useVideoConfig,
-} from 'remotion';
+import {AbsoluteFill, Sequence, staticFile, useCurrentFrame, useDelayRender, useVideoConfig} from 'remotion';
import {createTikTokStyleCaptions} from '@remotion/captions';
import type {Caption, TikTokPage} from '@remotion/captions';
@@ -223,8 +205,7 @@ const CaptionPage: React.FC<{page: TikTokPage}> = ({page}) => {
}}
>
{page.tokens.map((token) => {
- const isActive =
- token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
+ const isActive = token.fromMs <= absoluteTimeMs && token.toMs > absoluteTimeMs;
return (
<span
@@ -275,10 +256,7 @@ export const CaptionedVideo: React.FC = () => {
{pages.map((page, index) => {
const nextPage = pages[index + 1] ?? null;
const startFrame = (page.startMs / 1000) * fps;
- const endFrame = Math.min(
- nextPage ? (nextPage.startMs / 1000) * fps : Infinity,
- startFrame + (SWITCH_CAPTIONS_EVERY_MS / 1000) * fps,
- );
+ const endFrame = Math.min(nextPage ? (nextPage.startMs / 1000) * fps : Infinity, startFrame + (SWITCH_CAPTIONS_EVERY_MS / 1000) * fps);
const durationInFrames = endFrame - startFrame;
if (durationInFrames <= 0) {
@@ -286,11 +264,7 @@ export const CaptionedVideo: React.FC = () => {
}
return (
- <Sequence
- key={index}
- from={startFrame}
- durationInFrames={durationInFrames}
- >
+ <Sequence key={index} from={startFrame} durationInFrames={durationInFrames}>
<CaptionPage page={page} />
</Sequence>
);
diff --git a/packages/docs/docs/captions/exporting.mdx b/packages/docs/docs/captions/exporting.mdx
index 2507a810d6..a6cd9a61bd 100644
--- a/packages/docs/docs/captions/exporting.mdx
+++ b/packages/docs/docs/captions/exporting.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-captions-exporting.png
sidebar_label: Exporting
title: Exporting subtitles
-crumb: '@remotion/captions'
+crumb: Captions
---
# Exporting subtitles
@@ -11,13 +11,12 @@ This guide covers different ways to export subtitles from your Remotion video.
## Burned-in subtitles
-If you want the subtitles to be part of the video itself (burned in), follow the instructions in [Displaying captions](/docs/captions/displaying) to render the captions, then simply [render the video](/docs/render) as usual.
+If you want the subtitles to be part of the video itself (burned in), follow the instructions in [Displaying captions](/docs/captions/displaying) to render the captions, then simply [render the video](/docs/render) as usual.
```bash
npx remotion render
```
-
## Exporting as a separate .srt file
To export subtitles as a separate `.srt` file, use the [`<Artifact>`](/docs/artifact) component together with [`serializeSrt()`](/docs/captions/serialize-srt).
@@ -58,9 +57,7 @@ export const MyComp: React.FC = () => {
return (
<>
{/* Only emit the artifact on the first frame */}
- {frame === 0 ? (
- <Artifact filename="subtitles.srt" content={srtContent} />
- ) : null}
+ {frame === 0 ? <Artifact filename="subtitles.srt" content={srtContent} /> : null}
{/* Rest of your video content */}
</>
);
diff --git a/packages/docs/docs/captions/index.mdx b/packages/docs/docs/captions/index.mdx
index dba38c75f2..e9be10e82b 100644
--- a/packages/docs/docs/captions/index.mdx
+++ b/packages/docs/docs/captions/index.mdx
@@ -1,7 +1,6 @@
---
image: /generated/articles-docs-captions-index.png
title: Captions
-crumb: 'Subtitle videos'
sidebar_label: Overview
---
diff --git a/packages/docs/docs/captions/transcribing.mdx b/packages/docs/docs/captions/transcribing.mdx
index 02e0fc1c75..af0a51d4ba 100644
--- a/packages/docs/docs/captions/transcribing.mdx
+++ b/packages/docs/docs/captions/transcribing.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-captions-transcribing.png
sidebar_label: Transcribing
title: Transcribing audio
-crumb: '@remotion/captions'
+crumb: Captions
---
# Transcribing audio
@@ -15,14 +15,14 @@ Remotion provides several built-in options for transcribing audio to generate ca
## Comparison
-| | [`@remotion/install-whisper-cpp`](/docs/install-whisper-cpp) | [`@remotion/whisper-web`](/docs/whisper-web) | [`@remotion/openai-whisper`](/docs/openai-whisper) |
-| -------------------- | --------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------ |
-| **Environment** | Server (Node.js) | Client (Browser) | Cloud (API) |
-| **Speed** | Fast (depends on hardware) | Slow (WASM overhead) | Fast |
-| **Cost** | Free | Free | Paid (OpenAI API pricing) |
-| **Offline support** | βœ… | βœ… | ❌ |
-| **No server needed** | ❌ | βœ… | βœ… |
-| **Convert function** | [`convertToCaptions()`](/docs/install-whisper-cpp/convert-to-captions) | [`toCaptions()`](/docs/whisper-web/to-captions) | [`openaiWhisperApiToCaptions()`](/docs/openai-whisper/openai-whisper-api-to-captions) |
+| | [`@remotion/install-whisper-cpp`](/docs/install-whisper-cpp) | [`@remotion/whisper-web`](/docs/whisper-web) | [`@remotion/openai-whisper`](/docs/openai-whisper) |
+| -------------------- | ---------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------- |
+| **Environment** | Server (Node.js) | Client (Browser) | Cloud (API) |
+| **Speed** | Fast (depends on hardware) | Slow (WASM overhead) | Fast |
+| **Cost** | Free | Free | Paid (OpenAI API pricing) |
+| **Offline support** | βœ… | βœ… | ❌ |
+| **No server needed** | ❌ | βœ… | βœ… |
+| **Convert function** | [`convertToCaptions()`](/docs/install-whisper-cpp/convert-to-captions) | [`toCaptions()`](/docs/whisper-web/to-captions) | [`openaiWhisperApiToCaptions()`](/docs/openai-whisper/openai-whisper-api-to-captions) |
## The `Caption` type
@@ -37,7 +37,6 @@ All of these options can output captions in the [`Caption`](/docs/captions/capti
You can use other ways of transcribing audio, such as [ElevenLabs](https://elevenlabs.io/).
You can also define your own caption format and not rely on the `Caption` type - this page is solely about the built-in options.
-
## See also
- [`Caption`](/docs/captions/caption) - The caption data structure
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 1176867165..5574c3a08b 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -481,7 +481,7 @@ export const articles = [
title: 'Displaying captions',
relativePath: 'docs/captions/displaying.mdx',
compId: 'articles-docs-captions-displaying',
- crumb: '@remotion/captions',
+ crumb: 'Captions',
noAi: false,
slug: 'captions/displaying',
},
@@ -499,7 +499,7 @@ export const articles = [
title: 'Exporting subtitles',
relativePath: 'docs/captions/exporting.mdx',
compId: 'articles-docs-captions-exporting',
- crumb: '@remotion/captions',
+ crumb: 'Captions',
noAi: false,
slug: 'captions/exporting',
},
@@ -517,7 +517,7 @@ export const articles = [
title: 'Captions',
relativePath: 'docs/captions/index.mdx',
compId: 'articles-docs-captions-index',
- crumb: 'Subtitle videos',
+ crumb: null,
noAi: false,
slug: 'captions/index',
},
@@ -544,7 +544,7 @@ export const articles = [
title: 'Transcribing audio',
relativePath: 'docs/captions/transcribing.mdx',
compId: 'articles-docs-captions-transcribing',
- crumb: '@remotion/captions',
+ crumb: 'Captions',
noAi: false,
slug: 'captions/transcribing',
},
diff --git a/packages/docs/static/generated/articles-docs-captions-exporting.png b/packages/docs/static/generated/articles-docs-captions-exporting.png
index c115035757..2315401153 100644
Binary files a/packages/docs/static/generated/articles-docs-captions-exporting.png and b/packages/docs/static/generated/articles-docs-captions-exporting.png differ
diff --git a/packages/docs/static/generated/articles-docs-captions-transcribing.png b/packages/docs/static/generated/articles-docs-captions-transcribing.png
index 24edf3c21e..b1b0f74887 100644
Binary files a/packages/docs/static/generated/articles-docs-captions-transcribing.png and b/packages/docs/static/generated/articles-docs-captions-transcribing.png differ