Community程式設計與開發github.com

remotion-markup

撰寫 Remotion React Markup 的最佳實踐

remotion-markup 是什麼?

這份技能提供撰寫 Remotion React Markup 的完整指南。它涵蓋了動畫屬性(使用 `useCurrentFrame()` 與 `interpolate()`)、在 Studio 中透過 `Interactive` 元件實現互動性、使用 `translate`、`scale` 與 `rotate` 等漸進式 CSS 屬性,以及經由 `staticFile()` 與 `@remotion/media` 來管理素材。其目的在於確保動畫能順利渲染、維持可編輯性,並符合 Remotion 的內部機制。此技能支援 Remotion Studio 與 CLI 環境,適用於 React 元件與 `<Sequence>` 組合的場景。此外,它也引導使用者參考其他專門文件,涵蓋地圖、文字高亮、語音旁白、影片編輯、轉場、視覺特效、3D 內容、音訊處理、字幕、字型、GIF、Lottie 動畫、進階時間控制、參數化影片、DOM 節點測量、FFmpeg 操作、靜音偵測、動態屬性、組合嵌套、序列化模式與模組安裝等主題。這些範例與規則能協助開發者運用 Remotion 的核心 API 與其生態中的附加套件,建立可靠且可調整的影片生成流程。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/remotion-dev/skills/tree/main/skills/remotion-best-practices/remotion-markup

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

預覽

來自技能 README

說明文件

這是撰寫 Remotion React Markup 的指引。 如果此主題不相關,請改載入 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> 元件來加入圖片。
對 public/ 中的檔案使用 staticFile(),或直接傳遞遠端 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>;
};

地圖

請參閱 map.md 以選擇簡單靜態地圖、Mapbox 地圖與 MapLibre 地圖。

文字高亮與註解

請參閱 text-highlights.md 了解文字高亮(螢光標記)、圓圈、底線、刪除線、劃掉文字、方框與括號。

語音旁白

請參閱 voiceover.md 了解如何使用 ElevenLabs TTS 為 Remotion 組合加入 AI 生成的語音旁白。

裁剪

請參閱 trimming.md 了解裁剪模式——切割動畫的開頭或結尾。

嵌入影片

請參閱 embedding-videos.md 取得關於嵌入影片的先進知識——裁剪、音量、速度、循環、音調。

影片編輯

請參閱 video-editing.md 了解如何在 Remotion Studio 中結構化可編輯的影片時間軸。

嵌入音訊

請參閱 audio.md 了解進階音訊功能,例如裁剪、音量、速度、音調。

轉場

請參閱 transitions.md 了解場景轉場模式。

視覺與像素特效

在建立視覺特效時,優先採用:1. 一般的 Remotion / HTML / CSS / SVG / filter / blend / mask 動畫,2. 透過 effects.md 列出的特效(包含透過 <HtmlInCanvas> 渲染的 HTML),3. 當使用者要求可重用或專案專屬的特效時,透過 effects.md 使用自訂的 createEffect(),4. 只有在沒有適合的特效時,才透過 html-in-canvas.md 使用自訂的 <HtmlInCanvas onPaint>。

關於漏光疊層,請參閱 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 內容

請參閱 3d.md 了解如何在 Remotion 中使用 Three.js 與 React Three Fiber 處理 3D 內容。

音效

當需要使用音效時,請載入 ./sfx.md 檔案以取得更多資訊。

音訊視覺化

當需要將音訊視覺化(頻譜條、波形、低音反應特效)時,請載入 ./audio-visualization.md 檔案以取得更多資訊。

字幕

在處理字幕或說明文字時,請載入 Remotion Captions 技能以取得更多資訊。

Google Fonts

是在 Remotion 中載入字型推薦的方式。請參閱 google-fonts.md 了解如何載入 Google Fonts。

本地字型

請參閱 local-fonts.md 了解如何載入本地字型。

GIF

請參閱 gifs.md 了解如何顯示與 Remotion 時間軸同步的 GIF。

進階圖片

請參閱 images.md 了解圖片的尺寸與定位、動態圖片路徑以及取得圖片尺寸。

Lottie 動畫

請參閱 lottie.md 了解如何在 Remotion 中嵌入 Lottie 動畫。

進階時間控制

請參閱 timing.md 了解進階時間控制,包含使用 interpolate 與 Bézier 緩動,以及彈簧。

參數化影片

請參閱 parameters.md 了解如何透過加入 Zod schema 讓組合可參數化。

測量 DOM 節點

請參閱 measuring-dom-nodes.md 了解如何在 Remotion 中測量 DOM 元素的尺寸。

測量文字

請參閱 measuring-text.md 了解測量文字尺寸、將文字適配到容器以及檢查溢出的方法。

使用 FFmpeg

對於某些影片操作,例如裁剪影片或偵測靜音,應使用 FFmpeg。請載入 ./ffmpeg.md 檔案以取得更多資訊。

靜音偵測

當需要偵測並裁剪影片或音訊檔案中的靜音片段時,請載入 ./silence-detection.md 檔案。

動態持續時間、尺寸與資料

請參閱 calculate-metadata.md 了解如何動態設定組合的持續時間、尺寸與屬性。

進階組合

請參閱 compositions.md 了解如何定義靜止畫面、資料夾、預設屬以及如何巢狀組合。

進階序列化

請參閱 sequencing.md 了解更多序列化模式——延遲、裁剪、限制項目的持續時間。

安裝模組

使用 npx remotion add 以正確的版本加入新套件:

npx remotion add @remotion/media

這適用於 @remotion/* 套件、mediabunny、@mediabunny/* 以及 zod。

預覽 Markup

僅在使用者想要看到預覽時才這麼做。

npx remotion studio --no-open

這會啟動一個長時間運行的程序,並輸出預覽的伺服器 URL。
如果已經啟動,則會輸出該 URL。

可選:單幀渲染檢查

你可以使用 CLI 渲染單一影格來檢查佈局、顏色或時間點。
對於簡單的編輯、純重構,或當你已經從 Studio 或先前的渲染中獲得足夠信心時,可以跳過此步驟。

npx remotion still [composition-id] --scale=0.25 --frame=30

在 30 fps 下,--frame=30 代表第 1 秒的位置(--frame 從 0 開始計算)。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

mediabunny

Multimedia handling with the Mediabunny library

remotion-best-practices

Router for all Remotion skills

remotion-captions

Transcribing, displaying and animating captions

remotion-captions

Dealing with captions in Remotion

remotion-create

Creating a new Remotion video

remotion-create

Create a new Remotion video

remotion-docs

Search Remotion documentation

remotion-docs

Search and fetch Remotion documentation pages

remotion-elements

Installs Elements, reusable video components such as titles, backgrounds, charts and caption styles, into a Remotion project with `npx remotion elements use`. Registers Element libraries in Remotion Studio with `npx remotion elements add-library`. Use when given an Element page URL or an Element library URL, or when a video needs a ready-made component.

remotion-interactivity

Best practices for writing Remotion animations that stay intuitive for agents and editable in Remotion Studio Visual Mode.

remotion-interactivity

Structure Remotion markup for interactivity

remotion-license

Find Remotion license information, FAQs, terms, and where to buy a license.

remotion-maps

Remotion Map animation knowledge

remotion-markup

Content, animation and effects best practices

remotion-multimedia

Interacting with Mediabunny

remotion-render

Best practices for rendering videos

remotion-saas

Building video apps with Remotion - framework, rendering and Player advice

remotion-saas

Build an app with Remotion

remotion-studio

Preview a Remotion video

remotion-upgrade

Upgrade Remotion, and related packages

相關技能