何时使用
在以下情况下使用此技能:
- 通过代码创建程序化视频(非生成式 AI 视频)
- 构建数据驱动的视频内容(图表、统计、个性化视频)
- 根据模板和数据批量生成视频
- 创建动画社交媒体内容(TikTok、Reels、Shorts)
- 构建需要精确控制的产品/解释性视频
快速入门
1. 创建新项目
python3 Skills/remotion/scripts/remotion_cli.py new my-video --template blank
cd Sites/my-video
2. 编写你的合成
编辑 src/Composition.tsx —— 这是你的视频,定义为 React 组件。
3. 在工作室中预览
python3 Skills/remotion/scripts/remotion_cli.py studio my-video
4. 渲染为 MP4
python3 Skills/remotion/scripts/remotion_cli.py render my-video --output output.mp4
核心概念
合成
合成定义了视频的尺寸、时长和帧率:
<Composition
id="MyVideo"
component={MyComponent}
durationInFrames={300} // 10秒,30fps
fps={30}
width={1920}
height={1080}
/>
基于帧的动画
所有动画必须使用 useCurrentFrame()。禁止使用 CSS 动画。
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
const opacity = interpolate(frame, [0, fps], [0, 1], { extrapolateRight: 'clamp' });
序列
使用 <Sequence> 来控制元素出现的时间:
<Sequence from={30} durationInFrames={60}>
<Title />
</Sequence>
规则参考
阅读以下文件以获取详细模式(从上游 Remotion 技能加载):
| 规则 | 描述 |
|---|---|
references/animations.md | 基于帧的动画基础 |
references/timing.md | 弹簧、缓动、插值曲线 |
references/compositions.md | 定义合成、静态帧、文件夹 |
references/sequencing.md | 元素的时序和排序 |
references/videos.md | 嵌入视频——裁剪、音量、速度 |
references/audio.md | 音频处理——导入、裁剪、音量 |
references/assets.md | 图片、字体、静态文件 |
references/transitions.md | 场景过渡 |
references/text-animations.md | 排版动画模式 |
references/charts.md | 数据可视化模式 |
references/display-captions.md | TikTok 风格字幕 |
CLI 命令
# 项目管理
python3 Skills/remotion/scripts/remotion_cli.py new <name> [--template blank|hello-world]
python3 Skills/remotion/scripts/remotion_cli.py studio <name>
python3 Skills/remotion/scripts/remotion_cli.py render <name> [--composition ID] [--output path]
python3 Skills/remotion/scripts/remotion_cli.py list
# 渲染选项
--composition ID # 要渲染的特定合成(默认:第一个)
--output PATH # 输出文件路径(默认:out/video.mp4)
--fps N # 覆盖 FPS
--width N # 覆盖宽度
--height N # 覆盖高度
--codec CODEC # h264, h265, vp8, vp9, prores(默认:h264)
常见模式
淡入/淡出
const frame = useCurrentFrame();
const { fps, durationInFrames } = useVideoConfig();
const fadeIn = interpolate(frame, [0, fps], [0, 1], { extrapolateRight: 'clamp' });
const fadeOut = interpolate(frame, [durationInFrames - fps, durationInFrames], [1, 0], { extrapolateLeft: 'clamp' });
const opacity = fadeIn * fadeOut;
弹簧动画(自然运动)
const scale = spring({
frame,
fps,
config: { damping: 200 }, // 平滑,无弹跳
});
交错元素
{items.map((item, i) => (
<Sequence key={i} from={i * 10}>
<Item data={item} />
</Sequence>
))}
数据驱动视频
type VideoProps = { title: string; stats: number[] };
export const DataVideo: React.FC<VideoProps> = ({ title, stats }) => {
// 根据属性进行动画
};
// 在 Root.tsx 中:
<Composition
id="DataVideo"
component={DataVideo}
defaultProps={{ title: "Q4 结果", stats: [10, 20, 30] }}
// ...
/>
与 Zo 集成
批量渲染
使用 /zo/ask 并行渲染多个视频:
for row in data:
# 每次调用使用不同的属性进行渲染
await render_video(row)
输出位置
项目位于 Sites/<name>/ 目录下,以保持与 Zo 站点系统的一致性。
渲染后的视频输出到 Sites/<name>/out/。
限制
- 无 CSS 动画 —— 它们无法正确渲染
- 无 Tailwind 动画类 —— 同样的问题
- 仅限基于帧的动画 —— 所有运动都来自
useCurrentFrame() - CPU 密集型 —— 渲染需要时间;复杂视频需要更长的渲染时间
- 需要 Node.js —— Remotion 需要 Node 环境(Zo 中已提供)