Playing videos in sequence
To play multiple videos one after another:
Render each<Video> in a <Series.Sequence>. calculateMetadata().
Create the video series
Render each <Video> in a <Series.Sequence> and set its durationInFrames:
VideosInSequence.tsximport {Video } from '@remotion/media'; importReact from 'react'; import {Series ,useVideoConfig } from 'remotion'; export typeVideoToEmbed = {src : string;durationInFrames : number | null; }; export typeVideosInSequenceProps = {videos :VideoToEmbed []; }; export constVideosInSequence :React .FC <VideosInSequenceProps > = ({videos }) => { const {fps } =useVideoConfig (); return ( <Series > {videos .map ((video ) => { if (video .durationInFrames === null) { throw newError ('Could not get video duration'); } return ( <Series .Sequence key ={video .src }durationInFrames ={video .durationInFrames }premountFor ={fps } > <Video src ={video .src } /> </Series .Sequence > ); })} </Series > ); };
premountFor mounts each video one second before it enters the timeline, giving it time to load in the Player.
Calculate the durations
Create a calculateMetadata() function that gets the duration of each video using Mediabunny's computeDuration(), converts the durations to frames, and returns their sum as the composition duration:
calculate-metadata.tsimport {ALL_FORMATS ,Input ,UrlSource } from 'mediabunny'; import type {CalculateMetadataFunction } from 'remotion'; import type {VideosInSequenceProps } from './VideosInSequence'; constgetVideoDuration = async (src : string) => { constinput = newInput ({formats :ALL_FORMATS ,source : newUrlSource (src , {getRetryDelay : () => null, }), }); returninput .computeDuration (); }; export constcalculateMetadata :CalculateMetadataFunction <VideosInSequenceProps > = async ({props }) => { constfps = 30; constvideos = awaitPromise .all (props .videos .map (async (video ) => { constdurationInSeconds = awaitgetVideoDuration (video .src ); return { ...video ,durationInFrames :Math .floor (durationInSeconds *fps ), }; }), ); constdurationInFrames =videos .reduce ( (sum ,video ) =>sum +video .durationInFrames , 0, ); return {durationInFrames ,fps ,props : { ...props ,videos , }, }; };
Mediabunny loads the assets using fetch(). Remote URLs must be CORS-enabled; files referenced with staticFile() are served from the same origin.
Register the composition
In the root file, register the component and pass the videos through defaultProps:
Root.tsximportReact from 'react'; import {Composition ,staticFile } from 'remotion'; import {calculateMetadata } from './calculate-metadata'; import {VideosInSequence } from './VideosInSequence'; export constRemotionRoot :React .FC = () => { return ( <Composition id ="VideosInSequence"component ={VideosInSequence }width ={1920}height ={1080}defaultProps ={{videos : [ {durationInFrames : null,src : 'https://remotion.media/BigBuckBunny.mp4', }, {durationInFrames : null,src :staticFile ('localvideo.mp4'), }, ], }}calculateMetadata ={calculateMetadata } /> ); };
Browser autoplay policies
Mobile browsers may block videos that start after the beginning of the composition. See the notes about browser autoplay behavior for the available options.