fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.96k stars 881 forks source link

How to add subtitles to m3u8 #835

Open daominhsangvn opened 6 years ago

daominhsangvn commented 6 years ago

Version information

Example Code

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"
xedsvg commented 6 years ago

Did you try to pass the subtitle as an input?

ffmpeg -i video.mp4 -i subtitle.srt -c copy -c:s webvtt -start_number 0 -hls_time 10 -hls_list_size 0 -f hls out/index.m3u8

[Source]

karimkhamwani commented 5 years ago

@xedsvg your cmd works in cmd but how to pass vtt file to this package? any example

xedsvg commented 5 years ago

@karimkhamwani what do you mean? It should be the same example as above. You just replace subtitle.srt with your subtitle.vtt. Can you post your code so we can understand what do you mean?

juliosouzam commented 4 years ago

@karimkhamwani can you tell us if this solution works? and put some final example.

halconel commented 4 months ago

Did you try to pass the subtitle as an input?

ffmpeg -i video.mp4 -i subtitle.srt -c copy -c:s webvtt -start_number 0 -hls_time 10 -hls_list_size 0 -f hls out/index.m3u8

[Source]

it does not work for me


command:

ffmpeg -i sample_video_transcript.srt -i sample_video.mp4 \
  -c:v copy -c:a copy -c:s webvtt \
  -f hls \
  -hls_time 6 -hls_list_size 0 -hls_allow_cache 1 -start_number 1 \
  -master_pl_name master.m3u8 output/index.m3u8

output master.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=1217707,RESOLUTION=720x1280
index.m3u8

missing line in master.m3u8

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