Skip to content

Commit b9cdd78

Browse files
Merge pull request #62 from BlurryBat/master
Please add usage instruction link subtitles in Manifest for HLS
2 parents 731530f + 4f66471 commit b9cdd78

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

ffmpeg_streaming/_hls_helper.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,25 @@ def rotate_key(self, line: str):
7777
self.update_suffix()
7878
self.generate()
7979

80+
def sub_info(rep, sub_path) -> list:
81+
"""
82+
Returns the subtitle information to be added to manifest.
83+
84+
Parameters
85+
----------
86+
rep : Representation
87+
sub_path : subtitle manifest file name
88+
"""
89+
tag = '#EXT-X-MEDIA:'
90+
info = [
91+
f'TYPE=SUBTITLES',
92+
f'GROUP-ID="subs"',
93+
f'NAME="subtitles"',
94+
f'URI="'+sub_path+'"'
95+
]
96+
return [tag + ",".join(info)]
8097

81-
def stream_info(rep) -> list:
98+
def stream_info(rep, sub_exists) -> list:
8299
"""
83100
@TODO: add documentation
84101
"""
@@ -88,6 +105,8 @@ def stream_info(rep) -> list:
88105
f'RESOLUTION={rep.size}',
89106
f'NAME="{rep.size.height}"'
90107
]
108+
if sub_exists:
109+
info.append(f'SUBTITLES="subs"')
91110
custom = rep.options.pop('stream_info', [])
92111

93112
return [tag + ",".join(info + custom)]
@@ -114,7 +133,11 @@ def _content(self) -> str:
114133
content = ['#EXTM3U'] + self._get_version() + self.media.options.get('description', [])
115134

116135
for rep in self.media.reps:
117-
content += stream_info(rep) + self.stream_path(rep)
136+
sub_exists=os.path.isfile(os.path.dirname(self.media.output_)+'/'+self.sub_path(rep)[0])
137+
if(sub_exists):
138+
content += sub_info(rep,self.sub_path(rep)[0]) + stream_info(rep,sub_exists) + self.stream_path(rep)
139+
else:
140+
content += stream_info(rep,sub_exists) + self.stream_path(rep)
118141

119142
return "\n".join(content)
120143

@@ -130,3 +153,13 @@ def stream_path(self, rep):
130153
@TODO: add documentation
131154
"""
132155
return ["{}_{}p.m3u8".format(os.path.basename(self.media.output_).split('.')[0], rep.size.height)]
156+
157+
def sub_path(self, rep):
158+
"""
159+
Returns the subtitles maifest file name.
160+
161+
Parameters
162+
----------
163+
rep : Representation
164+
"""
165+
return ["{}_{}p_vtt.m3u8".format(os.path.basename(self.media.output_).split('.')[0], rep.size.height)]

0 commit comments

Comments
 (0)