serializeSrt()v4.0.216
Converts a two-dimensional array of Caption items into a string in the SubRip format (.srt).
Example usageimport {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 = `1 00:00:00,000 --> 00:00:02,500 Welcome to the Example Subtitle File! 2 00:00:03,000 --> 00:00:06,000 This is a demonstration of SRT subtitles. 3 00:00:07,000 --> 00:00:10,500 You can use SRT files to add subtitles to your videos. ` */
API
lines
A two-dimensional array of Caption items.
Each top-level item represents a subtitle cue in the SubRip file.
The second-level items represent the words in that cue.
Words get concatenated together during serialization. No spaces are added between the words.
If a word has pageBreakAfter: true, the current cue ends after it and the next word starts a new cue. Use a newline in text to create multiple visual lines within one cue.
The start timestamp is determined from the startMs value of the first word in the cue.
The end timestamp is determined from the endMs value of the last word in the cue.
Arrays with no items will be ignored.
Return value
A string in the SubRip format (.srt).