How to add subtitles to m3u8

Author: daominhsangvnCreated Jul 19, 2018Updated Jan 27, 2025

Version information

  • fluent-ffmpeg version: 2.1.2
  • ffmpeg version: 4.0.2
  • OS: MAC OS

Example Code

javascript
ffmpeg(input, { timeout: 432000 }).addOptions([
      '-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
      '-level 3.0',
      '-s 640x360',          // 640px width, 360px height output video dimensions
      '-start_number 0',     // start the first .ts segment at index 0
      '-hls_time 10',        // 10 second segment duration
      '-hls_list_size 0',    // Maxmimum number of playlist entries (0 means all entries/infinite)
      '-f hls'               // HLS format
    ])
      .output(path.join(output, 'playlist.m3u8')).on('end', (err) => {
        console.log('convert done');
      })
      .run();

Above code is working good, it generated various ts files for streaming. But i dont know how to add WebVTT subtitle into the m3u8 playlist. Something like this in the playlist.m3u8:

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="subtitles_en.m3u8"

Source: fluent-ffmpeg/node-fluent-ffmpeg