Jump Cutting
You might wanna use a "jump cut" to skip parts of a video.
Use the following snippet to skip certain sections of a video, without re-mounting it.
tsx
importReact , {useMemo } from 'react';import {CalculateMetadataFunction ,OffthreadVideo ,staticFile ,useCurrentFrame ,} from 'remotion';constfps = 30;typeSection = {startFrom : number;endAt : number;};export constSAMPLE_SECTIONS :Section [] = [{startFrom : 0,endAt : 5 *fps },{startFrom : 7 *fps ,endAt : 10 *fps ,},{startFrom : 13 *fps ,endAt : 18 *fps ,},];typeProps = {sections :Section [];};export constcalculateMetadata :CalculateMetadataFunction <Props > = ({props ,}) => {constdurationInFrames =props .sections .reduce ((acc ,section ) => {returnacc +section .endAt -section .startFrom ;}, 0);return {fps ,durationInFrames ,};};export constJumpCuts :React .FC <Props > = ({sections }) => {constframe =useCurrentFrame ();conststartFrom =useMemo (() => {letsummedUpDurations = 0;for (constsection ofsections ) {summedUpDurations +=section .endAt -section .startFrom ;if (summedUpDurations >frame ) {returnsection .endAt -summedUpDurations ;}}return null;}, [frame ,sections ]);if (startFrom === null) {return null;}return (<OffthreadVideo pauseWhenBuffering startFrom ={startFrom }// Remotion will automatically add a time fragment to the end of the video URL// based on `startFrom` and `endAt`. Opt out of this by adding one yourself.// https://www.remotion.dev/docs/media-fragmentssrc ={`${staticFile ('time.mp4')}#t=0,`}/>);};
tsx
importReact , {useMemo } from 'react';import {CalculateMetadataFunction ,OffthreadVideo ,staticFile ,useCurrentFrame ,} from 'remotion';constfps = 30;typeSection = {startFrom : number;endAt : number;};export constSAMPLE_SECTIONS :Section [] = [{startFrom : 0,endAt : 5 *fps },{startFrom : 7 *fps ,endAt : 10 *fps ,},{startFrom : 13 *fps ,endAt : 18 *fps ,},];typeProps = {sections :Section [];};export constcalculateMetadata :CalculateMetadataFunction <Props > = ({props ,}) => {constdurationInFrames =props .sections .reduce ((acc ,section ) => {returnacc +section .endAt -section .startFrom ;}, 0);return {fps ,durationInFrames ,};};export constJumpCuts :React .FC <Props > = ({sections }) => {constframe =useCurrentFrame ();conststartFrom =useMemo (() => {letsummedUpDurations = 0;for (constsection ofsections ) {summedUpDurations +=section .endAt -section .startFrom ;if (summedUpDurations >frame ) {returnsection .endAt -summedUpDurations ;}}return null;}, [frame ,sections ]);if (startFrom === null) {return null;}return (<OffthreadVideo pauseWhenBuffering startFrom ={startFrom }// Remotion will automatically add a time fragment to the end of the video URL// based on `startFrom` and `endAt`. Opt out of this by adding one yourself.// https://www.remotion.dev/docs/media-fragmentssrc ={`${staticFile ('time.mp4')}#t=0,`}/>);};