Deft
Ask AI

Search

Search skills, authors and topics

remotion-dev / skills

remotion-captions

Transcribe, display, and animate captions in Remotion compositions.

Install

npx skills add https://github.com/remotion-dev/skills --skill 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.

If you don't have a .srt file, read Transcribing audio [blocked] for how to generate captions instead.

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 npmbunx remotion add @remotion/captions # If project uses bunyarn remotion add @remotion/captions # If project uses yarnpnpm 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 { 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 (    <>      {/* Use captions here */}    </>  );};

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.