目的
此技能为 Claude Code 和 AI 编码智能体提供使用 Remotion 构建生产级视频的全面上下文。它包括设计原则、精选模板和最佳实践。
何时使用
在以下情况下使用此技能:
- 使用 React 以编程方式创建视频内容
- 构建播客音频图或音频可视化
- 为视频添加动画字幕(TikTok/Reels 风格)
- 创建 3D 产品展示
- 构建视频生成 SaaS
- 制作数据可视化视频
- 大规模生成社交媒体内容
视频设计原则
1. 节奏与韵律
- 快速剪辑:1-2 秒,适用于充满活力的社交媒体
- 中等节奏:3-5 秒,适用于教程类的理解
- 慢节奏:5-10 秒,适用于电影般的强调
- 匹配音频:将转场与节拍/语音同步
2. 视觉层次
- 每帧一个焦点
- 使用动效引导注意力
- 对比重要元素
- 保持一致的间距
3. 视频文本规则
- 每帧最多 7 个单词
- 高对比度(白色背景深色文字,或带轮廓)
- 让文本在屏幕上停留足够长的时间,以便阅读两遍
- 放置在下方三分之一或中心位置
- 避免边缘(安全区域:10% 边距)
4. 动画时间
| 元素 | 时长 (帧) | 缓动函数 |
|---|---|---|
| 文字出现 | 8-15 | easeOut |
| 文字退出 | 6-10 | easeIn |
| 场景转场 | 15-30 | easeInOut |
| Logo 展示 | 30-60 | spring |
| 快速切换 | 0-3 | linear |
5. 帧率
- 30fps:标准视频、社交媒体
- 60fps:流畅动效、游戏内容
- 24fps:电影感
- 25fps:欧洲广播标准
6. 宽高比
| 平台 | 比例 | 分辨率 |
|---|---|---|
| YouTube | 16:9 | 1920x1080 |
| TikTok/Reels | 9:16 | 1080x1920 |
| Instagram 动态 | 1:1 | 1080x1080 |
| Instagram 故事 | 9:16 | 1080x1920 |
| 16:9 | 1280x720 | |
| 16:9 | 1920x1080 |
快速开始
安装
# 使用模板选择创建新项目
npx create-video@latest
# 手动设置
mkdir my-video && cd my-video
npm init -y
npm install remotion @remotion/cli react react-dom
npm install -D typescript @types/react
项目结构
src/
├── index.ts # registerRoot
├── Root.tsx # 合成定义
├── compositions/
│ ├── Main.tsx # 主视频
│ └── Intro.tsx # 介绍序列
├── components/
│ ├── Text.tsx # 动画文字
│ └── Logo.tsx # Logo 展示
└── assets/
├── fonts/
├── images/
└── audio/
Root.tsx 模板
import { Composition } from 'remotion';
import { Main } from './compositions/Main';
export const RemotionRoot = () => {
return (
<>
<Composition
id="Main"
component={Main}
durationInFrames={300}
fps={30}
width={1920}
height={1080}
defaultProps={{
title: "My Video"
}}
/>
</>
);
};
核心模式
动画基础
import { useCurrentFrame, useVideoConfig, interpolate, spring } from 'remotion';
const frame = useCurrentFrame();
const { fps, width, height, durationInFrames } = useVideoConfig();
// 线性插值(限制)
const opacity = interpolate(frame, [0, 30], [0, 1], {
extrapolateRight: 'clamp'
});
// 弹簧动画(有弹性)
const scale = spring({
frame,
fps,
config: { damping: 12, stiffness: 200 }
});
// 延迟弹簧动画
const delayedScale = spring({
frame: frame - 15, // 15 帧延迟
fps,
config: { damping: 10 }
});
序列化
import { Sequence, AbsoluteFill } from 'remotion';
export const MyVideo = () => (
<AbsoluteFill>
<Sequence from={0} durationInFrames={60}>
<Intro />
</Sequence>
<Sequence from={60} durationInFrames={120}>
<MainContent />
</Sequence>
<Sequence from={180}>
<Outro />
</Sequence>
</AbsoluteFill>
);
文字动画
const TextReveal = ({ text }: { text: string }) => {
const frame = useCurrentFrame();
const words = text.split(' ');
return (
<div style={{ display: 'flex', gap: 10, justifyContent: 'center' }}>
{words.map((word, i) => {
const delay = i * 5;
const opacity = interpolate(frame - delay, [0, 10], [0, 1], {
extrapolateLeft: 'clamp',
extrapolateRight: 'clamp'
});
const y = interpolate(frame - delay, [0, 10], [20, 0], {
extrapolateLeft: 'clamp',
extrapolateRight: 'clamp'
});
return (
<span key={i} style={{ opacity, transform: `translateY(${y}px)` }}>
{word}
</span>
);
})}
</div>
);
};
音频同步
import { Audio, useCurrentFrame, interpolate } from 'remotion';
import { getAudioDurationInSeconds } from '@remotion/media-utils';
// 音量包络
const frame = useCurrentFrame();
const volume = interpolate(frame, [0, 30, 270, 300], [0, 1, 1, 0]);
<Audio src={staticFile('music.mp3')} volume={volume} />
模板目录
字幕与标题
remotion-subtitles(17 种样式)
npm install @ahgsql/remotion-subtitles
import { Subtitle } from '@ahgsql/remotion-subtitles';
// 可用样式:bounce, fire, glitch, neon, typewriter,
// 3d, lightning, glowing, explosive, wave, slide, fade,
// zoom, rotate, flip, shake, pulse
<Subtitle
src={staticFile('captions.srt')}
style="bounce"
fontSize={48}
color="#ffffff"
strokeColor="#000000"
strokeWidth={2}
/>
TikTok 风格字幕
const Caption = ({ text, highlight }: { text: string; highlight: number }) => {
const words = text.split(' ');
return (
<div style={{
position: 'absolute',
bottom: '20%',
width: '100%',
textAlign: 'center',
fontSize: 64,
fontWeight: 900,
textTransform: 'uppercase'
}}>
{words.map((word, i) => (
<span
key={i}
style={{
color: i === highlight ? '#FFE135' : '#FFFFFF',
textShadow: '4px 4px 0 #000, -4px -4px 0 #000, 4px -4px 0 #000, -4px 4px 0 #000'
}}
>
{word}{' '}
</span>
))}
</div>
);
};
音频可视化
波形可视化
import { useAudioData, visualizeAudio } from '@remotion/media-utils';
const Waveform = ({ src }: { src: string }) => {
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
const audioData = useAudioData(src);
if (!audioData) return null;
const visualization = visualizeAudio({
fps,
frame,
audioData,
numberOfSamples: 64
});
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
{visualization.map((amplitude, i) => (
<div
key={i}
style={{
width: 8,
height: amplitude * 200,
backgroundColor: '#667eea',
borderRadius: 4
}}
/>
))}
</div>
);
};
圆形音频可视化
const CircularVisualizer = ({ audioData, frame, fps }) => {
const visualization = visualizeAudio({ fps, frame, audioData, numberOfSamples: 32 });
const radius = 150;
return (
<svg width={400} height={400} viewBox="0 0 400 400">
{visualization.map((amp, i) => {
const angle = (i / visualization.length) * Math.PI * 2;
const x1 = 200 + Math.cos(angle) * radius;
const y1 = 200 + Math.sin(angle) * radius;
const x2 = 200 + Math.cos(angle) * (radius + amp * 100);
const y2 = 200 + Math.sin(angle) * (radius + amp * 100);
return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} stroke="#667eea" strokeWidth={4} />;
})}
</svg>
);
};
使用 Three.js 进行 3D 渲染
设置
npm install @remotion/three three @react-three/fiber @react-three/drei
手机模型
import { ThreeCanvas } from '@remotion/three';
import { useFrame } from '@react-three/fiber';
const PhoneMockup = ({ videoSrc }: { videoSrc: string }) => {
const frame = useCurrentFrame();
const rotation = interpolate(frame, [0, 150], [0, Math.PI * 2]);
return (
<ThreeCanvas>
<ambientLight intensity={0.5} />
<pointLight position={[10, 10, 10]} />
<mesh rotation={[0, rotation, 0]}>
<boxGeometry args={[2, 4, 0.2]} />
<meshStandardMaterial color="#1a1a2e" />
</mesh>
</ThreeCanvas>
);
};
社交媒体模板
Instagram Reel 开场
const ReelIntro = ({ username, avatar }: Props) => {
const frame = useCurrentFrame();
const scale = spring({ frame, fps: 30, config: { damping: 12 } });
return (
<AbsoluteFill style={{ background: 'linear-gradient(135deg, #667eea, #764ba2)' }}>
<div style={{
transform: `scale(${scale})`,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%'
}}>
<img
src={avatar}
style={{ width: 120, height: 120, borderRadius: '50%', border: '4px solid white' }}
/>
<h1 style={{ color: 'white', fontSize: 48, marginTop: 20 }}>@{username}</h1>
</div>
</AbsoluteFill>
);
};
YouTube 订阅号召
const SubscribeCTA = () => {
const frame = useCurrentFrame();
const slideIn = interpolate(frame, [0, 20], [100, 0], { extrapolateRight: 'clamp' });
const bellWiggle = Math.sin(frame * 0.5) * 10;
return (
<div style={{
position: 'absolute',
bottom: 50,
right: 50,
transform: `translateX(${slideIn}%)`,
display: 'flex',
alignItems: 'center',
gap: 20,
background: 'rgba(0,0,0,0.8)',
padding: '20px 30px',
borderRadius: 50
}}>
<div style={{
background: '#FF0000',
padding: '12px 24px',
borderRadius: 4,
color: 'white',
fontWeight: 'bold'
}}>
SUBSCRIBE
</div>
<div style={{ transform: `rotate(${bellWiggle}deg)`, fontSize: 32 }}>
🔔
</div>
</div>
);
};
特效库
故障效果
const GlitchText = ({ text }: { text: string }) => {
const frame = useCurrentFrame();
const glitchOffset = Math.random() > 0.9 ? Math.random() * 10 - 5 : 0;
return (
<div style={{ position: 'relative' }}>
<span style={{
position: 'absolute',
left: glitchOffset,
color: 'cyan',
clipPath: 'inset(0 0 50% 0)'
}}>
{text}
</span>
<span style={{
position: 'absolute',
left: -glitchOffset,
color: 'magenta',
clipPath: 'inset(50% 0 0 0)'
}}>
{text}
</span>
<span style={{ color: 'white' }}>{text}</span>
</div>
);
};
粒子场
const Particles = ({ count = 50 }: { count?: number }) => {
const frame = useCurrentFrame();
const particles = useMemo(() =>
Array.from({ length: count }, () => ({
x: Math.random() * 100,
y: Math.random() * 100,
size: Math.random() * 4 + 2,
speed: Math.random() * 0.5 + 0.2
})),
[]
);
return (
<AbsoluteFill style={{ overflow: 'hidden' }}>
{particles.map((p, i) => (
<div
key={i}
style={{
position: 'absolute',
left: `${p.x}%`,
top: `${(p.y + frame * p.speed) % 100}%`,
width: p.size,
height: p.size,
borderRadius: '50%',
background: 'rgba(255,255,255,0.5)'
}}
/>
))}
</AbsoluteFill>
);
};
渐变背景
const AnimatedGradient = () => {
const frame = useCurrentFrame();
const hue1 = (frame * 0.5) % 360;
const hue2 = (hue1 + 60) % 360;
return (
<div style={{
width: '100%',
height: '100%',
background: `linear-gradient(${hue1}deg, hsl(${hue1}, 70%, 50%), hsl(${hue2}, 70%, 50%))`
}} />
);
};