Skip to content

🎥 Make videos programmatically with React

Skills: Keep frame subscriptions local in Remotion markup

JonnyBurgerc8bd82b4babd
diff --git a/.agents/skills/remotion-new-markup/SKILL.md b/.agents/skills/remotion-new-markup/SKILL.md
index 8ac82eeaa7..06d327b719 100644
--- a/.agents/skills/remotion-new-markup/SKILL.md
+++ b/.agents/skills/remotion-new-markup/SKILL.md
@@ -15,6 +15,28 @@ For footage with synchronized captions or overlays, also read
For extracting a group into its own timeline, use
[connected compositions](../../../packages/skills/skills/remotion-markup/connected-compositions.md).
+## Keep frame subscriptions local
+
+Call `useCurrentFrame()` in the smallest component that needs the frame to
+render. Keep composition and scene components that arrange clips and tracks
+free of frame subscriptions when only a soundtrack volume, animated title, or
+overlay needs to change. Extract that item into a component defined at module
+scope, and read the frame there instead of passing it down from the parent.
+This prevents that animation from re-rendering unrelated clips and scenes on
+every frame.
+
+Keep editable `interpolate()` calls inline on the animated item's props. For
+example, a `Soundtrack` component can read `useCurrentFrame()` and return an
+`Audio` with `volume={interpolate(frame, ...)}`, while the composition only
+renders `<Soundtrack />` alongside its scenes. Prefer a static value when the
+output does not actually vary with the frame.
+
+Preserve the existing timing boundary when extracting: placing the hook inside
+a `Sequence` or a timed component changes its frame coordinates. Keep trims,
+offsets, volume envelopes, and animation keyframes on the same clock, or adjust
+the keyframes deliberately to preserve the edit. A plain React component is
+enough for this render boundary; add timeline wrappers only for editing needs.
+
Verify a structural change in the full composition and any standalone views.
Preserve the existing edit, and distinguish useful markup grouping from Studio's
row expansion and layout behavior.
diff --git a/packages/jonnys-videos/src/roller-skis/Composition.tsx b/packages/jonnys-videos/src/roller-skis/Composition.tsx
index 249582d981..a979878985 100644
--- a/packages/jonnys-videos/src/roller-skis/Composition.tsx
+++ b/packages/jonnys-videos/src/roller-skis/Composition.tsx
@@ -649,9 +649,31 @@ const PresenterIntroductionInner: React.FC = () => {
);
};
-const RollerSkiRoughCutInner: React.FC = () => {
+const AnimatedYouTubeEndCard: React.FC = () => {
const frame = useCurrentFrame();
+ return (
+ <YouTubeEndCard
+ name="Jonny Burger YouTube end card"
+ from={END_CARD_START}
+ durationInFrames={END_CARD_DURATION_IN_FRAMES}
+ style={{
+ translate: interpolate(
+ frame,
+ [12115, 12139],
+ ['1920px 0px', '0px 0px'],
+ {
+ easing: [Easing.bezier(0.22, 1, 0.36, 1)],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ },
+ ),
+ }}
+ />
+ );
+};
+
+const RollerSkiRoughCutInner: React.FC = () => {
return (
<>
<TransitionSeries>
@@ -1340,10 +1362,7 @@ const RollerSkiRoughCutInner: React.FC = () => {
style={videoStyle}
objectFit="cover"
effects={[lut({content: outdoorLut})]}
- volume={interpolate(frame, [2697, 2896], [1, 1], {
- extrapolateLeft: 'clamp',
- extrapolateRight: 'clamp',
- })}
+ volume={1}
/>
<BasicCaptions
name="Climbing the incline captions"
@@ -3935,23 +3954,7 @@ const RollerSkiRoughCutInner: React.FC = () => {
/>
</TransitionSeries.Sequence>
</TransitionSeries>
- <YouTubeEndCard
- name="Jonny Burger YouTube end card"
- from={END_CARD_START}
- durationInFrames={END_CARD_DURATION_IN_FRAMES}
- style={{
- translate: interpolate(
- frame,
- [12115, 12139],
- ['1920px 0px', '0px 0px'],
- {
- easing: [Easing.bezier(0.22, 1, 0.36, 1)],
- extrapolateLeft: 'clamp',
- extrapolateRight: 'clamp',
- },
- ),
- }}
- />
+ <AnimatedYouTubeEndCard />
<Track name="Music">
<Audio
name="No School Today music"
diff --git a/packages/skills/skills/remotion-markup/SKILL.md b/packages/skills/skills/remotion-markup/SKILL.md
index 1faf893caa..8018a2822b 100644
--- a/packages/skills/skills/remotion-markup/SKILL.md
+++ b/packages/skills/skills/remotion-markup/SKILL.md
@@ -15,6 +15,13 @@ If you detect a surprising change made in the meanwhile, don't overwrite it, ass
## General rules
+Keep `useCurrentFrame()` in the smallest component that needs it. Extract
+frame-dependent audio volume, titles, and overlays into their own components
+instead of subscribing the whole composition or scene; otherwise unrelated
+descendants re-render on every frame. Preserve the existing frame coordinates
+when extracting across timing boundaries, and keep editable interpolations
+inline on the item's props.
+
Inside a composition or scene component, get `fps` from `useVideoConfig()` for
all seconds-to-frames calculations, including timing props such as `from`,
`trimBefore` and `durationInFrames`. Keeping the expression on