Capítulo 675 de 988

Chapter 675: serializeSrt()

Core Idea

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

Key Concepts

  • API
  • lines
  • Return value
  • See also

Code Examples

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.
`
*/
  • What it demonstrates: Usage pattern for serializeSrt() from the official docs.

Key Takeaways

  1. Understand api when working with serializeSrt().
  2. Understand lines when working with serializeSrt().
  3. Understand return value when working with serializeSrt().
  4. Understand see also when working with serializeSrt().

Connects To

  • api: related page in the Captions (@remotion/captions) section.
  • Caption: related page in the Captions (@remotion/captions) section.
  • Create Tiktok Style Captions: related page in the Captions (@remotion/captions) section.