mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-22 13:20:31 +08:00
Translated 85 skill sub-reference files to achieve full parity with the English source: - skills/angular-developer/references/ — 35 files (all references) - skills/remotion-video-creation/rules/ — 28 files (all rules) - skills/tinystruct-patterns/references/ — 5 files - skills/openclaw-persona-forge/references/ — 6 files - skills/skill-comply/prompts/ — 3 files - skills/lead-intelligence/agents/ — 4 files - skills/brand-voice/references/ — 1 file - skills/frontend-slides/ — 2 files - hooks/memory-persistence/README.md — 1 file English source parity: 0 missing files (excluding rules/zh/, internal docs, and experimental examples absent from zh-CN)
68 lines
2.4 KiB
Markdown
68 lines
2.4 KiB
Markdown
---
|
|
name: import-srt-captions
|
|
description: @remotion/captionsを使ってRemotionに.srt字幕ファイルをインポートする
|
|
metadata:
|
|
tags: captions, subtitles, srt, import, parse
|
|
---
|
|
|
|
# Remotionへの.srt字幕のインポート
|
|
|
|
既存の `.srt` 字幕ファイルがある場合、`@remotion/captions` の `parseSrt()` を使ってRemotionにインポートできます。
|
|
|
|
## 前提条件
|
|
|
|
まず、@remotion/captionsパッケージをインストールする必要があります。
|
|
インストールされていない場合は、以下のコマンドを使用します:
|
|
|
|
```bash
|
|
npx remotion add @remotion/captions # npmを使うプロジェクト
|
|
bunx remotion add @remotion/captions # bunを使うプロジェクト
|
|
yarn remotion add @remotion/captions # yarnを使うプロジェクト
|
|
pnpm exec remotion add @remotion/captions # pnpmを使うプロジェクト
|
|
```
|
|
|
|
## .srtファイルの読み込み
|
|
|
|
`staticFile()` で `public` フォルダ内の `.srt` ファイルを参照し、フェッチしてパースします:
|
|
|
|
```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>{/* ここでキャプションを使用 */}</AbsoluteFill>;
|
|
};
|
|
```
|
|
|
|
リモートURLもサポートされています。`staticFile()` の代わりにURLを指定してリモートファイルを `fetch()` できます。
|
|
|
|
## インポートしたキャプションの使用
|
|
|
|
パース後、キャプションは `Caption` 形式となり、すべての `@remotion/captions` ユーティリティで使用できます。
|