Skip to content

🎥 Make videos programmatically with React

skill for importing captions

Jonny Burger1a90b1272995
diff --git a/packages/skills/skills/remotion/SKILL.md b/packages/skills/skills/remotion/SKILL.md
index 30b7ca837d..a00add14e0 100644
--- a/packages/skills/skills/remotion/SKILL.md
+++ b/packages/skills/skills/remotion/SKILL.md
@@ -28,6 +28,7 @@ Read individual rule files for detailed explanations and code examples:
- [rules/get-video-duration.md](rules/get-video-duration.md) - Getting the duration of a video file in seconds with Mediabunny
- [rules/gifs.md](rules/gifs.md) - Displaying GIFs synchronized with Remotion's timeline
- [rules/images.md](rules/images.md) - Embedding images in Remotion using the Img component
+- [rules/import-srt-captions.md](rules/import-srt-captions.md) - Importing .srt subtitle files into Remotion using @remotion/captions
- [rules/lottie.md](rules/lottie.md) - Embedding Lottie animations in Remotion
- [rules/measuring-dom-nodes.md](rules/measuring-dom-nodes.md) - Measuring DOM element dimensions in Remotion
- [rules/measuring-text.md](rules/measuring-text.md) - Measuring text dimensions, fitting text to containers, and checking overflow
diff --git a/packages/skills/skills/remotion/rules/import-srt-captions.md b/packages/skills/skills/remotion/rules/import-srt-captions.md
new file mode 100644
index 0000000000..0b9c5bb303
--- /dev/null
+++ b/packages/skills/skills/remotion/rules/import-srt-captions.md
@@ -0,0 +1,67 @@
+---
+name: import-srt-captions
+description: Importing .srt subtitle files into Remotion using @remotion/captions
+metadata:
+ tags: captions, subtitles, srt, import, parse
+---
+
+# Importing .srt subtitles into Remotion
+
+If you have an existing `.srt` subtitle file, you can import it into Remotion using `parseSrt()` from `@remotion/captions`.
+
+## Prerequisites
+
+First, the @remotion/captions package needs to be installed.
+If it is not installed, use the following command:
+
+```bash
+npx remotion add @remotion/captions # If project uses npm
+bunx remotion add @remotion/captions # If project uses bun
+yarn remotion add @remotion/captions # If project uses yarn
+pnpm exec remotion add @remotion/captions # If project uses pnpm
+```
+
+## Reading an .srt file
+
+Use `staticFile()` to reference an `.srt` file in your `public` folder, then fetch and parse it:
+
+```tsx
+import {useState, useEffect, useCallback} from 'react';
+import {AbsoluteFill, staticFile, useDelayRender} from 'remotion';
+import {parseSrt} from '@remotion/captions';
+import type {Caption} from '@remotion/captions';
+
+export const MyComponent: React.FC = () => {
+ const [captions, setCaptions] = useState<Caption[] | null>(null);
+ const {delayRender, continueRender, cancelRender} = useDelayRender();
+ const [handle] = useState(() => delayRender());
+
+ const fetchCaptions = useCallback(async () => {
+ try {
+ const response = await fetch(staticFile('subtitles.srt'));
+ const text = await response.text();
+ const {captions: parsed} = parseSrt({input: text});
+ setCaptions(parsed);
+ continueRender(handle);
+ } catch (e) {
+ cancelRender(e);
+ }
+ }, [continueRender, cancelRender, handle]);
+
+ useEffect(() => {
+ fetchCaptions();
+ }, [fetchCaptions]);
+
+ if (!captions) {
+ return null;
+ }
+
+ return <AbsoluteFill>{/* Use captions here */}</AbsoluteFill>;
+};
+```
+
+Remote URLs are also supported - you can `fetch()` a remote file via URL instead of using `staticFile()`.
+
+## Using imported captions
+
+Once parsed, the captions are in the `Caption` format and can be used with all `@remotion/captions` utilities.