Skip to content

Commit 8dca94c

Browse files
scastielclaude
andauthored
Fix blank frames when speed > 1 (#26) (#39)
The speed setting scaled the frame-sampling index (frame * speed) but left each sequence's durationInFrames unscaled, so at speed=2 the index ran past the pre-rendered frames array halfway through each typing sequence, rendering undefined (blank). Scale durationInFrames by 1/speed for non-transition sequences so the real timeline matches the content timeline, and clamp the sample index as a safety net. Transition sequences keep their fixed 20-frame slide timing. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7661bde commit 8dca94c

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎src/components/remotion/code-composition.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ function CodeSequences({
152152
lang={seq.lang}
153153
filename={seq.filename}
154154
filenames={filenames}
155-
codeForFrame={(frame) => seq.frames[Math.floor(frame * speed)]}
155+
codeForFrame={(frame) => {
156+
const effectiveSpeed = seq.isTransition ? 1 : speed
157+
const index = Math.min(
158+
Math.floor(frame * effectiveSpeed),
159+
seq.frames.length - 1,
160+
)
161+
return seq.frames[index]
162+
}}
156163
watermark={watermark}
157164
scale={scale}
158165
font={font}

‎src/components/remotion/composition-data.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,23 @@ export function getCompositionData({
127127
filename: steps[steps.length - 1]?.filename,
128128
})
129129

130-
return { sequences, metadata }
130+
const { speed } = metadata
131+
const scaledSequences =
132+
speed === 1
133+
? sequences
134+
: sequences.map((seq) =>
135+
seq.isTransition
136+
? seq
137+
: {
138+
...seq,
139+
durationInFrames: Math.max(
140+
1,
141+
Math.ceil(seq.durationInFrames / speed),
142+
),
143+
},
144+
)
145+
146+
return { sequences: scaledSequences, metadata }
131147
}
132148

133149
export type CompositionData = ReturnType<typeof getCompositionData>

0 commit comments

Comments
 (0)