編碼與格式
了解 Remotion 支援的影片編碼器和輸出格式。
支援的編碼器
Remotion 透過 FFmpeg 支援多種影片編碼器:
| 編碼器 | 格式 | 說明 | 建議使用場景 |
|---|---|---|---|
h264 | MP4 | 最通用的編碼器 | 社群媒體、一般用途 |
h265 | MP4 | 更好的壓縮,較小檔案 | 需要小檔案時 |
vp8 | WebM | 開放格式 | 網頁嵌入 |
vp9 | WebM | VP8 的改進版 | 網頁嵌入(更好品質) |
prores | MOV | Apple ProRes | 專業後製 |
指定編碼器
CLI
npx remotion render MyComp out/video.mp4 --codec=h264Node.js API
import { renderMedia } from "@remotion/renderer";
await renderMedia({
composition,
serveUrl: bundled,
codec: "h264",
outputLocation: "out/video.mp4",
});品質控制
CRF(Constant Rate Factor)
CRF 控制壓縮品質。數值越低 = 品質越好 = 檔案越大:
# H.264: CRF 範圍 1-51,預設 18
npx remotion render MyComp out/video.mp4 --crf=15
# VP9: CRF 範圍 0-63,預設 28
npx remotion render MyComp out/video.webm --codec=vp9 --crf=20| CRF | 品質 | 檔案大小 |
|---|---|---|
| 1-15 | 近乎無損 | 非常大 |
| 16-23 | 高品質 | 適中 |
| 24-35 | 一般品質 | 較小 |
| 36+ | 低品質 | 很小 |
位元率
也可以直接指定位元率:
npx remotion render MyComp out/video.mp4 --video-bitrate=8M渲染靜態圖片
# 渲染單幀為 PNG
npx remotion still MyComp out/thumb.png --frame=45
# 渲染為 JPEG
npx remotion still MyComp out/thumb.jpeg --frame=45 --image-format=jpeg渲染 GIF
npx remotion render MyComp out/animation.gifGIF 適合短動畫(建議 5 秒以內),檔案會比較大。
透明影片
需要透明背景時,使用 ProRes 或 VP9:
# ProRes 4444(含 alpha 通道)
npx remotion render MyComp out/video.mov --codec=prores --prores-profile=4444
# VP9(含 alpha 通道)
npx remotion render MyComp out/video.webm --codec=vp9確保你的 Composition 背景是透明的(不要設定 backgroundColor)。
選擇建議
| 場景 | 建議編碼器 | 格式 |
|---|---|---|
| 社群媒體發布 | H.264 | MP4 |
| 網頁嵌入 | VP9 | WebM |
| 專業後製 | ProRes | MOV |
| 短動畫 / 迷因 | — | GIF |
| 需要透明背景 | ProRes 4444 或 VP9 | MOV / WebM |
小結
- H.264 MP4 是最通用的選擇
- CRF 值控制品質與檔案大小的平衡
- 用
remotion still渲染靜態圖片 - 透明影片用 ProRes 4444 或 VP9