這是 Remotion React 標記的撰寫指導。 如果此主題不相關,請改為載入 Remotion 最佳實務。
通用規則
使用 useCurrentFrame() 和 interpolate() 來處理屬性動畫。
優先使用 interpolate() 而非 spring()。
使用 Easing.bezier() 自訂時間曲線,包含跳躍或過衝的動態效果。
若需彈簧動畫,則使用 Easing.spring()。
在 Studio 中需要互動的 HTML 元素應使用 Interactive:<div> -> <Interactive.Div>。
為 Interactive、Solid、Sequence 設定描述性的 name 屬性,例如 name="Hero title"。
import { useCurrentFrame, Easing, interpolate, Interactive } from "remotion";
export const FadeIn = () => {
const frame = useCurrentFrame();
return (
<Interactive.Div
name="Title"
style={{
opacity: interpolate(frame, [0, 60], [0, 1], {
extrapolateRight: "clamp",
extrapolateLeft: "clamp",
easing: Easing.bezier(0.16, 1, 0.3, 1),
}),
}}
>
Hello World!
</Interactive.Div>
);
};
將 interpolate() 呼叫內聯在 style 屬性中。
優先使用 scale、translate、rotate 等 CSS 屬性,而非 transform。
// 👍 可內聯編輯的關鍵影格與變形簡寫
style={{
scale: interpolate(frame, [0, 100], [0, 1]),
translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
}}
// 👎 隱藏的值與 transform 字串在 Studio 中更難編輯
const scale = interpolate(frame, [0, 100], [0, 1]);
style={{
transform: `scale(${scale})`,
}}
禁止使用 CSS 轉場或動畫——它們無法正確渲染。 禁止使用 Tailwind 動畫類別名稱——它們無法正確渲染。
將素材放在專案根目錄的 public/ 資料夾中。
使用 staticFile() 來引用 public/ 資料夾中的檔案。
使用 @remotion/media 加入影片和音訊。
使用 <Img> 元件加入圖片。
使用 staticFile() 存取 public/ 中的檔案,或直接傳入遠端 URL:
import { Audio, Video } from "@remotion/media";
import { staticFile } from "remotion";
export const MyComposition = () => {
return (
<>
<Video src={staticFile("video.mp4")} style={{ opacity: 0.5 }} />
<Audio src={staticFile("audio.mp3")} />
<Img src={staticFile("logo.png")} style={{ width: 100, height: 100 }} />
<Video src="https://remotion.media/video.mp4" />
</>
);
};
若要延遲內容,請用 <Sequence> 包裝並使用 from。
若要限制元素的持續時間,請使用 <Sequence> 的 durationInFrames。
<Sequence> 預設為覆蓋整個場景的絕對填滿佈局。
若需內聯內容,請使用 layout="none"。
const Main = () => {
const {fps} = useVideoConfig();
return (
<AbsoluteFill>
<Sequence name="Background">
<Background />
</Sequence>
<Sequence name="Title" from={30} durationInFrames={60} layout="none">
<Title />
</Sequence>
<Sequence name="Subtitle" from={60} durationInFrames={60} layout="none">
<Subtitle />
</Sequence>
</AbsoluteFill>
);
}
export const Title = () => {
const frame = useCurrentFrame();
return (
<div
style={{
opacity: interpolate(frame, [0, 60], [0, 1], {
extrapolateRight: "clamp",
extrapolateLeft: "clamp",
easing: Easing.bezier(0.16, 1, 0.3, 1),
}),
}}
>
Title
</div>
);
};
export const Subtitle = () => {
return <div>Subtitle</div>;
};
地圖
關於選擇簡單靜態地圖、Mapbox 地圖與 MapLibre 地圖,請參閱 map.md。
語音旁白
關於使用 ElevenLabs TTS 為 Remotion 合成加入 AI 語音旁白,請參閱 voiceover.md。
修剪
關於修剪模式——裁剪動畫的開頭或結尾,請參閱 trimming.md。
嵌入影片
關於嵌入影片的進階知識——修剪、音量、速度、循環、音高,請參閱 embedding-videos.md。
嵌入音訊
關於進階音訊功能——修剪、音量、速度、音高,請參閱 audio.md。
轉場
關於場景轉場模式,請參閱 transitions.md。
視覺與像素效果
建立視覺效果時,優先順序:1. 一般 Remotion/HTML/CSS/SVG/濾鏡/混合/遮罩動畫;2. 透過 effects.md 列出的效果(包含在 <HtmlInCanvas> 中渲染的 HTML);3. 當使用者需要可重複使用或專案特定的效果時,透過 effects.md 使用自訂 createEffect();4. 僅在沒有任何效果適合時使用自訂 <HtmlInCanvas onPaint>(參考 html-in-canvas.md)。
關於漏光疊加,請參閱 light-leaks.md。文件:https://www.remotion.dev/docs/effects
可用效果:brightness(), contrast(), colorKey(), duotone(), grayscale(), hue(), invert(), saturation(), tint(), linearGradient(), linearGradientTint(), thermalVision(), blur(), linearProgressiveBlur(), radialProgressiveBlur(), zoomBlur(), dropShadow(), glow(), lightTrail(), evolve(), venetianBlinds(), mirror(), scale(), uvTranslate(), xyTranslate(), barrelDistortion(), chromaticAberration(), fisheye(), cornerPin(), wave(), burlap(), emboss(), dotGrid(), halftone(), noise(), noiseDisplacement(), paper(), roughenEdges(), pattern(), pixelate(), pixelDissolve(), scanlines(), speckle(), shine(), shrinkwrap(), vignette(), contourLines(), checkerboard(), halftoneLinearGradient(), gridlines(), whiteNoise(), tvSignalOff(), lines(), rings(), waves(), zigzag(), lightLeak(), starburst()。
3D 內容
關於使用 Three.js 和 React Three Fiber 在 Remotion 中處理 3D 內容,請參閱 3d.md。
音效
當需要使用音效時,請載入 ./sfx.md 檔案以取得更多資訊。
音訊視覺化
當需要將音訊視覺化(頻譜條、波形、低音反應效果)時,請載入 ./audio-visualization.md 檔案以取得更多資訊。
字幕
處理字幕時,請載入 Remotion 字幕 技能以取得更多資訊。
Google 字型
這是 Remotion 載入字型的建議方式。關於如何載入 Google 字型,請參閱 google-fonts.md。
本地字型
關於如何載入本地字型,請參閱 local-fonts.md。
GIF
關於如何顯示與 Remotion 時間軸同步的 GIF,請參閱 gifs.md。
進階圖片
關於調整圖片大小與位置、動態圖片路徑以及取得圖片尺寸,請參閱 images.md。
Lottie 動畫
關於在 Remotion 中嵌入 Lottie 動畫,請參閱 lottie.md。
進階時間控制
關於使用 interpolate 與貝茲曲線緩動以及彈簧的進階時間控制,請參閱 timing.md。
參數化影片
關於透過加入 Zod 模式使合成可參數化,請參閱 parameters.md。
測量 DOM 節點
關於在 Remotion 中測量 DOM 元素尺寸,請參閱 measuring-dom-nodes.md。
測量文字
關於測量文字尺寸、將文字置入容器以及檢查溢出,請參閱 measuring-text.md。
使用 FFmpeg
對於某些影片操作,例如修剪影片或偵測靜音,應使用 FFmpeg。請載入 ./ffmpeg.md 檔案以取得更多資訊。
靜音偵測
當需要偵測並修剪影片或音訊檔案中的靜音片段時,請載入 ./silence-detection.md 檔案。
動態持續時間、尺寸與資料
關於動態設定合成持續時間、尺寸與 props,請參閱 calculate-metadata.md。
進階合成
關於定義靜態圖片、資料夾、預設 props 以及巢狀合成,請參閱 compositions.md。
進階排序
關於更多排序模式——延遲、修剪、限制項目持續時間,請參閱 sequencing.md。
安裝模組
使用 npx remotion add 以正確版本加入新套件:
npx remotion add @remotion/media
此命令適用於 @remotion/* 套件、mediabunny、@mediabunny/* 以及 zod。
預覽標記
僅在使用者想要查看預覽時才執行此操作。
npx remotion studio --no-open
這會啟動一個長時間運行的程序,並輸出預覽伺服器的 URL。 如果伺服器已啟動,則會直接輸出 URL。
選擇性:單幀渲染檢查
你可以使用 CLI 渲染單個影格,以驗證佈局、顏色或時間。 對於簡單的修改、純重構或當你已從 Studio 或先前的渲染中獲得足夠信心時,可以跳過此步驟。
npx remotion still [composition-id] --scale=0.25 --frame=30
在 30 fps 下,--frame=30 表示第一秒的位置(--frame 從 0 開始計數)。