Remotion — 用 React 製作影片 是做什麼的?
來源: remotion-dev/remotion · 43.6k ⭐ · v4.x · 🟢 活躍維護中(2026) NPM:
remotion·@remotion/cli·@remotion/player·@remotion/lambda文件: https://www.remotion.dev/
1. 核心思維模型
- 影片 是由 React 元件序列逐幀渲染而成
- 你取得一個
frame編號(0 → N)和一塊空白畫布——其餘就是 CSS / SVG / Canvas / WebGL - Remotion 會將你的 React 編譯成一系列 PNG / JPEG 幀,再透過 FFmpeg 編碼為 MP4
2. 使用時機
- 程式化影片產製(解說影片、個人化廣告影片、數據驅動影片)
- 年度回顧 / 統計影片(如 GitHub Unwrapped、Spotify Wrapped)
- 由文案 + 資料建構的行銷解說(非在 AE / Premiere 中手動編輯)
- 開發者工具 / 教學影片,從程式碼自動產生
不適合的情況
- 真人實拍影片剪輯(請用 Premiere / Final Cut)
- 傳統動態圖形設計(After Effects 更有效)
- 一次性影片——花費成本不划算
3. 安裝(新專案)
npx create-video@latest my-video
cd my-video
npm install
npm start # 開啟 Remotion Studio
提供的範本
- Hello World
- TypeScript
- JavaScript
- React 18 / 19
- Audiogram
- Stargazer(GitHub 星數動畫)
- Three.js
- Empty
加入現有專案
npm install remotion @remotion/cli
建立 src/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' }}
/>
);
};
在 remotion.config.ts 中註冊根元件:
import { Config } from '@remotion/cli/config';
Config.setEntryPoint('./src/index.ts');
4. 核心概念
<Composition />
定義一部影片:渲染哪個元件、持續時間、fps、解析度、預設 props。
useCurrentFrame()
回傳當前幀編號(從 0 開始)。所有動畫都由此驅動:
import { useCurrentFrame, useVideoConfig, interpolate } from 'remotion';
export const MyVideo: React.FC<{ title: string }> = ({ title }) => {
const frame = useCurrentFrame();
const { fps, durationInFrames } = useVideoConfig();
const opacity = interpolate(frame, [0, 30], [0, 1], { extrapolateRight: 'clamp' });
return (
<div style={{ flex: 1, backgroundColor: '#0a0a0f', color: 'white', opacity, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<h1 style={{ fontSize: 120 }}>{title}</h1>
</div>
);
};
interpolate(frame, [from, to], [startVal, endVal], options)
將幀編號映射到任意數值(位置、透明度、縮放、顏色等)。
spring(...)
自然的運動曲線:
import { spring, useCurrentFrame, useVideoConfig } from 'remotion';
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
const scale = spring({
frame,
fps,
config: { damping: 100, stiffness: 200, mass: 0.5 },
});
<div style={{ transform: `scale(${scale})` }}>Content</div>
<Sequence from={f} durationInFrames={n}>
將一個元件的起始幀偏移到 f:
import { Sequence } from 'remotion';
<Sequence from={0} durationInFrames={60}><Intro /></Sequence>
<Sequence from={60} durationInFrames={120}><Scene1 /></Sequence>
<Sequence from={180} durationInFrames={90}><Outro /></Sequence>
<Audio src={...} />
import { Audio } from 'remotion';
import bgMusic from './music.mp3';
<Audio src={bgMusic} volume={0.5} />
<Img src={...} /> / <Video src={...} />
在時間軸中嵌入圖片 / 影片片段。
staticFile('...')
引用 public/ 中的檔案——Remotion 會處理路徑解析:
import { staticFile } from 'remotion';
<Img src={staticFile('logo.svg')} />
5. 渲染
本地渲染(CLI)
npx remotion render MyVideo out/video.mp4
npx remotion render MyVideo out/video.mp4 --props='{"title":"Hello"}'
npx remotion render MyVideo out/video.mp4 --quality=high --codec=h265
Remotion Studio(預覽 + 時間軸)
npm start # 開啟 http://localhost:3000
Remotion Player(嵌入你的 React 應用)
import { Player } from '@remotion/player';
import { MyVideo } from './MyVideo';
<Player
component={MyVideo}
durationInFrames={150}
fps={30}
compositionWidth={1920}
compositionHeight={1080}
inputProps={{ title: 'Hello' }}
controls
style={{ width: '100%' }}
/>
Remotion Lambda(雲端渲染)
用於批次 / 伺服器端渲染:
npm install @remotion/lambda
設定 AWS Lambda 函式,部署 Remotion:
npx remotion lambda functions deploy
npx remotion lambda sites create
npx remotion lambda render MyVideo --input-props='{"title":"User 123"}'
6. 範例——數據驅動影片
產生個人化的「年度回顧」影片:
import { Composition } from 'remotion';
import { YearInReview } from './YearInReview';
export const RemotionRoot = () => (
<Composition
id="Recap"
component={YearInReview}
durationInFrames={8 * 30} // 8 秒,30fps
fps={30}
width={1080}
height={1920} // 垂直(手機)
defaultProps={{
user: { name: 'Alice', stats: { commits: 1284, prs: 42, reviews: 89 } },
}}
/>
);
為每位使用者渲染:
for user in $(cat users.json); do
npx remotion lambda render Recap --input-props="$user"
done
7. 定價 / 授權
| 層級 | 適合對象 | 價格 |
|---|---|---|
| 個人 / 團隊 ≤ 3 人 | 個人、小型公司 | 免費(類似 MIT) |
| 公司 ≤ 10 名員工 | 小型新創 | 免費 |
| 較大公司 | > 10 名員工 | $100/月 + $25/席 |
| Editor Starter | 使用 Remotion 打造自己的影片編輯器 | $600 一次性 |
| Lambda | 雲端渲染 | 按每次渲染付費(每分鐘影片約幾美分) |
詳情請見 https://www.remotion.dev/docs/license 以取得授權條款。
8. 禁止事項
- ❌ 永遠不要用 Remotion 做即時影片播放引擎——它是為「渲染成檔案」設計的,不是直播串流
- ❌ 永遠不要把大於 100MB 的實際影片檔案放在 bundle 中——請用
staticFile()並將大型媒體另外託管 - ❌ 永遠不要在 Remotion 元件中使用
setTimeout、setInterval或requestAnimationFrame——確定性只能來自useCurrentFrame() - ❌ 永遠不要在渲染過程中擷取資料——請預先擷取並透過
inputProps傳入 - ❌ 永遠不要為每個元件渲染不必要的幀數——每一幀都耗費渲染時間
- ❌ 永遠不要在沒有授權(團隊 > 3 人)的情況下進行商業 Lambda 渲染
- ❌ 永遠不要直接使用
Math.random()——輸出將不具確定性。請使用 Remotion 的random()並帶入種子 - ❌ 永遠不要用 CSS 過渡效果(transition)製作動畫——Remotion 是逐幀渲染的;CSS 過渡效果無法生效。請用
interpolate()+ 幀
9. 出片前檢查清單
- [ ] remotion + @remotion/cli 已安裝
- [ ] src/Root.tsx 已用 <Composition /> 定義影片
- [ ] 所有動畫皆由 useCurrentFrame() 驅動——無 setTimeout/setInterval
- [ ] 隨機值使用 Remotion 的 random() 搭配種子(非 Math.random)
- [ ] 字型載入:使用 useFont 或 <link> 在 <head> 中
- [ ] 音訊檔案透過 <Audio> 並設定適當的音量 / 裁剪
- [ ] 正式產出:透過 Lambda 或 remotion render CLI 渲染
- [ ] 定價已確認——選擇適合團隊規模的層級
- [ ] 每個 Composition 的 inputProps 皆有型別定義(TypeScript)
- [ ] 在完整渲染前先測試渲染一段短預覽
10. 畫面風格調整
完全取決於影片的設計——Remotion 是一個框架,而非視覺函式庫。
11. 與 DesignDNA 整合
Remotion 可與 DesignDNA 的品牌 DNA 完美搭配:使用品牌的 DESIGN.md 權杖(顏色、字型、間距)作為所產生影片的視覺語言。範例:
import { tokens } from '../design-md/stripe/tokens';
<div style={{ color: tokens.colors['stripe-purple'], fontFamily: tokens.typography.families[0] }}>
Stripe 品牌風格開場
</div>
你的「年度回顧」影片就能與品牌視覺識別保持一致。
12. 替代方案
| 情境 | 替代方案 |
|---|---|
| 傳統非程式碼影片 | Adobe After Effects / Premiere |
| 資料視覺化影片 | D3 + 螢幕錄製 或 Remotion + D3 |
| 動畫 React 元件(非完整影片) | Framer Motion · Motion · React Bits(請見相關技能) |
| 互動式網頁動畫 | Lottie · GSAP |