Remotion Captions — 動画用アニメーション字幕
SRTファイルからRemotion動画にアニメーション付きの字幕やキャプションを追加します。TikTokスタイルの単語単位ハイライト、カラオケ効果などに対応。
概要
- リポジトリ: github.com/ahgsql/remotion-subtitles
- 言語: TypeScript / React
- ライセンス: オープンソース
- インストール:
npm install remotion-subtitles - 必要条件: Remotionプロジェクト
セットアップ
npm install remotion-subtitles
基本的な使い方
SRTファイルから
import { useSubtitles, SubtitleSequence } from "remotion-subtitles";
export const CaptionedVideo: React.FC = () => {
const subtitles = useSubtitles("./subtitles.srt");
return (
<AbsoluteFill>
<Video src={staticFile("video.mp4")} />
<SubtitleSequence subtitles={subtitles} />
</AbsoluteFill>
);
};
SRT形式
1
00:00:00,000 --> 00:00:02,500
Custom Agentsへようこそ
2
00:00:02,500 --> 00:00:05,000
AI搭載のメールプラットフォーム
3
00:00:05,000 --> 00:00:08,000
受信箱を自動で処理します
字幕のスタイリング
<SubtitleSequence
subtitles={subtitles}
style={{
position: "absolute",
bottom: 80,
left: 0,
right: 0,
textAlign: "center",
fontSize: 42,
fontWeight: "bold",
color: "white",
textShadow: "2px 2px 8px rgba(0,0,0,0.8)",
fontFamily: "Inter, sans-serif",
}}
/>
単語単位ハイライト(TikTokスタイル)
import { useCurrentFrame, interpolate } from "remotion";
export const WordHighlightCaption: React.FC<{
words: { text: string; startFrame: number; endFrame: number }[];
}> = ({ words }) => {
const frame = useCurrentFrame();
return (
<div style={{
position: "absolute",
bottom: 100,
width: "100%",
textAlign: "center",
display: "flex",
justifyContent: "center",
gap: 8,
flexWrap: "wrap",
padding: "0 60px",
}}>
{words.map((word, i) => {
const isActive = frame >= word.startFrame && frame <= word.endFrame;
const scale = isActive
? interpolate(frame, [word.startFrame, word.startFrame + 3], [1, 1.15], { extrapolateRight: "clamp" })
: 1;
return (
<span
key={i}
style={{
fontSize: 48,
fontWeight: 800,
color: isActive ? "#FFD700" : "white",
textShadow: isActive
? "0 0 20px rgba(255,215,0,0.5)"
: "2px 2px 4px rgba(0,0,0,0.8)",
transform: `scale(${scale})`,
transition: "color 0.1s",
display: "inline-block",
}}
>
{word.text}
</span>
);
})}
</div>
);
};
手動キャプションタイミング
SRTファイルがない場合は、手動でキャプションを定義します:
const captions = [
{ text: "Custom Agentsへようこそ", startFrame: 0, endFrame: 75 },
{ text: "AI搭載のメール自動化", startFrame: 80, endFrame: 150 },
{ text: "エージェントを数分で作成", startFrame: 155, endFrame: 240 },
];
export const ManualCaptions: React.FC = () => {
const frame = useCurrentFrame();
const current = captions.find(
(c) => frame >= c.startFrame && frame <= c.endFrame
);
if (!current) return null;
const progress = interpolate(
frame,
[current.startFrame, current.startFrame + 10],
[0, 1],
{ extrapolateRight: "clamp" }
);
return (
<div style={{
position: "absolute",
bottom: 80,
width: "100%",
textAlign: "center",
opacity: progress,
transform: `translateY(${(1 - progress) * 10}px)`,
}}>
<span style={{
fontSize: 44,
fontWeight: 700,
color: "white",
backgroundColor: "rgba(0,0,0,0.6)",
padding: "8px 24px",
borderRadius: 8,
}}>
{current.text}
</span>
</div>
);
};
ベストプラクティス
- 下部に配置 — 標準的な字幕配置は下部中央
- コントラストを利用 — 白いテキストに暗い影または半透明の背景
- 大きめのフォント — 動画での可読性のために最低40-50px
- 短いフレーズ — 最大2行、キャプションあたり6-8語
- タイミングバッファ — 字幕は音声の2-3フレーム前に開始
- 入場アニメーション — 微妙なフェード/スライドイン、終了はアニメーションなし
- 太字 — 動画の可読性のために700以上のフォントウェイト
ソース
- remotion-subtitles: github.com/ahgsql/remotion-subtitles
- Remotion Audiogram テンプレート: github.com/remotion-dev/template-audiogram