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. 使用夾值插值
// 務必使用外推夾值
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 | 屬性驗證失敗 | 檢查屬性型別是否符合結構 |