axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
2.01k stars 482 forks source link

Including subtitles for HLS FMP4 #225

Closed ajagannath closed 6 years ago

ajagannath commented 6 years ago

I am trying to get subtitles with fragmented mp4 HLS. While I am at it, found a bug

 mp4dash --subtitles frag_with_sub.mp4 --hls --debug
Parsing media file 1: frag_with_sub.mp4
Processing MP4 file frag_with_sub.mp4
  found 10 segments
COMMAND:  ../bin/mp4info --fast --format json frag_with_sub.mp4 ['../bin/mp4info', '--fast', '--format', 'json', 'frag_with_sub.mp4']
COMMAND:  ../bin/mp4dump --verbosity 1 --format json frag_with_sub.mp4 ['../bin/mp4dump', '--verbosity', '1', '--format', 'json', 'frag_with_sub.mp4']
Traceback (most recent call last):
  File "../utils/mp4-dash.py", line 1837, in <module>
    main()
  File "../utils/mp4-dash.py", line 1619, in main
    (audio_sets, video_sets, subtitles_sets, mp4_files) = SelectTracks(options, media_sources)
  File "../utils/mp4-dash.py", line 1039, in SelectTracks
    mp4_file = Mp4File(Options, media_source)
  File "../utils/mp4utils.py", line 632, in __init__
    self.tracks[track_id].update(options)
  File "../utils/mp4utils.py", line 457, in update
    self.bandwidth = ComputeBandwidth(options.min_buffer_time, self.segment_sizes, self.segment_durations)
  File "../utils/mp4utils.py", line 700, in ComputeBandwidth
    bandwidth = 8.0*(accu_size-buffer_size)/accu_duration

Checking for accu_duraion > 0 here fixed this.

However I am not seeing any subtitle track added to the master.m3u8.

#EXTM3U
# Created with Bento4 mp4-dash.py, VERSION=1.8.0-621
#
#EXT-X-VERSION:6

# Media Playlists

# Audio
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio/mp4a",LANGUAGE="und",NAME="Unknown",AUTOSELECT=YES,DEFAULT=YES,URI="audio/und/mp4a/media.m3u8"

# Video
#EXT-X-STREAM-INF:AUDIO="audio/mp4a",AVERAGE-BANDWIDTH=720437,BANDWIDTH=797414,CODECS="avc1.42C01F,mp4a.40.2",RESOLUTION=1280x720
video/avc1/media.m3u8

# I-Frame Playlists
#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH=641907,BANDWIDTH=718414,CODECS="avc1.42C01F",RESOLUTION=1280x720,URI="video/avc1/media.m3u8"

What kind of subtitle tracks are supported at the input? and how do I use bento to get IMSC1 compatible subtitles added?

Media: bento_test_sample.zip

barbibulle commented 6 years ago

Thanks for reporting this. I'll fix this ASAP and push an update shortly.

barbibulle commented 6 years ago

I fixed the bug. Regarding the subtitles here, your input file does have a subtitles track (track ID 3), but it has almost nothing in it (just one sample with 2 bytes of data). It is a TTML track (IMSC1), which is supported, but with no data in it, it is hard to test. (there's some more detailed info about subtitle support in Bento4 here: https://www.bento4.com/developers/dash/subtitles/) IMSC1 subtitles in HLS are supported by the standard, so in theory it should work. The apple recommendations say that for subtitles, the CODECS string "SHOULD" include "stpp.ttml.im1t” for IMSC1 subtitles, which isn't currently done by Bento4, but I'll add that in the next release. In the meantime, can you try again with an input file that actually contains non-empty subtitles?

barbibulle commented 6 years ago

Actually, following up to my previous reply, it looks like your input file also has the subtitle track in 'tx3g (Timed Text)' format, not 'stpp'. The only format supported by HLS/Apple is 'stpp' (which is supported by Bento4).