]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/postprocessor/ffmpeg.py
Add field `name` for subtitles
[yt-dlp.git] / yt_dlp / postprocessor / ffmpeg.py
index 0e160f5dcd91a985f33fcbf8c43d4568e15580f1..b156108293ba92806fba457e7333aa46b095fea6 100644 (file)
@@ -474,8 +474,7 @@ def run(self, information):
         filename = information['filepath']
 
         ext = information['ext']
-        sub_langs = []
-        sub_filenames = []
+        sub_langs, sub_names, sub_filenames = [], [], []
         webm_vtt_warn = False
         mp4_ass_warn = False
 
@@ -485,6 +484,7 @@ def run(self, information):
                 self.report_warning('JSON subtitles cannot be embedded')
             elif ext != 'webm' or ext == 'webm' and sub_ext == 'vtt':
                 sub_langs.append(lang)
+                sub_names.append(sub_info.get('name'))
                 sub_filenames.append(sub_info['filepath'])
             else:
                 if not webm_vtt_warn and ext == 'webm' and sub_ext != 'vtt':
@@ -510,10 +510,13 @@ def run(self, information):
         ]
         if information['ext'] == 'mp4':
             opts += ['-c:s', 'mov_text']
-        for (i, lang) in enumerate(sub_langs):
+        for i, (lang, name) in enumerate(zip(sub_langs, sub_names)):
             opts.extend(['-map', '%d:0' % (i + 1)])
             lang_code = ISO639Utils.short2long(lang) or lang
             opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code])
+            if name:
+                opts.extend(['-metadata:s:s:%d' % i, 'handler_name=%s' % name,
+                             '-metadata:s:s:%d' % i, 'title=%s' % name])
 
         temp_filename = prepend_extension(filename, 'temp')
         self.to_screen('Embedding subtitles in "%s"' % filename)
@@ -605,7 +608,8 @@ def ffmpeg_escape(text):
                 in_filenames.append(metadata_filename)
                 options.extend(['-map_metadata', '1'])
 
-        if '__infojson_filename' in info and info['ext'] in ('mkv', 'mka'):
+        if ('no-attach-info-json' not in self.get_param('compat_opts', [])
+                and '__infojson_filename' in info and info['ext'] in ('mkv', 'mka')):
             old_stream, new_stream = self.get_stream_number(
                 filename, ('tags', 'mimetype'), 'application/json')
             if old_stream is not None: