Skip to main content

Change the speed of a video over time

note

This does not work with <Video> from @remotion/media yet.

Speeding up a video over time - for example starting at regular speed and then increasingly making it faster - requires some code that stays within Remotion's rules.

It is not as easy as interpolating the playbackRate:

❌ Does not work
<OffthreadVideo playbackRate={interpolate(frame, [0, 100], [1, 5])} src="https://remotion.media/BigBuckBunny.mp4#disable" />;

This is because Remotion will evaluate each frame independently from the other frames. If frame is 100, the playbackRate evaluates as 5 and Remotion will render the 500th frame of the video, which is undesired because it does not take into account that the speed has been building up to 5 until now.

The correct way is to calculate the total time that has elapsed until the current frame, by accumulating the playback rates of the previous frames. Then the video starts from that frame and uses the playback rate of the current frame, so the video plays smoothly.

✅ AcceleratedVideo.tsx
import React from 'react'; import {interpolate, Sequence, useCurrentFrame, OffthreadVideo} from 'remotion'; const remapSpeed = (frame: number, speed: (fr: number) => number) => { let framesPassed = 0; for (let i = 0; i <= frame; i++) { framesPassed += speed(i); } return framesPassed; }; export const AcceleratedVideo: React.FC = () => { const frame = useCurrentFrame(); const speedFunction = (f: number) => interpolate(f, [0, 500], [1, 5]); const remappedFrame = remapSpeed(frame, speedFunction); return ( <Sequence from={frame}> <OffthreadVideo trimBefore={Math.round(remappedFrame)} playbackRate={speedFunction(frame)} src="https://remotion.media/BigBuckBunny.mp4#disable" /> </Sequence> ); };
note

The code disables the media fragment hints that would be appended to the video URL by adding #disable to the end of the URL.

Note that the timeline in the Remotion Studio might move while the video plays, because the sequence is repositioned over time. This is okay as long as the frame is calculated in an idempotent way.

Demo​

See also​