Remotion 视频生成技能
App Factory 包含一个集成的 Remotion 视频管道,用于生成已构建应用的演示视频。
何时应用此技能
- 处理
demo-video/目录中的文件 - 运行
/factory video命令 - 创建或修改 Remotion 组合
- 调试视频渲染问题
- 理解基于帧的动画
项目结构
demo-video/
├── src/
│ ├── index.ts # Remotion 入口点
│ ├── Root.tsx # 组合注册表
│ └── compositions/
│ └── AppFactoryDemo.tsx # 主演示视频(10秒,1920x1080)
│ └── components/
│ ├── Title.tsx # 动画标题
│ ├── BulletPoints.tsx # 交错高亮
│ ├── VerificationBadge.tsx # PASS 徽章
│ └── Footer.tsx # UTC 时间戳
├── remotion.config.ts # Remotion 配置
└── package.json # 依赖项(Remotion v4.x)
关键规则(必须遵循)
1. 仅使用基于帧的动画
// 正确:所有动画使用 useCurrentFrame()
const frame = useCurrentFrame();
const opacity = interpolate(frame, [0, 30], [0, 1], {
extrapolateRight: 'clamp',
});
// 禁止:使用 CSS 动画/过渡
// 永远不要使用:animation:、transition:、@keyframes
2. 插值时使用钳制
// 始终使用 extrapolation 钳制
const value = interpolate(frame, [0, 60], [0, 100], {
extrapolateLeft: 'clamp',
extrapolateRight: 'clamp',
});
3. 弹簧动画
// 使用 spring() 进行基于物理的动画
const springValue = spring({
fps,
frame,
config: { damping: 200, stiffness: 100 },
durationInFrames: 40,
});
4. 确定性要求
- 时间戳必须是输入属性,绝不能使用
new Date() - 所有日期格式化必须使用
timeZone: 'UTC' - 不能使用
Math.random()或非确定性值 - 相同的属性必须产生相同的视频输出
5. 组件结构
// 所有组合必须遵循此模式
export const MyComposition: React.FC<Props> = (props) => {
const frame = useCurrentFrame();
const { fps, width, height, durationInFrames } = useVideoConfig();
return (
<AbsoluteFill style={{ backgroundColor: '#000' }}>
{/* 顺序排列的内容 */}
<Sequence from={0} durationInFrames={60}>
<Scene1 />
</Sequence>
<Sequence from={60} durationInFrames={60}>
<Scene2 />
</Sequence>
</AbsoluteFill>
);
};
管道集成
自动生成流程
- Local Run Proof 验证运行
- 创建
RUN_CERTIFICATE.json,内容包含status: "PASS" - 钩子触发
post-run-certificate-video.mjs - 演示视频渲染到
demo/out/<slug>.mp4
手动渲染
# 基本用法
node scripts/render-demo-video.mjs --cwd ./my-app --slug my-app
# 带自定义高亮
node scripts/render-demo-video.mjs \
--cwd ./my-app \
--slug my-app \
--title "我的优秀应用" \
--highlights '["功能1", "功能2", "功能3"]'
属性模式
interface AppFactoryDemoProps {
title: string; // 应用名称
slug: string; // URL 安全标识符
verifiedUrl: string; // 通过健康检查的 localhost URL
timestamp: string; // ISO 8601 时间戳 (UTC)
highlights: string[]; // 4-6 个要点
certificateHash: string; // RUN_CERTIFICATE.json 的 SHA256
}
调试
# 在 Remotion Studio 中预览
cd demo-video && npm run studio
# 渲染特定组合
npx remotion render src/index.ts AppFactoryDemo output.mp4
# 检查 TypeScript 错误
npx tsc --noEmit
常见模式
淡入/淡出
const fadeIn = interpolate(frame, [0, 30], [0, 1], {
extrapolateRight: 'clamp',
});
const fadeOut = interpolate(frame, [duration - 30, duration], [1, 0], {
extrapolateLeft: 'clamp',
extrapolateRight: 'clamp',
});
const opacity = fadeIn * fadeOut;
交错动画
items.map((item, index) => {
const delay = index * 10; // 每个项之间间隔 10 帧
const itemOpacity = interpolate(
frame,
[delay, delay + 20],
[0, 1],
{ extrapolateLeft: 'clamp', extrapolateRight: 'clamp' }
);
return <Item key={index} style={{ opacity: itemOpacity }} />;
});
使用弹簧缩放
const scaleSpring = spring({
fps,
frame: frame - startFrame,
config: { damping: 80, stiffness: 200 },
});
const scale = interpolate(scaleSpring, [0, 1], [0.8, 1]);
错误代码
| 代码 | 含义 | 解决方法 |
|---|---|---|
| FAC-006 | 视频渲染失败 | 检查 Remotion 日志,确认 ffmpeg 已安装 |
| FAC-007 | 证书缺失 | 先运行 Local Run Proof |
| FAC-008 | 属性验证失败 | 检查属性类型与模式匹配 |