Displaying captions
See importing and transcribing captions first to see how to produce captions.
Once you have captions to work with, you are free to render captions as you like by using React:
Render the current wordimport type {Caption } from '@remotion/captions'; import {useCurrentFrame ,useVideoConfig } from 'remotion'; constcaptions :Caption [] = [ {text : 'Hello there.',startMs : 0,endMs : 1000,timestampMs : null,confidence : null, }, {text : 'Welcome to the demo.',startMs : 1000,endMs : 2500,timestampMs : null,confidence : null, }, ]; export constSimpleCaptions = () => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); consttimeMs = (frame /fps ) * 1000; constcaption =captions .find (({startMs ,endMs }) =>startMs <=timeMs &&timeMs <endMs ); if (!caption ) { return null; } return ( <div style ={{position : 'absolute',left : 0,right : 0,bottom : 64,color : 'white',fontSize : 48,textAlign : 'center',textShadow : '0 2px 8px black', }} > {caption .text } </div > ); };
Make captions editable in Studiov4.0.536
Use Interactive.create() with Interactive.captionsSchema to declare your component as one that displays captions.
- In the Studio, captions will appear as orange layers and show the transcript.
- You can click captions to select them.
- In the inspector, you can edit the transcript.
- You can retime, and move the captions.
Captions.tsximport type {Caption } from '@remotion/captions'; import {Interactive ,useCurrentFrame ,useVideoConfig } from 'remotion'; constCaptionsInner = ({captions }: {readonlycaptions :Caption []}) => { constframe =useCurrentFrame (); const {fps } =useVideoConfig (); consttimeMs = (frame /fps ) * 1000; constcaption =captions .find (({startMs ,endMs }) =>startMs <=timeMs &&timeMs <endMs ); if (!caption ) { return null; } return ( <div style ={{position : 'absolute',left : 48,right : 48,bottom : 64,color : 'white',fontSize : 48,textAlign : 'center',textShadow : '0 2px 8px black',whiteSpace : 'pre-wrap', }} > {caption .text } </div > ); }; export constCaptions =Interactive .create ({Component :CaptionsInner ,layout : 'absolute-fill',schema :Interactive .captionsSchema , });
Splitting and changing speed of clips
We recommend the following best practices for your markup:
- Directly inline the captions in your React markup, making it editable in the Studio.
- Put the captions layer adjacent to the video or audio it belongs to and wrap both in another component using
Interactive.create(). - Trim, split and adjust the speed of your clips only on the outer instance.
This keeps the captions in sync with the media and avoids duplicating the transcript.
This example shows how a scene is split into multiple clips, which have different speeds.
The captions remain in sync with the video and have a single source of truth.
In addition, <Track> is being used to keep the clips on the same timeline row.
CaptionedVideo.tsximport {Video } from '@remotion/media'; import {Interactive ,staticFile ,Track ,useVideoConfig } from 'remotion'; import {Captions } from './Captions'; constCaptionedVideoInner = () => ( <> <Video name ="Footage"src ={staticFile ('video.mp4')} /> <Captions name ="Captions"captions ={[ {text : 'Hello there.',startMs : 2000,endMs : 3000,timestampMs : null,confidence : null, }, {text : 'Welcome to the demo.',startMs : 3000,endMs : 5000,timestampMs : null,confidence : null, }, ]} /> </> ); constCaptionedVideo =Interactive .create ({Component :CaptionedVideoInner ,layout : 'absolute-fill', }); export constMyComposition = () => { const {fps } =useVideoConfig (); return ( <Track name ="Captioned clips"> <CaptionedVideo name ="First cut"trimBefore ={2 *fps }durationInFrames ={3 *fps } /> <CaptionedVideo name ="Faster repeat"from ={3 *fps }trimBefore ={2 *fps }durationInFrames ={3 *fps }playbackRate ={1.5} /> </Track > ); };
Next steps
- Styling captions to change how captions look on screen.
- Editing captions to correct text and adjust page breaks.