Different segments at different speeds
If you have a video and want to show different sections of the video at different speeds, use the following snippet.
SegmentSpeeds.tsxtsx
import {OffthreadVideo ,Sequence ,staticFile ,useCurrentFrame } from 'remotion';constsegments = [{duration : 100,speed : 0.5,},{duration : 100,speed : 1,},{duration : 200,speed : 2,},{duration : 400,speed : 4,},];typeAccumulatedSegment = {start : number;passedVideoTime : number;end : number;speed : number;};export constaccumulateSegments = () => {constaccumulatedSegments :AccumulatedSegment [] = [];letaccumulatedDuration = 0;letaccumulatedPassedVideoTime = 0;for (constsegment ofsegments ) {constduration =segment .duration /segment .speed ;accumulatedSegments .push ({end :accumulatedDuration +duration ,speed :segment .speed ,start :accumulatedDuration ,passedVideoTime :accumulatedPassedVideoTime ,});accumulatedPassedVideoTime +=segment .duration ;accumulatedDuration +=duration ;}returnaccumulatedSegments ;};export constSpeedSegments = () => {constframe =useCurrentFrame ();constaccumulated =accumulateSegments ();constcurrentSegment =accumulated .find ((segment ) =>frame >segment .start &&frame <=segment .end ,);if (!currentSegment ) {return;}return (<Sequence from ={currentSegment .start }><OffthreadVideo pauseWhenBuffering startFrom ={currentSegment .passedVideoTime }// Remotion will automatically add a time fragment to the end of the video URL// based on `startFrom`. Opt out of this by adding one yourself.// https://www.remotion.dev/docs/media-fragmentssrc ={`${staticFile ('bigbuckbunny.mp4')}#t=0,`}playbackRate ={currentSegment .speed }/></Sequence >);};
SegmentSpeeds.tsxtsx
import {OffthreadVideo ,Sequence ,staticFile ,useCurrentFrame } from 'remotion';constsegments = [{duration : 100,speed : 0.5,},{duration : 100,speed : 1,},{duration : 200,speed : 2,},{duration : 400,speed : 4,},];typeAccumulatedSegment = {start : number;passedVideoTime : number;end : number;speed : number;};export constaccumulateSegments = () => {constaccumulatedSegments :AccumulatedSegment [] = [];letaccumulatedDuration = 0;letaccumulatedPassedVideoTime = 0;for (constsegment ofsegments ) {constduration =segment .duration /segment .speed ;accumulatedSegments .push ({end :accumulatedDuration +duration ,speed :segment .speed ,start :accumulatedDuration ,passedVideoTime :accumulatedPassedVideoTime ,});accumulatedPassedVideoTime +=segment .duration ;accumulatedDuration +=duration ;}returnaccumulatedSegments ;};export constSpeedSegments = () => {constframe =useCurrentFrame ();constaccumulated =accumulateSegments ();constcurrentSegment =accumulated .find ((segment ) =>frame >segment .start &&frame <=segment .end ,);if (!currentSegment ) {return;}return (<Sequence from ={currentSegment .start }><OffthreadVideo pauseWhenBuffering startFrom ={currentSegment .passedVideoTime }// Remotion will automatically add a time fragment to the end of the video URL// based on `startFrom`. Opt out of this by adding one yourself.// https://www.remotion.dev/docs/media-fragmentssrc ={`${staticFile ('bigbuckbunny.mp4')}#t=0,`}playbackRate ={currentSegment .speed }/></Sequence >);};