Skills2026年3月29日·1 分钟阅读

Remotion Rule: Import Srt Captions

Remotion skill rule: Importing .srt subtitle files into Remotion using @remotion/captions. Part of the official Remotion Agent Skill for programmatic video in React.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Remotion Rule: Import Srt Captions
先审查命令
npx -y tokrepo@latest install 35ed666e-ab87-4ac0-9308-7ef73f9f0e9a --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Use @remotion/captions to parse .srt subtitle files and render them as timed captions in Remotion videos.
§01

What it is

This is a Remotion skill rule for importing .srt (SubRip) subtitle files into Remotion video projects. It uses the @remotion/captions package to parse SRT files and convert them into timed caption data that can be rendered as text overlays in your video composition.

The rule is part of the official Remotion Agent Skill collection, designed for developers using AI coding assistants (Claude Code, Cursor, OpenAI Codex) to build React-based programmatic videos with subtitles.

§02

How it saves time or tokens

Parsing SRT files manually requires handling timestamp formats, multi-line text, and sequence numbering. The @remotion/captions package handles all parsing details and returns structured caption data ready for rendering. Without this rule, an AI assistant might generate custom SRT parsers or suggest incompatible libraries. The rule ensures the assistant uses the official Remotion package directly.

§03

How to use

  1. Install the Remotion skills collection:
npx skills add remotion-dev/skills
  1. Add the captions package to your project:
npx remotion add @remotion/captions
  1. Import and parse an SRT file in your Remotion project.
§04

Example

import { parseSrt } from '@remotion/captions';
import { useCurrentFrame, useVideoConfig } from 'remotion';
import fs from 'fs';

// In a Node.js script or getStaticProps
const srtContent = fs.readFileSync('subtitles.srt', 'utf-8');
const captions = parseSrt({ input: srtContent });

// In a Remotion component
export const SubtitleOverlay: React.FC<{ captions: Caption[] }> = ({ captions }) => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();
  const currentTime = frame / fps;

  const activeCaption = captions.find(
    c => currentTime >= c.startMs / 1000 && currentTime <= c.endMs / 1000
  );

  if (!activeCaption) return null;
  return (
    <div style={{ position: 'absolute', bottom: 50, textAlign: 'center', width: '100%' }}>
      <span style={{ background: 'rgba(0,0,0,0.7)', color: 'white', padding: '4px 12px' }}>
        {activeCaption.text}
      </span>
    </div>
  );
};
§05

Related on TokRepo

§06

Common pitfalls

  • SRT files must use UTF-8 encoding; files with other encodings (e.g., ISO-8859-1) will produce garbled characters. Convert to UTF-8 before parsing.
  • The parseSrt function returns timestamps in milliseconds; convert to seconds (divide by 1000) when comparing with Remotion's frame-based timing.
  • Large SRT files with hundreds of entries are fine for parsing but may need optimization for rendering; avoid re-searching the full array on every frame by pre-computing frame-to-caption mappings.

常见问题

What SRT format does Remotion support?+

Remotion's parseSrt function supports standard SubRip (.srt) format with sequence numbers, timestamps (HH:MM:SS,mmm), and text content. It handles multi-line captions and common formatting variations.

Can I style captions individually?+

Yes. The parsed caption data is plain objects with text and timing. You control all rendering in your React component, so you can apply any CSS styles, animations, or effects to individual captions.

Does this work with VTT files?+

The parseSrt function is specifically for SRT files. For WebVTT (.vtt) files, check if @remotion/captions provides a separate parser, or convert VTT to SRT before importing.

Do I need to install anything extra?+

Run npx skills add remotion-dev/skills for the AI skill rule, and npx remotion add @remotion/captions for the caption parsing package. Both are needed for full functionality.

Can I generate SRT files from audio with Remotion?+

Yes. Use the @remotion/install-whisper-cpp package to transcribe audio to captions, then export as SRT. This pairs well with the import SRT rule for round-trip caption workflows.

引用来源 (3)
🙏

来源与感谢

Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule: import-srt-captions

Part of the Remotion AI Skill collection on TokRepo.

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产