Communitygithub.com

Hownameee/short-videos

以特定方式編寫 Remotion 標記,使 Remotion Studio 能夠識別程式碼結構並實現互動性。

short-videos 是什麼?

此技能描述了如何以結構化方式撰寫 Remotion 標記,以充分利用 Remotion Studio 的互動式編輯功能。這允許開發者透過點擊選取、拖放、調整大小和旋轉來操作視覺元素,並能直接編輯 CSS 樣式、關鍵影格和緩動函數值。支援的平台包括 Remotion Studio,其核心機制是透過 Interactive 元件和 InteractivitySchema 定義可編輯的屬性。技能詳細說明了如何使用 `Interactive.withSchema({wrapInSequence: true})` 建立具有獨立時間軸的元件、如何為每個可獨立編輯的項目建立單獨的 JSX 節點、如何將 CSS 樣式內聯化、以及如何使用內聯的 `interpolate()` 呼叫進行動畫處理,以確保 Studio 能正確解析並提供圖形化編輯介面。它也強調了為互動式元件提供描述性名稱、優先使用內聯文字,以及將可複用元件註冊為已連接組合(connected compositions)的重要性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Hownameee/short-videos/tree/HEAD/.agent/skills/remotion-interactivity

在你喜歡的 AI 中提問

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

預覽

來自技能 README

short-videos preview

說明文件

透過以特定方式編寫 Remotion 標記,Remotion Studio 能夠識別程式碼的結構並使其具有互動性:

  • 允許透過點擊選取項目
  • 允許拖放、調整大小和旋轉
  • 編輯 CSS 樣式
  • 讓關鍵影格和緩動函數值可編輯

如果標記對於 Studio 來說過於複雜而無法使其互動,則這些值會變成灰色。

優先使用具有自身時間軸的互動式元件

對於自訂場景、卡片、標題以及其他其 props 應可逐個實例編輯的視覺元件,請使用 Interactive.withSchema({wrapInSequence: true})。在 InteractivitySchema 中公開有意義的內容和外觀控制項。將裝飾性的實作細節保留在元件內部。

該元件必須接受 style 並將其轉發到一個視覺根元素。當變換、裁切或不透明度應影響其所有圖層時,請保持一個共享的根元素。當冗餘的內部包裝器的樣式可以移動到現有元素上而不改變佈局或動畫時,請將其扁平化。

import type React from 'react';
import {Interactive, type InteractivitySchema} from 'remotion';

type LowerThirdProps = {
  readonly children: string;
  readonly accentColor: string;
  readonly style?: React.CSSProperties;
};

const LowerThirdInner: React.FC<LowerThirdProps> = ({
  children,
  accentColor,
  style,
}) => {
  return (
    <Interactive.Div
      style={{
        position: 'absolute',
        left: 80,
        bottom: 80,
        display: 'flex',
        alignItems: 'center',
        gap: 20,
        backgroundColor: 'white',
        borderRadius: 16,
        padding: '20px 32px',
        color: 'black',
        fontFamily: 'Helvetica, Arial, sans-serif',
        fontSize: 48,
        fontWeight: 600,
        ...style,
      }}
    >
      <div
        style={{
          width: 8,
          alignSelf: 'stretch',
          borderRadius: 4,
          backgroundColor: accentColor,
        }}
      />
      {children}
    </Interactive.Div>
  );
};

const lowerThirdSchema = {
  children: {type: 'text-content', default: '', description: 'Text'},
  accentColor: {
    type: 'color',
    default: '#0b84f3',
    description: 'Accent color',
  },
} as const satisfies InteractivitySchema;

export const LowerThird = Interactive.withSchema({
  Component: LowerThirdInner,
  componentName: '<LowerThird>',
  schema: lowerThirdSchema,
  wrapInSequence: true,
});

在元件內部轉發注入的style是必須的;在元件的呼叫位置將可編輯的樣式保持內聯。

選擇 Schema 欄位

Schema 中的每個鍵都是一個 prop,Studio 可以在呼叫位置讀取和編輯它。不在 Schema 中的 Props 仍然可以運作,但在 Studio 中無法編輯。鍵可以使用點記號,例如 style.color。

類型用途可關鍵影格化
text-content文字,例如標題否
number數字,可選 min、max、step、integer是
boolean開關是 (hold)
colorCSS 顏色字串是
enum在 variants 之間選擇,每個選項有自己的巢狀 schema選擇加入 (hold)
array數字、顏色、枚舉等的列表否
asset媒體來源,可選 assetType否
font-familyCSS 字型家族否
font-weight字型粗細是
translate, scale, rotation-css, rotation-degrees, transform-origin變換是
uv-coordinate元素上的一個標準化 [x, y] 點是
svg-pathSVG 路徑資料是
remotion-captionsCaption[] 資料否
hidden一個保持在控制項之外的值—

每個欄位都需要一個 default,並且應該有一個 description,Studio 會將其顯示為標籤。 設定 keyframable: false 來顯示一個靜態控制項。

公開內容和每個實例的外觀,例如文字和強調色。\n不要為 style.translate、style.scale、style.rotate、style.transformOrigin 和 style.opacity 添加欄位:wrapInSequence: true 已經添加了它們。

要使根元素的 CSS 屬性可逐個實例編輯,請展開內建的 schema 片段:

const cardSchema = {
  ...Interactive.textSchema, // style.color, style.fontSize, style.fontWeight, ...
  ...Interactive.backgroundSchema, // style.backgroundColor
  ...Interactive.borderRadiusSchema, // style.borderRadius, ...
} as const satisfies InteractivitySchema;

也可用:Interactive.borderSchema,以及用於接受字幕的元件的 Interactive.captionsSchema。\n請參閱 InteractivitySchema 以了解所有選項。

將可複用元件註冊為已連接組合

將具有自身圖層或動畫的重要場景和可複用元件註冊為獨立組合。Studio 將這些稱為已連接組合:它們可以在自己的時間軸中打開,同時與父影片共享相同的元件實作。

註冊父級渲染所使用的相同匯出元件參考。對於上面的範例,使用 component={LowerThird},而不是 LowerThirdInner 或內聯包裝器。 使用 wrapInSequence: true,則不需要額外的 <Sequence> 來進行連接。

import {Composition} from 'remotion';
import {LowerThird} from './LowerThird';

export const RemotionRoot = () => (
  <Composition
    id="LowerThird"
    component={LowerThird}
    width={1280}
    height={720}
    fps={30}
    durationInFrames={30}
    defaultProps={{
      children: 'Jane Doe, Product Designer',
      accentColor: '#0b84f3',
    }}
  />
);

選擇一個唯一的 ID、代表性的內聯預設值以及適合預覽元件的尺寸、fps 和持續時間。註冊預設值不會自動從父實例複製 props。請參閱已連接組合以了解註冊和提取的詳細資訊。

直接將時間設定放在元件上

避免在一個已經接受時間 props 的元件周圍放置單獨的 <Sequence>。使用 wrapInSequence: true 製作的內建互動式元件和自訂元件可以直接接收 name、from、durationInFrames、trimBefore、playbackRate 和 premountFor。

<LowerThird
  name="Lower third"
  from={30}
  durationInFrames={90}
  accentColor="#0b84f3"
>
  Jane Doe, Product Designer
</LowerThird>

移除冗餘的 Sequence 時,將其時間和名稱移動到子元件。保留任何現有的子元件時間;不要覆蓋或雙重應用偏移。在元件內部的 useCurrentFrame() 呼叫讀取其本地影格,而在呼叫位置的樣式表達式仍然使用呼叫者的影格。在移動動畫樣式時,保留這種區別。

當一個 <Sequence> 為多個兄弟元素提供共享時間、覆蓋 useVideoConfig() 的尺寸,或包裝一個不處理時間的元件時,請保留它。保留 <Series.Sequence> 用於連續佈局,保留 <TransitionSeries.Sequence> 用於轉場;直接的 from props 不會取代這些行為。

為每個可獨立編輯的項目提供其自己的 JSX 節點

Studio 編輯的是創建項目的 JSX 原始碼節點。如果多個執行時期項目來自同一個 JSX 節點,它們共享一個原始碼編輯目標。

對於每個應可獨立編輯的組合註冊、剪輯、場景、圖層或序列,請撰寫一個單獨的 JSX 節點,並將其可編輯的 props 保留在該節點上。這適用於 <Composition>、<Still>、內建媒體元件、<Sequence>、<Series.Sequence>、<TransitionSeries.Sequence> 和自訂元件。

例如,像這樣建立一個可編輯的時間軸:

<Series>
  <Series.Sequence name="Introduction" durationInFrames={90}>
    <Introduction />
  </Series.Sequence>
  <Series.Sequence name="Demo" durationInFrames={150}>
    <Demo />
  </Series.Sequence>
</Series>

一個 .map() 或其他程式化迴圈會從一個 JSX 原始碼節點創建多個執行時期項目。這適用於重複的輸出,這些輸出是作為一個模板有意控制的,例如視覺化長條圖或粒子。當實例在 Studio 中需要獨立的 ID 或名稱、props、元資料、時間、排序、刪除或複製時,這是不合適的。

使用 Interactive 讓 HTML 元素具有互動性

每個 HTML 和 SVG 元素(除了 <Img>,它已經有互動性)例如 <div>,都可以使用 Interactive 變成互動式:

<Interactive.Div
  name="Greeting card"
  style={{fontSize: 80, padding: 24}}
>
  Hello
</Interactive.Div>

這允許在 Studio 中設定樣式和關鍵影格。請明智使用,如果一個元件有許多元素,時間軸可能會變得雜亂。

優先使用內聯文字

如果文字是固定的且只使用一次,請直接將其寫在互動式元素內部,而不是將其提取到常數中。

// 👍 固定的副本保持可編輯
<Interactive.Div name="Title">
  Remotion Best Practices
</Interactive.Div>

僅在文字是動態或可複用時才使用 prop 或變數。

為互動式元素提供描述性名稱

為元素添加一個 name prop,使其易於識別。 避免使用計算出來的名稱,請對其進行硬編碼。

<>
  <Interactive.Div name="Hero title" style={{fontSize: 80}}>
    Launch day
  </Interactive.Div>
  <Img name="Avatar" src="https://remotion.media/image.jpeg" />
  <Video name="Background" src="https://remotion.media/video.mp4" />
  <Interactive.Div name="Title">
    Launch day
  </Interactive.Div>
</>

將所有 CSS 樣式保持內聯

最好的方法是直接將一個純物件傳遞給 style —— 不要引用常數,不要展開物件,不要使用數學運算。

<Interactive.Div
  style={{
    fontSize: 80,
    color: 'red',
  }}
>
  Hello World!
</Interactive.Div>
const baseStyle = useMemo(() => {
  return {
    fontSize: 12 // ❌ 不支援非內聯樣式
  }
}, []);

<Interactive.Div
  style={{
    ...baseStyle, // ❌ 不支援展開
    color: RED, // ❌ 不支援引用常數
    scale: frame * 10 // ❌ 不支援數學運算
  }}
>
  Hello World!
</Interactive.Div>

使用 interpolate() 進行動畫處理

將動畫編寫為直接內聯在變化的屬性上的 interpolate() 呼叫。 輸出範圍、緩動、外推和 output 屬性應使用硬編碼值。

輸入範圍可以另外使用直接從 useVideoConfig() 解構出來的 durationInFrames、fps、width 和 height。支援純標識符如 durationInFrames、與數字相乘如 2 * fps 或 fps * 2,以及減去一個數字如 durationInFrames - 1。

const {fps, durationInFrames} = useVideoConfig();

// 👍 內聯值可以被標準化和關鍵影格化
<Interactive.Div
  name="Product card"
  style={{
    color: 'white',
    fontSize: 80,
    scale: interpolate(frame, [0, fps], [0, 1], {
      easing: Easing.spring({damping: 200}),
      output: 'perceptual-scale',
      extrapolateLeft: 'clamp',
      extrapolateRight: 'clamp'
    }),
    rotate: interpolate(frame, [0, 1 * fps], ['0deg', '20deg'], {
      easing: Easing.spring({damping: 200}),
      extrapolateLeft: 'clamp',
      extrapolateRight: 'clamp'
    }),
    translate: interpolate(
      frame,
      [durationInFrames - 30, durationInFrames],
      ['0px 0px', '0px 120px'],
      {
        easing: Easing.spring({damping: 200}),
        output: 'perceptual-scale',
        extrapolateLeft: 'clamp',
        extrapolateRight: 'clamp'
      }
    ),
  }}
/>
const translateY = interpolate(frame, [0, 30], [0, 120]); // ❌ 數學運算應直接在標記中

<Interactive.Div
  name="Product card"
  style={{
    translate: translateY, // ❌ 僅支援內聯的 interpolate() 呼叫
    rotate: interpolate(frame, [start, start + 10], [0, Math.PI]), // ❌ 不能使用帶有任意變數的數學運算,不能使用常數
    scale: interpolate(anyVariable, [0, 30], [0, 1]) // ❌ 只能解釋 `frame` 變數。
  }}
/>

保持 SVG 路徑內聯

將 SVG 路徑資料直接作為字串文字放在 d prop 中。避免使用變數或從外部來源動態構建路徑,因為 Studio 無法編輯它們。

<Interactive.SvgPath
  d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80"
  style={{stroke: 'black', fill: 'none'}}
/>

使用適當的 Interactive 包裝器

對於不同的元素類型,使用對應的 Interactive 包裝器:

元素類型Interactive 包裝器
<div><Interactive.Div>
<span><Interactive.Span>
<img><Img>(已內建互動性)
<video><Video>(已內建互動性)
<svg><Interactive.Svg>
<path><Interactive.SvgPath>
<rect><Interactive.SvgRect>
<circle><Interactive.SvgCircle>
<ellipse><Interactive.SvgEllipse>
<line><Interactive.SvgLine>
<polyline><Interactive.SvgPolyline>
<polygon><Interactive.SvgPolygon>
<text><Interactive.SvgText>
<g><Interactive.SvgG>

結論

透過遵循這些指南,你可以確保你的 Remotion 元件在 Studio 中具有高度互動性,從而為編輯者提供直觀的圖形化體驗。專注於將可編輯的屬性暴露在頂層,保持樣式內聯,並為每個邏輯單元使用單獨的 JSX 節點。

Individual skills in this repo

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

Hownameee/short-videos

Generate, revise or troubleshoot local Kokoro narration, pronunciation and scene word timing. Reuse verified unchanged clips; inspect the Python environment before setup changes. Exclude research, visuals, music composition and publishing.

Hownameee/short-videos

Router for all Remotion skills

Hownameee/short-videos

Transcribing, displaying and animating captions

Hownameee/short-videos

Remotion Map animation knowledge

Hownameee/short-videos

Content, animation and effects best practices

Hownameee/short-videos

Upgrade Remotion, and related packages

Hownameee/short-videos

>- Run Phase 1 of the shared short-video workflow: turn a raw topic or prompt into a sourced research pack and 2–4 distinct video directions, each with a defensible tension hook, promise, payoff, beats, visual approach, duration range, and risks. Use whenever the user asks for video ideas, angles, research, facts, hooks, topic analysis, or choices before scriptwriting. Stop for the user's direction choice and do not silently continue into script or production.

Hownameee/short-videos

Produce an approved short video or correct an existing video's background sound, emotion, captions, mix or export. Generate only changed narration, render and review a current preview, run technical and editorial QC, then export. Exclude script-only and general audio-advice requests.

Hownameee/short-videos

>- Run Phase 2 of the shared short-video workflow: convert an explicitly selected direction and its research into a reviewable beat sheet, narration, flexible scene timing, on-screen text, visual plan, captions, music and SFX cues, pronunciation notes, payoff, takeaway, and contextual CTA. Use whenever a user asks to write, revise, preview, or approve a short-video script. Stop for script approval and do not generate TTS or render video yet.

Hownameee/short-videos

>- Design and review a coherent visual system for short-form video before and during Remotion implementation. Use for video art direction, scene UI, typography, layout, color, diagrams, captions, motion, transitions, platform safe areas, or visual-quality review. Use Remotion skills separately for API, timeline, media, Studio, and rendering behavior; do not use this skill for narration-only or research-only work.

Hownameee/short-videos

Coordinate prompt-to-short-video discovery, scripting and production. Resume existing projects and route soundtrack or mix corrections directly to production. Preserve direction choice and script approval; exclude general audio advice.

相關技能