Communitygithub.com

remotion-frame-driven-refactor

把 GSAP、Anime.js、Framer Motion、ScrollTrigger、Lottie 或手写 requestAnimationFrame 这类"时间轴/时钟驱动"的动画代码,重构成 Remotion 的"帧驱动"组件(画面 = frame 的纯函数)。当用户想复用一段开源网页动效、把线上 demo 搬进视频、或报告 Remotion 里"动画不跟帧走、导出与预览不一致、偶发错位、渲染出来是静态"时使用。含 API 对照表、七步重构流程、时间源审计脚本与确定性验收。

remotion-frame-driven-refactor とは?

remotion-frame-driven-refactor is a Claude Code agent skill that 把 GSAP、Anime.js、Framer Motion、ScrollTrigger、Lottie 或手写 requestAnimationFrame 这类"时间轴/时钟驱动"的动画代码,重构成 Remotion 的"帧驱动"组件(画面 = frame 的纯函数)。当用户想复用一段开源网页动效、把线上 demo 搬进视频、或报告 Remotion 里"动画不跟帧走、导出与预览不一致、偶发错位、渲染出来是静态"时使用。含 API 对照表、七步重构流程、时间源审计脚本与确定性验收。.

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/GhostFace-yz/remotion-skill-store/tree/HEAD/skills/remotion-frame-driven-refactor

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Frame-Driven Refactoring: Convert "Timeline" Animations to "Frame" Animations

When to Use

  • You have animation code from GSAP / anime.js / framer-motion / Web Animations API / native rAF and want to render it in Remotion
  • You've already ported it, but you see symptoms like: static visuals, export mismatching Studio preview, misalignment on skipped frames, intermittent ghosting in concurrent renders, or animations running faster/slower in the final video than in preview
  • You're considering "screen recording" to work around this—read references/recording-vs-frames.md first; you usually shouldn't record

The One Rule

Visual = f(frame). Given a frame number, produce exactly one set of pixels, independent of rendering order, machine, or concurrency level.

All external time sources must be replaced with frame numbers: requestAnimationFrame, setTimeout, Date.now, performance.now, CSS transition/animation, gsap.ticker, or any animation library's internal Ticker.

The reason is that Remotion renders frames out of order and concurrently: frame 900 may render before frame 300. Any code that "depends on the previous frame's state" (accumulation, eased approximation, spring integration) will produce ghost results.

One-sentence self-check:

Is frame 200 rendered in isolation pixel-identical to frame 200 when rendered as part of a continuous sequence from 0 to 200?

Conversion Base

frame = seconds × fps

Get fps from useVideoConfig(), don't hardcode 30. Same for duration.

Quick Reference (full version in references/gsap-mapping.md)

Original CodeFrame-Driven Equivalent
gsap.to(el, {x: 100, duration: 1})interpolate(frame, [0, fps], [0, 100])
ease: "power2.out"Easing.out(Easing.cubic)
tl.to(a).to(b, "-=0.3")Frame-point constants: const aEnd = aStart + 30; const bStart = aEnd - 9;
stagger: 0.05start + i * Math.round(0.05 * fps)
repeat: -1frame % period
yoyo: trueTriangle wave (pingPong from assets/keyframes.ts)
tl.progress()-driven scrubUse the incoming progress value directly as frame
DOM modifications in onUpdateDon't touch DOM; render from derived values
SplitText character-by-character entryUse charIndex to calculate each character's delay in frames
useSpring / motion.divspring({frame, fps, config})
Draggable / InertiaPluginClosed-form v0*t + ½at², or precomputed curve sampling
canvas rAF loopReplace t with frame; keep the drawing function side-effect-free

Seven-Step Workflow

  1. Audit time sources: bash assets/audit-time-sources.sh <source-dir> – lists all rAF / timers / animation libraries / CSS animations.
  2. Eliminate external state: mouse position, window size, network, Math.random(). If randomness is needed, use random(seed) with an explicit seed; no parameterless random during rendering.
  3. Flatten the timeline: Convert chained timelines into a keyframe table [[frame, value], ...], write frame numbers as constants, and centralize in one timeline module shared by animation, recording script, and export script (don't write it twice).
  4. Derive values at the top of the component: One pure const block for computations, then only rendering below.
  5. Map easings: GSAP ease names → Easing.* (see reference table; note: power1=quad, power2=cubic, don't swap them).
  6. Turn side effects into rendering: el.style.transform = ... → style={{transform: ...}}; imperative canvas draw → parameterized draw function.
  7. Verify (see next section).

Case Study: Pitfalls in a Vertical Promo Video

Symptoms / Root Cause / Fix – applies beyond this specific case.

  1. End freeze frame showed the video's opening Root cause: <Freeze frame>'s frame number was relative to the parent <Sequence> start; using an absolute frame caused an offset. Fix: <Freeze frame={0}> only means "freeze at frame 0 of this segment"; to freeze at absolute frame N, use frame={N - sequence.from}, or avoid Freeze altogether.

  2. Subtitle focus index stuck at 0 Root cause: useCurrentFrame() inside a <Sequence> returns a frame relative to the parent's start; direct comparison against absolute frame never matched. Fix: Unify the absolute frame perspective – subtract from before entering the Sequence (or convert before passing props).

  3. Audio volume curve not working / timing off Root cause: Same relative-frame issue – the callback for <Audio volume={(f) => ...}> receives sequence-local frames. Fix: In the volume callback, compute f + sequenceFrom then look up the curve.

  4. Frame-by-frame accumulation of position jitters on export Root cause: pos += v * dt depends on the previous frame's result, but frames render out of order. Fix: Always use a closed-form solution – pos(frame) computes from starting value + frame number; don't read the previous frame.

  5. CSS transition / @keyframes don't animate in the final video Root cause: Remotion uses seek to capture frames; it doesn't advance the CSS clock, so transitions never complete. Fix: Replace all with inline styles + interpolate; disable or convert transition effects in third-party components via props.

  6. Measured positions offset in preview but correct on export Root cause: Studio preview scales the canvas; getBoundingClientRect() returns scaled values. Fix: Normalize by dividing by container offsetWidth/offsetHeight; use ratios, not pixels.

  7. Async resources (images, fonts, resize measurements) cause blank first frame Root cause: Screenshot captured before data is ready. Fix: Call delayRender() at start, continueRender(handle) at end; for images, additionally await img.decode().

  8. three.js / Lottie / Pixi have their own clocks Root cause: These libraries have built-in tickers or useFrame loops that don't respect Remotion's frame. Fix: Take over the clock – for @remotion/three, use frameloop="never" + advance() each frame; for Lottie, use goToAndStop(frame, true); for Pixi, manually call app.ticker.update() or render frame by frame with render().

Verification

bash assets/verify-determinism.sh <entry-file> <CompositionId> [frame-number] does three things:

  1. Single-frame render (still) vs same frame from a continuous sequence (--sequence) – catches hidden state that "only works when played from frame 0"
  2. Concurrency 1 vs concurrency 8 rendering the same range – catches "depends on render order"
  3. Compares PNG MD5 checksums (don't compare MP4; H.264 is lossy and can't show differences)
# Manual version (what the script does internally)
npx remotion render <entry> <Id> out/seq-a --sequence --image-format=png --frames=196-204 --concurrency=1
npx remotion render <entry> <Id> out/seq-b --sequence --image-format=png --frames=196-204 --concurrency=8
npx remotion still  <entry> <Id> out/still.png --frame=200
# md5 out/seq-a/element-200.png out/seq-b/element-200.png out/still.png   All three must match

Note: --sequence defaults to JPEG output; you must explicitly use --image-format=png; files are named element-[frame].png by default.

Numeric metrics only prove "consistent," not "visually correct" – a human must confirm visual correctness.

When Is Screen Recording Allowed?

See references/recording-vs-frames.md for detail. One-sentence version:

  • Allowed: Real software UI / terminal output (faking it is unprofessional), third-party WebGL scenes you can't modify the source of, complex shaders with prohibitive per-frame rendering budgets
  • Not allowed: Text animations, charts, transitions, particles, anything where "changing one word would require re-recording"
  • Compromise: Recorded footage used as a texture (image) while animation and text are still done frame-driven

Environment Notes

These conclusions were validated on Remotion 4.0.438 + React 19 + three 0.187. Easing actually exports only linear/ease/quad/cubic/poly(n)/sin/circle/exp/elastic(n)/back(s)/bounce/bezier/step0/step1 – no quart/quint, use poly(4)/poly(5) instead.

Attached Assets

FilePurpose
assets/keyframes.tsKeyframe interpolation, loop, yoyo, stagger, progress helpers
assets/audit-time-sources.shScans project for all external clocks (categorized as "high confidence" and "needs manual review")
assets/verify-determinism.shSingle-frame vs sequence, concurrency 1 vs 8, compares PNG MD5
references/gsap-mapping.mdLine-by-line mapping and code examples from GSAP/Anime/Framer to Remotion
references/recording-vs-frames.mdDecision document for recording vs frame-driven (includes real incident postmortems)

関連スキル