Remotion動画ツールキット は何をしますか?
概要
ReactとRemotionを使用してプログラムで動画を作成します。Reactコンポーネントとして再利用可能な動画テンプレートを構築し、CLIまたはクラウドインフラ経由でMP4/WebMにレンダリングし、大規模なパーソナライズ動画を生成できます。自動化されたソーシャルメディアコンテンツ、アニメーションデータ可視化、動的な動画制作パイプラインに最適です。
手順
ユーザーがプログラム動画の作成を依頼したら、タスクを判断します:
タスクA: Remotionプロジェクトのセットアップ
# 新しいRemotionプロジェクトを作成
npx create-video@latest my-video
cd my-video
npm start # Remotion Studioが http://localhost:3000 で開きます
プロジェクト構造:
my-video/
src/
Root.tsx # すべてのコンポジションを登録
MyComposition.tsx # 動画コンポーネント
remotion.config.ts # レンダリング設定
タスクB: 動画コンポジションの作成
すべてのRemotion動画は、useCurrentFrame()とuseVideoConfig()を使用するReactコンポーネントです:
import { AbsoluteFill, useCurrentFrame, useVideoConfig, interpolate, spring } from "remotion";
interface MyVideoProps {
title: string;
subtitle: string;
bgColor: string;
}
export const MyVideo: React.FC<MyVideoProps> = ({ title, subtitle, bgColor }) => {
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
// タイトルがスライドインするアニメーション
const titleY = spring({ frame, fps, from: -100, to: 0, durationInFrames: 30 });
// 20フレーム後にサブタイトルがフェードイン
const subtitleOpacity = interpolate(frame, [20, 40], [0, 1], {
extrapolateRight: "clamp",
});
return (
<AbsoluteFill style={{ backgroundColor: bgColor, justifyContent: "center", alignItems: "center" }}>
<h1 style={{ fontSize: 80, color: "white", transform: `translateY(${titleY}px)` }}>
{title}
</h1>
<p style={{ fontSize: 36, color: "rgba(255,255,255,0.8)", opacity: subtitleOpacity }}>
{subtitle}
</p>
</AbsoluteFill>
);
};
コンポジションを Root.tsx に登録:
import { Composition } from "remotion";
import { MyVideo } from "./MyVideo";
export const RemotionRoot: React.FC = () => {
return (
<Composition
id="MyVideo"
component={MyVideo}
durationInFrames={150}
fps={30}
width={1920}
height={1080}
defaultProps={{ title: "Hello World", subtitle: "Made with Remotion", bgColor: "#1a1a2e" }}
/>
);
};
タスクC: TikTokスタイルのアニメーションキャプション追加
import { AbsoluteFill, useCurrentFrame, Sequence } from "remotion";
interface CaptionWord {
text: string;
startFrame: number;
durationInFrames: number;
}
const captions: CaptionWord[] = [
{ text: "This", startFrame: 0, durationInFrames: 15 },
{ text: "is", startFrame: 15, durationInFrames: 10 },
{ text: "amazing!", startFrame: 25, durationInFrames: 20 },
];
export const CaptionOverlay: React.FC = () => {
const frame = useCurrentFrame();
const activeWord = captions.find(
(c) => frame >= c.startFrame && frame < c.startFrame + c.durationInFrames
);
return (
<AbsoluteFill style={{ justifyContent: "flex-end", alignItems: "center", paddingBottom: 120 }}>
{activeWord && (
<div style={{
fontSize: 64,
fontWeight: "bold",
color: "white",
textShadow: "2px 2px 8px rgba(0,0,0,0.8)",
backgroundColor: "rgba(0,0,0,0.5)",
padding: "8px 24px",
borderRadius: 12,
}}>
{activeWord.text}
</div>
)}
</AbsoluteFill>
);
};
タスクD: 動画のレンダリング
# CLIでローカルレンダリング
npx remotion render MyVideo out/video.mp4
# カスタムプロパティでレンダリング
npx remotion render MyVideo out/video.mp4 --props='{"title":"カスタムタイトル"}'
# スチルフレームのレンダリング(サムネイル用)
npx remotion still MyVideo out/thumbnail.png --frame=45
# 特定のコーデックと品質でレンダリング
npx remotion render MyVideo out/video.mp4 --codec=h264 --crf=18
大規模なバッチレンダリング:
# AWS Lambdaでレンダリング
npx remotion lambda render MyVideo --props='{"title":"ビデオ1"}'
# Google Cloud Runでレンダリング
npx remotion cloudrun render MyVideo --props='{"title":"ビデオ1"}'
タスクE: アニメーションデータ可視化
import { AbsoluteFill, useCurrentFrame, interpolate } from "remotion";
interface DataPoint { label: string; value: number; color: string; }
export const BarChart: React.FC<{ data: DataPoint[] }> = ({ data }) => {
const frame = useCurrentFrame();
const maxVal = Math.max(...data.map((d) => d.value));
return (
<AbsoluteFill style={{ padding: 80, justifyContent: "flex-end", backgroundColor: "#0f0f23" }}>
<div style={{ display: "flex", alignItems: "flex-end", gap: 20, height: "70%" }}>
{data.map((point, i) => {
const height = interpolate(frame, [i * 10, i * 10 + 30], [0, (point.value / maxVal) * 100], {
extrapolateLeft: "clamp",
extrapolateRight: "clamp",
});
return (
<div key={i} style={{ flex: 1, textAlign: "center" }}>
<div style={{
height: `${height}%`,
backgroundColor: point.color,
borderRadius: "8px 8px 0 0",
transition: "height 0.3s",
}} />
<p style={{ color: "white", marginTop: 12, fontSize: 24 }}>{point.label}</p>
</div>
);
})}
</div>
</AbsoluteFill>
);
};
使用例
例1: パーソナライズされたウェルカム動画
ユーザーリクエスト: 「各新規ユーザー向けに名前入りのウェルカム動画を生成して」
# users.jsonのユーザーリストから動画を生成
for user in $(jq -r '.[] | @base64' users.json); do
name=$(echo "$user" | base64 -d | jq -r '.name')
npx remotion render WelcomeVideo "out/welcome_${name}.mp4" \
--props="{\"userName\":\"${name}\"}"
done
例2: アニメーション販売ダッシュボード
ユーザーリクエスト: 「四半期のメトリクスがアニメーションで表示される動画を作成して」
BarChartコンポーネントを使用して四半期データでコンポジションを構築し、以下でレンダリング:
npx remotion render SalesDashboard out/q4_report.mp4 \
--props='{"quarter":"Q4","revenue":1250000,"growth":12.5}'
例3: キャプション付きソーシャルメディアコンテンツ
ユーザーリクエスト: 「TikTok用に動画にアニメーションキャプションを追加して」
CaptionOverlayをOffthreadVideoソースと組み合わせる:
import { OffthreadVideo } from "remotion";
<AbsoluteFill>
<OffthreadVideo src="https://example.com/clip.mp4" />
<CaptionOverlay />
</AbsoluteFill>
ガイドライン
- すべてのアニメーションに
useCurrentFrame()とinterpolate()を使用し、CSSトランジションは避けてください。 - コンポジションは純粋に保ち、すべての動的データをプロパティとして渡して、簡単なバッチレンダリングを可能にしてください。
<Sequence>を使用して、動画タイムラインのセクションを整理してください。<Video>よりも<OffthreadVideo>を優先して使用し、動画ソースのパフォーマンスを向上させてください。crf(Constant Rate Factor)は16〜20に設定し、品質とサイズのバランスを取ってください。- Lambdaレンダリングの場合は、タイムアウトの問題を避けるため、コンポジションを120秒未満に保ってください。
- レンダリング前にRemotion Studioでテストし、レイアウトの問題を早期に発見してください。
staticFile()を使用して、public/フォルダ内のアセットを参照してください。