Skip to main content

serializeSrt()v4.0.216

将二维数组的 Caption 项转换为 SubRip 格式(.srt)的字符串。

🌐 Converts a two-dimensional array of Caption items into a string in the SubRip format (.srt).

Example usage
import {serializeSrt, Caption} from '@remotion/captions'; const captions: 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, }, ]; const lines = captions.map((caption) => [caption]); const serialized = 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

一个由 Caption 项组成的二维数组。

🌐 An two-dimensional array of Caption items.

每个顶层项目代表 SubRip 文件中的一行。

🌐 Each top-level item represents a line in the SubRip file.

二级项目表示该行中的单词。 在序列化过程中,单词会被连接在一起。单词之间不会添加空格。 起始时间戳由该行中第一个单词的 startMs 值确定。 结束时间戳由该行中最后一个单词的 endMs 值确定。

🌐 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

SubRip 格式的字符串(.srt)。

🌐 A string in the SubRip format (.srt).

另请参阅

🌐 See also