Communitygithub.com

Remotion — 使用 React 進行程式化影片創作

使用 React 元件以程式化方式建立影片。這是最成熟的程式驅動影片製作框架。

Remotion — 使用 React 進行程式化影片創作 是什麼?

Remotion 是一個基於 React 和 TypeScript 的開源框架,讓開發者能透過撰寫程式碼來產生影片。它支援動畫、轉場效果、音訊與影片嵌入,並可輸出為 MP4 或 GIF 格式。該框架提供 Composition、Sequence、Series 等核心概念,以及 useCurrentFrame、interpolate、spring 等動畫基礎函式,讓開發者能夠精確控制影格層級的動畫。Remotion 適合用於自動化影片生成、動態廣告、資料視覺化等場景。支援平台包括 macOS、Windows 和 Linux,並可整合 CI/CD 流程。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ever-just/agentskills/tree/HEAD/skills/remotion

在你喜歡的 AI 中提問

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

說明文件

Remotion — 使用 React 進行程式化影片創作 是做什麼的?

使用 React 元件以程式化方式建立影片。這是最成熟的程式驅動影片製作框架。

概覽

  • 儲存庫: github.com/remotion-dev/remotion (21K+ 星)
  • 語言: TypeScript / React
  • 授權: 個人及營收低於 100 萬美元的公司免費
  • 安裝: npm install remotion @remotion/cli @remotion/transitions
  • 文件: remotion.dev/docs

核心概念

Composition

<Composition> 定義影片的尺寸、影格率和持續時間:

import { Composition } from "remotion";

export const RemotionRoot: React.FC = () => {
  return (
    <Composition
      id="MyVideo"
      component={MyVideo}
      durationInFrames={300}  // 在 30fps 下為 10 秒
      fps={30}
      width={1920}
      height={1080}
    />
  );
};

動畫基礎函式

useCurrentFrame() — 回傳目前影格編號(從 0 開始):

const frame = useCurrentFrame();

interpolate() — 將影格範圍對應到輸出值:

import { interpolate, useCurrentFrame } from "remotion";

const opacity = interpolate(frame, [0, 30], [0, 1], {
  extrapolateRight: "clamp",
});

spring() — 基於物理的彈簧動畫:

import { spring, useCurrentFrame, useVideoConfig } from "remotion";

const { fps } = useVideoConfig();
const scale = spring({ frame, fps, config: { damping: 200 } });

排序

— 將內容在時間上偏移:

<Sequence from={30} durationInFrames={60}>
  <MyScene />
</Sequence>

— 將子元素依序排列:

import { Series } from "remotion";

<Series>
  <Series.Sequence durationInFrames={90}>
    <IntroScene />
  </Series.Sequence>
  <Series.Sequence durationInFrames={150}>
    <MainScene />
  </Series.Sequence>
  <Series.Sequence durationInFrames={60}>
    <OutroScene />
  </Series.Sequence>
</Series>

— 全影格定位容器:

<AbsoluteFill style={{ backgroundColor: "#0a0a0a" }}>
  <h1>Hello World</h1>
</AbsoluteFill>

轉場效果

import { linearTiming, TransitionSeries } from "@remotion/transitions";
import { fade } from "@remotion/transitions/fade";
import { slide } from "@remotion/transitions/slide";

<TransitionSeries>
  <TransitionSeries.Sequence durationInFrames={90}>
    <Scene1 />
  </TransitionSeries.Sequence>
  <TransitionSeries.Transition
    presentation={fade()}
    timing={linearTiming({ durationInFrames: 15 })}
  />
  <TransitionSeries.Sequence durationInFrames={90}>
    <Scene2 />
  </TransitionSeries.Sequence>
</TransitionSeries>

可用的轉場效果:fade、slide、wipe、flip、clockWipe、none

媒體

import { Video, Audio, Img, staticFile } from "remotion";

// 靜態檔案放在 /public 目錄
<Video src={staticFile("demo.mp4")} />
<Audio src={staticFile("music.mp3")} volume={0.5} />
<Img src={staticFile("logo.png")} />

專案設定

# 建立新專案
npx create-video@latest my-video

# 或手動建立:
mkdir my-video && cd my-video
npm init -y
npm install remotion @remotion/cli @remotion/transitions react react-dom
npm install -D typescript @types/react

必要檔案

src/index.ts(進入點):

import { registerRoot } from "remotion";
import { RemotionRoot } from "./Root";
registerRoot(RemotionRoot);

remotion.config.ts:

import { Config } from "@remotion/cli/config";
Config.setVideoImageFormat("jpeg");
Config.setOverwriteOutput(true);

指令

# 在瀏覽器中預覽(Remotion Studio)
npx remotion studio

# 渲染為 MP4
npx remotion render MyVideo out/video.mp4

# 渲染特定影格
npx remotion render MyVideo out/video.mp4 --frames=0-90

# 渲染為 GIF
npx remotion render MyVideo out/video.gif --image-format=png

# 渲染靜止影像
npx remotion still MyVideo out/thumbnail.png --frame=45

最佳實踐

  1. 總是限制插值範圍:使用 extrapolateRight: "clamp" 防止數值超出範圍
  2. 使用 spring() 實現自然運動:彈簧動畫比線性插值更自然
  3. 將場景拆分為獨立元件:每個場景應為獨立的 React 元件
  4. 使用 處理連續場景:比手動計算偏移更簡單
  5. 設定明確的持續時間:每個 Sequence 都應有 durationInFrames
  6. 使用 AbsoluteFill:用於全影格背景和重疊圖層
  7. 靜態資源放在 /public:使用 staticFile() 引用它們
  8. 在不同影格測試:使用 Remotion Studio 的影格滑桿驗證動畫
  9. 優先使用 CSS 變換:transform: scale() 和 translateX() 由 GPU 加速
  10. 避免大量重新渲染:使用 useMemo 記憶化耗時的計算

常見模式

淡入文字:

const frame = useCurrentFrame();
const opacity = interpolate(frame, [0, 20], [0, 1], { extrapolateRight: "clamp" });
const y = interpolate(frame, [0, 20], [20, 0], { extrapolateRight: "clamp" });

<div style={{ opacity, transform: `translateY(${y}px)` }}>
  Hello World
</div>

列表項目交錯出現:

{items.map((item, i) => {
  const delay = i * 8;
  const opacity = interpolate(frame, [delay, delay + 15], [0, 1], {
    extrapolateLeft: "clamp",
    extrapolateRight: "clamp",
  });
  return <div key={i} style={{ opacity }}>{item}</div>;
})}

打字機效果:

const charsShown = interpolate(frame, [0, text.length * 2], [0, text.length], {
  extrapolateRight: "clamp",
});
<span>{text.slice(0, Math.floor(charsShown))}</span>

擴充套件(皆為開源,透過 npm install 安裝)

  • @remotion/transitions — 場景轉場效果(fade、slide、wipe)
  • @remotion/three — 在影片中使用 React Three Fiber 3D 場景
  • @remotion/lottie — 嵌入 Lottie 動畫
  • @remotion/gif — 嵌入 GIF 檔案
  • @remotion/media-utils — 音訊/影片中繼資料工具
  • @remotion/noise — 用於自然效果的 Perlin 雜訊
  • @remotion/paths — SVG 路徑動畫工具

上游技能來源

  • 官方技能:github.com/remotion-dev/skills
  • 模板:github.com/reactvideoeditor/remotion-templates
  • Superpowers 流程:github.com/dojocodinglabs/remotion-superpowers

Individual skills in this repo

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

ever-just/agentskills

> Declarative animations for React. Springs, gestures, layout animations, and page transitions. GPU-accelerated, production-ready.

ever-just/agentskills

> Create animated logos, icons, and micro-interactions as lightweight Lottie JSON files. No After Effects needed — build animations entirely in code.

ever-just/agentskills

> A TypeScript library using generators to program animations with a real-time editor. Ideal for explainer videos, code walkthroughs, and educational content.

ever-just/agentskills

> Add animated subtitles and captions to Remotion videos from .SRT files. TikTok-style word-by-word highlights, karaoke effects, and more.

ever-just/agentskills

> Copy-paste video components for Remotion. Intros, text effects, transitions, and full scene templates. Like shadcn/ui but for video.

ever-just/agentskills

Extract actionable intelligence from video content across YouTube, Vimeo, and company websites. Video reveals what text sources cannot: facility scale, team composition, product demonstrations, signage, event attendance, and operational reality.

ever-just/agentskills

Optimize and embed an existing video as a fast, crisp, autoplaying hero/background/loop on a website. Use when adding or replacing a video on a marketing site and it is too heavy, will not autoplay (especially on mobile/Safari), shows a codec error, or looks soft — to transcode it to web-safe H.264 with the right pixel format, faststart, retina-aware sizing, and a poster frame, then embed and verify it actually plays. This is optimization + embedding of footage you already have, not creating/animating a video (for that use remotion/moviepy/motion-canvas). Use when the user says "add this video to the site", "the hero video is too big / won't play / isn't crisp", "replace the homepage video", or "make this loop on the landing page".

ever-just/agentskills

Full conversion audit for any homepage or landing page. Use when someone asks to "review my homepage," "audit my landing page," "why isn't my page converting," "check my website," or wants feedback on their marketing page. Requires URL or screenshot before proceeding.

ever-just/agentskills

Automatically fetch YouTube video transcripts, generate structured summaries, and send full transcripts to messaging platforms. Detects YouTube URLs and provides metadata, key insights, and downloadable transcripts.

相關技能