serializeSrt()v4.0.216
Converts a two-dimensional array of Caption
items into a string in the SubRip format (.srt
).
Example usagetsx
import {serializeSrt ,Caption } from '@remotion/captions';constcaptions :Caption [] = [{text : 'Welcome to the Example Subtitle File!',startMs : 0,endMs : 2500,timestampMs : 1250,confidence : 1,},{text : 'This is a demonstration of SRT subtitles.',startMs : 3000,endMs : 6000,timestampMs : 4500,confidence : 1,},{text : 'You can use SRT files to add subtitles to your videos.',startMs : 7000,endMs : 10500,timestampMs : 8750,confidence : 1,},];constlines =captions .map ((caption ) => [caption ]);constserialized =serializeSrt ({lines });/* serialized = `100:00:00,000 --> 00:00:02,500Welcome to the Example Subtitle File!200:00:03,000 --> 00:00:06,000This is a demonstration of SRT subtitles.300:00:07,000 --> 00:00:10,500You can use SRT files to add subtitles to your videos.`*/
Example usagetsx
import {serializeSrt ,Caption } from '@remotion/captions';constcaptions :Caption [] = [{text : 'Welcome to the Example Subtitle File!',startMs : 0,endMs : 2500,timestampMs : 1250,confidence : 1,},{text : 'This is a demonstration of SRT subtitles.',startMs : 3000,endMs : 6000,timestampMs : 4500,confidence : 1,},{text : 'You can use SRT files to add subtitles to your videos.',startMs : 7000,endMs : 10500,timestampMs : 8750,confidence : 1,},];constlines =captions .map ((caption ) => [caption ]);constserialized =serializeSrt ({lines });/* serialized = `100:00:00,000 --> 00:00:02,500Welcome to the Example Subtitle File!200:00:03,000 --> 00:00:06,000This is a demonstration of SRT subtitles.300:00:07,000 --> 00:00:10,500You can use SRT files to add subtitles to your videos.`*/
API
lines
An two-dimensional array of Caption
items.
Each top-level item represents a line in the SubRip file.
The second-level items represent the words in that line.
Words get concatenated together during serialization. No spaces are added between the words.
The start timestamp is determined from the startMs
value of the first word in the line.
The end timestamp is determined from the endMs
value of the last word in the line.
Arrays with no items will be ignored.
Return value
A string in the SubRip format (.srt
).