From 66a1b8643ad3ef492dfd55692dce6be66397e2b4 Mon Sep 17 00:00:00 2001 From: Felix S Date: Sun, 18 Apr 2021 12:48:39 +0200 Subject: [PATCH] [downloader/ism] Support muxing TTML subtitles --- yt_dlp/downloader/ism.py | 11 +++++++++-- yt_dlp/extractor/common.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/yt_dlp/downloader/ism.py b/yt_dlp/downloader/ism.py index 103064df1..07d74aef0 100644 --- a/yt_dlp/downloader/ism.py +++ b/yt_dlp/downloader/ism.py @@ -118,8 +118,7 @@ def write_piff_header(stream, params): vmhd_payload += u16.pack(0) * 3 # opcolor media_header_box = full_box(b'vmhd', 0, 1, vmhd_payload) # Video Media Header elif stream_type == 'text': - sthd_payload = u16.pack(0) * 2 - media_header_box = full_box(b'sthd', 0, 1, sthd_payload) # Subtitle Media Header + media_header_box = full_box(b'sthd', 0, 0, b'') # Subtitle Media Header else: assert False minf_payload = media_header_box @@ -173,6 +172,14 @@ def write_piff_header(stream, params): sample_entry_box = box(b'avc1', sample_entry_payload) # AVC Simple Entry else: assert False + elif stream_type == 'text': + if fourcc == 'TTML': + sample_entry_payload += b'http://www.w3.org/ns/ttml\0' # namespace + sample_entry_payload += b'\0' # schema location + sample_entry_payload += b'\0' # auxilary mime types(??) + sample_entry_box = box(b'stpp', sample_entry_payload) + else: + assert False else: assert False stsd_payload += sample_entry_box diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index 803c7fa06..2ca25951b 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -2816,7 +2816,7 @@ class InfoExtractor(object): for track in stream.findall('QualityLevel'): fourcc = track.get('FourCC', 'AACL' if track.get('AudioTag') == '255' else None) # TODO: add support for WVC1 and WMAP - if fourcc not in ('H264', 'AVC1', 'AACL'): + if fourcc not in ('H264', 'AVC1', 'AACL', 'TTML'): self.report_warning('%s is not a supported codec' % fourcc) continue tbr = int(track.attrib['Bitrate']) // 1000