Communitygithub.com

IGNOVA-SYSTEMS-INTEGRATION/KONTRX

使用 Remotion (React/TypeScript 影片程式庫) 創作影片的最佳實踐與領域知識。適合在撰寫或編輯 Remotion 程式碼時查閱。

KONTRX 是什麼?

這項技能提供使用 Remotion 框架以程式化方式建立影片所需的完整領域知識與最佳實踐。Remotion 允許開發者使用 React 和 TypeScript 撰寫影片,並將其渲染為 MP4 檔案。該技能涵蓋了專案搭建、動畫製作(如使用 `useCurrentFrame()`、`interpolate()` 和 `spring()`)、場景排序與過場、字幕處理、音訊與影片資產管理、以及 GIF、Lottie 動畫和 3D 內容的整合。它支援在 Claude Code、Cursor、Codex 等 AI 代理程式中使用,透過查閱此技能檔案,開發者可以確保他們使用正確且最新的 Remotion API,例如 `@remotion/media` 元件,並遵循官方推薦的模式,從而避免常見錯誤並提升開發效率。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/IGNOVA-SYSTEMS-INTEGRATION/KONTRX/tree/HEAD/AGENT/skills/remotion

在你喜歡的 AI 中提問

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

預覽

來自技能 README

說明文件

使用時機

每當處理 Remotion 程式碼時,請使用這項技能來獲取領域特定知識。

新專案設定

當位於空資料夾或沒有任何現有 Remotion 專案的工作區時,請使用以下指令建立一個新專案:

npx create-video@latest --yes --blank --no-tailwind my-video

將 my-video 替換為合適的專案名稱。

設計影片

在設計視覺場景、佈局、宣傳片、動態圖形或文字密集型影片之前,請先載入 rules/video-layout.md 以取得影片優先佈局和文字大小的指引。

使用 useCurrentFrame() 和 interpolate() 來動畫化屬性。除非明確需要基於物理的運動,否則請優先使用 interpolate() 而非 spring()。使用 Easing.bezier() 自訂時間曲線,包括彈跳或過衝的運動效果。

對於需要在 Remotion Studio 中編輯的動畫,請將 interpolate() 呼叫內聯在 style prop 中,並使用個別的 CSS transform 屬性 (scale, translate, rotate),而不是組合 transform 字串。

import { useCurrentFrame, Easing, interpolate, useVideoConfig } from "remotion";

export const FadeIn = () => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();

  const opacity = interpolate(frame, [0, 2 * fps], [0, 1], {
    extrapolateRight: "clamp",
    extrapolateLeft: "clamp",
    easing: Easing.bezier(0.16, 1, 0.3, 1),
  });

  return <div style={{ opacity }}>Hello World!</div>;
};

偏好使用:

style={{
  scale: interpolate(frame, [0, 100], [0, 1]),
  translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
  rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
}}

勝過:

const scale = interpolate(frame, [0, 100], [0, 1]);

style={{
  transform: `scale(${scale})`,
}}

禁止使用 CSS transitions 或 animations — 它們無法正確渲染。 禁止使用 Tailwind 動畫類別名稱 — 它們無法正確渲染。

將資源放置在專案根目錄的 public/ 資料夾中。

使用 staticFile() 來引用 public/ 資料夾中的檔案。

使用 <Img> 元件新增圖片:

import { Img, staticFile } from "remotion";

export const MyComposition = () => {
  return <Img src={staticFile("logo.png")} style={{ width: 100, height: 100 }} />;
};

使用 @remotion/media 的 <Video> 元件新增影片:

import { Video } from "@remotion/media";
import { staticFile } from "remotion";

export const MyComposition = () => {
  return <Video src={staticFile("video.mp4")} style={{ opacity: 0.5 }} />;
};

使用 @remotion/media 的 <Audio> 元件新增音訊:

import { Audio } from "@remotion/media";
import { staticFile } from "remotion";

export const MyComposition = () => {
  return <Audio src={staticFile("audio.mp3")} />;
};

資源也可以作為遠端 URL 引用:

import { Video } from "@remotion/media";

export const MyComposition = () => {
  return <Video src="https://remotion.media/video.mp4" />
};

若要延遲內容,請將其包裹在 <Sequence> 中並使用 from。 若要限制元素的持續時間,請使用 <Sequence> 的 durationInFrames。 <Sequence> 預設為絕對填滿。對於內聯內容,請使用 layout="none"。

import { Sequence } from "remotion";

export const Title = () => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();

  const opacity = interpolate(frame, [0, 2 * fps], [0, 1], {
    extrapolateRight: "clamp",
    extrapolateLeft: "clamp",
    easing: Easing.bezier(0.16, 1, 0.3, 1),
  });

  return <div style={{ opacity }}>Title</div>;
};

export const Subtitle = () => {
  return <div>Subtitle</div>;
};

const Main = () => {
  const {fps} = useVideoConfig();

  return (
    <AbsoluteFill>
      <Sequence>
        <Background />
      </Sequence>
      <Sequence from={1 * fps} durationInFrames={2 * fps} layout="none">
        <Title />
      </Sequence>
      <Sequence from={2 * fps} durationInFrames={2 * fps} layout="none">
        <Subtitle />
      </Sequence>
    </AbsoluteFill>
  );
}

影片的寬度、高度、fps 和持續時間在 src/Root.tsx 中定義:

import { Composition } from "remotion";
import { MyComposition } from "./MyComposition";

export const RemotionRoot = () => {
  return (
    <Composition
      id="MyComposition"
      component={MyComposition}
      durationInFrames={100}
      fps={30}
      width={1080}
      height={1080}
    />
  );
};

元資料也可以動態計算:

import { Composition, CalculateMetadataFunction } from "remotion";
import { MyComposition, MyCompositionProps } from "./MyComposition";

const calculateMetadata: CalculateMetadataFunction<
  MyCompositionProps
> = async ({ props, abortSignal }) => {
  const data = await fetch(`https://api.example.com/video/${props.videoId}`, {
    signal: abortSignal,
  }).then((res) => res.json());

  return {
    durationInFrames: Math.ceil(data.duration * 30),
    props: {
      ...props,
      videoUrl: data.url,
    },
    width: 1080,
    height: 1080,
  };
};

export const RemotionRoot = () => {
  return (
    <Composition
      id="MyComposition"
      component={MyComposition}
      fps={30}
      width={1080}
      height={1080}
      defaultProps={{ videoId: "abc123" }}
      calculateMetadata={calculateMetadata}
    />
  );
};

啟動預覽

啟動 Remotion Studio 預覽影片:

npx remotion studio

可選:單影格渲染檢查

您可以使用 CLI 渲染單個影格,以快速驗證佈局、顏色或時間點。 對於微小的編輯、純重構,或當您已從 Studio 或之前的渲染中獲得足夠信心時,可以跳過此步驟。

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

在 30 fps 時,--frame=30 是 1 秒標記(--frame 從 0 開始)。

字幕

當處理字幕時,請載入 ./rules/subtitles.md 檔案以取得更多資訊。

使用 FFmpeg

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

靜音偵測

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

音訊視覺化

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

音效

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

視覺與像素效果

建立視覺效果時,偏好順序:1. 一般的 Remotion/HTML/CSS/SVG/濾鏡/混合/遮罩動畫,2. 透過 rules/effects.md 列出效果(包括透過 <HtmlInCanvas> 渲染的 HTML),3. 當使用者要求可重用/專案特定效果時,透過 rules/effects.md 使用自訂 createEffect(),4. 僅在沒有合適效果時,才使用自訂的 <HtmlInCanvas onPaint>(參見 rules/html-in-canvas.md)。

如需光暈疊加,請參閱 rules/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(), pattern(), pixelate(), pixelDissolve(), scanlines(), speckle(), shine(), shrinkwrap(), vignette(), contourLines(), checkerboard(), halftoneLinearGradient(), gridlines(), whiteNoise(), tvSignalOff(), lines(), rings(), waves(), zigzag(), lightLeak(), starburst()。

3D 內容

參閱 rules/3d.md 了解如何在 Remotion 中使用 Three.js 和 React Three Fiber 建立 3D 內容。

進階音訊

參閱 rules/audio.md 了解進階音訊功能,如修剪、音量、速度、音高。

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

參閱 rules/calculate-metadata.md 了解如何動態設定合成的持續時間、尺寸和 props。

進階合成

參閱 rules/compositions.md 了解如何定義靜止畫面、資料夾、預設 props 以及如何巢狀合成。

Google Fonts

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

本地字型

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

取得音訊長度

參閱 rules/get-audio-duration.md 了解如何使用 Mediabunny 以秒為單位取得音訊檔案的長度。

取得影片尺寸

參閱 rules/get-video-dimensions.md 了解如何使用 Mediabunny 取得影片檔案的寬度和高度。

取得影片長度

參閱 rules/get-video-duration.md 了解如何使用 Mediabunny 以秒為單位取得影片檔案的長度。

GIF

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

進階圖片

參閱 rules/images.md 了解如何調整圖片大小和定位、動態圖片路徑以及取得圖片尺寸。

Lottie 動畫

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

測量 DOM 節點

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

測量文字

參閱 rules/measuring-text.md 了解如何測量文字尺寸、將文字適配到容器以及檢查溢位。

進階排序

參閱 rules/sequencing.md 了解更多排序模式 - 延遲、修剪、限制項目持續時間。

TailwindCSS

參閱 rules/tailwind.md 了解如何在 Remotion 中使用 TailwindCSS。

文字動畫

參閱 rules/text-animations.md 了解排版和文字動畫模式。

進階時間控制

參閱 rules/timing.md 了解使用 interpolate 和貝塞爾曲線緩動以及彈簧的進階時間控制。

轉場

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

透明影片

參閱 rules/transparent-videos.md 了解如何渲染帶有透明度的影片。

修剪

參閱 rules/trimming.md 了解修剪模式 - 剪掉動畫的開頭或結尾。

進階影片

參閱 rules/videos.md 了解關於嵌入影片的進階知識 - 修剪、音量、速度、循環、音高。

參數化影片

參閱 rules/parameters.md 了解如何透過新增 Zod schema 使合成可參數化。

地圖

對於簡單且包含少量飛越效果的地圖,可以考慮使用靜態地圖圖片。 對於具有動畫路線或飛越效果的複雜地圖,請載入地圖規則:rules/maplibre.md

配音

參閱 rules/voiceover.md 了解如何使用 ElevenLabs TTS 為 Remotion 合成加入 AI 生成的配音。

相關技能