Communitygithub.com

BolajiOlajide/dotfiles

编写 Remotion React 标记的最佳实践指南

dotfiles 是什么?

这个技能为开发者提供了在 Remotion 中编写 React 标记的详细最佳实践指南。它涵盖了动画属性使用 `useCurrentFrame()` 和 `interpolate()` 的正确方法,推荐使用 `interpolate()` 而非 `spring()`,并优先使用内联可编辑的关键帧和 CSS 简写属性(如 `scale`、`translate`、`rotate`)。同时,明确禁止使用 CSS 过渡或动画,因为它们在 Remotion 中无法正确渲染。技能还详细说明了资源管理(使用 `public/` 文件夹和 `staticFile()`)、音视频和图片组件(`<Video>`、`<Audio>`、`<Img>`)、序列(`<Sequence>`)的延迟与持续时间控制,以及文本高亮、语音旁白、剪辑、嵌入视频/音频、转场、视觉效果、3D 内容、音效、音频可视化、字幕、字体加载、GIF、Lottie 动画、高级计时、参数化视频、DOM 节点测量、FFmpeg 使用、静音检测、动态时长/尺寸/数据、高级合成和排序等广泛主题。该技能适用于 Claude Code、Cursor 等 AI 代理工具,帮助开发者高效构建可编辑、高性能的 Remotion 视频项目。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/BolajiOlajide/dotfiles/tree/HEAD/ai/skills/remotion-markup

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

预览

来自技能 README

文档

这是编写 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"]),
}}

// 👎 隐藏的值和变换字符串在 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>;
};

文本高亮与标注

关于文本高亮(高亮标记)、圆圈、下划线、删除线、划掉文字、方框和括号,请参见 text-highlights.md。

语音旁白

关于使用 ElevenLabs TTS 为 Remotion 合成添加 AI 生成的语音旁白,请参见 voiceover.md。

剪辑

关于剪辑模式——剪切动画的开头或结尾,请参见 trimming.md。

嵌入视频

关于嵌入视频的高级知识——剪辑、音量、速度、循环、音高,请参见 embedding-videos.md。

视频编辑

关于在 Remotion Studio 中构建可编辑的视频时间线,请参见 video-editing.md。

嵌入音频

关于高级音频功能,如剪辑、音量、速度、音高,请参见 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 内容

关于使用 Three.js 和 React Three Fiber 在 Remotion 中创建 3D 内容,请参见 3d.md。

音效

当需要使用音效时,请加载 ./sfx.md 文件获取更多信息。

音频可视化

当需要可视化音频(频谱条、波形、低音响应效果)时,请加载 ./audio-visualization.md 文件获取更多信息。

字幕

当涉及字幕时,请加载 Remotion 字幕 技能获取更多信息。

Google 字体

是在 Remotion 中加载字体的推荐方式。请参见 google-fonts.md 了解如何加载 Google 字体。

本地字体

请参见 local-fonts.md 了解如何加载本地字体。

GIF

请参见 gifs.md 了解如何显示与 Remotion 时间线同步的 GIF。

高级图像

请参见 images.md 了解图像大小和位置、动态图像路径以及获取图像尺寸。

Lottie 动画

请参见 lottie.md 了解如何在 Remotion 中嵌入 Lottie 动画。

高级计时

请参见 timing.md 了解使用 interpolate 和 Bézier 缓动以及弹簧的高级计时。

参数化视频

请参见 parameters.md 了解通过添加 Zod 模式使合成可参数化。

测量 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。

预览标记

仅在您认为用户希望看到预览时执行此操作。

npx remotion studio --no-open

这将启动一个长时间运行的进程,并打印预览的服务器 URL。
如果已经启动,将打印该 URL。

可选:单帧渲染检查

您可以使用 CLI 渲染单帧以检查布局、颜色或计时。
对于琐碎的编辑、纯粹的重构,或者当您已从 Studio 或先前的渲染中获得足够信心时,请跳过此步骤。

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

在 30 fps 时,--frame=30 对应一秒标记(--frame 从零开始)。

Individual skills in this repo

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

相关技能