]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/ffmpeg.py
cc65b34e71a28cfb0947b9441d5dcc006baf47ba
[youtubedl] / youtube_dl / postprocessor / ffmpeg.py
1 from __future__ import unicode_literals
2
3 import io
4 import os
5 import subprocess
6 import time
7
8
9 from .common import AudioConversionError, PostProcessor
10
11 from ..compat import (
12 compat_subprocess_get_DEVNULL,
13 )
14 from ..utils import (
15 encodeArgument,
16 encodeFilename,
17 get_exe_version,
18 is_outdated_version,
19 PostProcessingError,
20 prepend_extension,
21 shell_quote,
22 subtitles_filename,
23 dfxp2srt,
24 )
25
26
27 class FFmpegPostProcessorError(PostProcessingError):
28 pass
29
30
31 class FFmpegPostProcessor(PostProcessor):
32 def __init__(self, downloader=None):
33 PostProcessor.__init__(self, downloader)
34 self._determine_executables()
35
36 def check_version(self):
37 if not self.available:
38 raise FFmpegPostProcessorError('ffmpeg or avconv not found. Please install one.')
39
40 required_version = '10-0' if self.basename == 'avconv' else '1.0'
41 if is_outdated_version(
42 self._versions[self.basename], required_version):
43 warning = 'Your copy of %s is outdated, update %s to version %s or newer if you encounter any errors.' % (
44 self.basename, self.basename, required_version)
45 if self._downloader:
46 self._downloader.report_warning(warning)
47
48 @staticmethod
49 def get_versions(downloader=None):
50 return FFmpegPostProcessor(downloader)._versions
51
52 def _determine_executables(self):
53 programs = ['avprobe', 'avconv', 'ffmpeg', 'ffprobe']
54 prefer_ffmpeg = self._downloader.params.get('prefer_ffmpeg', False)
55
56 self.basename = None
57 self.probe_basename = None
58
59 self._paths = None
60 self._versions = None
61 if self._downloader:
62 location = self._downloader.params.get('ffmpeg_location')
63 if location is not None:
64 if not os.path.exists(location):
65 self._downloader.report_warning(
66 'ffmpeg-location %s does not exist! '
67 'Continuing without avconv/ffmpeg.' % (location))
68 self._versions = {}
69 return
70 elif not os.path.isdir(location):
71 basename = os.path.splitext(os.path.basename(location))[0]
72 if basename not in programs:
73 self._downloader.report_warning(
74 'Cannot identify executable %s, its basename should be one of %s. '
75 'Continuing without avconv/ffmpeg.' %
76 (location, ', '.join(programs)))
77 self._versions = {}
78 return None
79 location = os.path.dirname(os.path.abspath(location))
80 if basename in ('ffmpeg', 'ffprobe'):
81 prefer_ffmpeg = True
82
83 self._paths = dict(
84 (p, os.path.join(location, p)) for p in programs)
85 self._versions = dict(
86 (p, get_exe_version(self._paths[p], args=['-version']))
87 for p in programs)
88 if self._versions is None:
89 self._versions = dict(
90 (p, get_exe_version(p, args=['-version'])) for p in programs)
91 self._paths = dict((p, p) for p in programs)
92
93 if prefer_ffmpeg:
94 prefs = ('ffmpeg', 'avconv')
95 else:
96 prefs = ('avconv', 'ffmpeg')
97 for p in prefs:
98 if self._versions[p]:
99 self.basename = p
100 break
101
102 if prefer_ffmpeg:
103 prefs = ('ffprobe', 'avprobe')
104 else:
105 prefs = ('avprobe', 'ffprobe')
106 for p in prefs:
107 if self._versions[p]:
108 self.probe_basename = p
109 break
110
111 @property
112 def available(self):
113 return self.basename is not None
114
115 @property
116 def executable(self):
117 return self._paths[self.basename]
118
119 @property
120 def probe_available(self):
121 return self.probe_basename is not None
122
123 @property
124 def probe_executable(self):
125 return self._paths[self.probe_basename]
126
127 def run_ffmpeg_multiple_files(self, input_paths, out_path, opts):
128 self.check_version()
129
130 oldest_mtime = min(
131 os.stat(encodeFilename(path)).st_mtime for path in input_paths)
132
133 files_cmd = []
134 for path in input_paths:
135 files_cmd.extend([encodeArgument('-i'), encodeFilename(path, True)])
136 cmd = ([encodeFilename(self.executable, True), encodeArgument('-y')] +
137 files_cmd +
138 [encodeArgument(o) for o in opts] +
139 [encodeFilename(self._ffmpeg_filename_argument(out_path), True)])
140
141 if self._downloader.params.get('verbose', False):
142 self._downloader.to_screen('[debug] ffmpeg command line: %s' % shell_quote(cmd))
143 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
144 stdout, stderr = p.communicate()
145 if p.returncode != 0:
146 stderr = stderr.decode('utf-8', 'replace')
147 msg = stderr.strip().split('\n')[-1]
148 raise FFmpegPostProcessorError(msg)
149 self.try_utime(out_path, oldest_mtime, oldest_mtime)
150
151 def run_ffmpeg(self, path, out_path, opts):
152 self.run_ffmpeg_multiple_files([path], out_path, opts)
153
154 def _ffmpeg_filename_argument(self, fn):
155 # ffmpeg broke --, see https://ffmpeg.org/trac/ffmpeg/ticket/2127 for details
156 if fn.startswith('-'):
157 return './' + fn
158 return fn
159
160
161 class FFmpegExtractAudioPP(FFmpegPostProcessor):
162 def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, nopostoverwrites=False):
163 FFmpegPostProcessor.__init__(self, downloader)
164 if preferredcodec is None:
165 preferredcodec = 'best'
166 self._preferredcodec = preferredcodec
167 self._preferredquality = preferredquality
168 self._nopostoverwrites = nopostoverwrites
169
170 def get_audio_codec(self, path):
171
172 if not self.probe_available:
173 raise PostProcessingError('ffprobe or avprobe not found. Please install one.')
174 try:
175 cmd = [
176 encodeFilename(self.probe_executable, True),
177 encodeArgument('-show_streams'),
178 encodeFilename(self._ffmpeg_filename_argument(path), True)]
179 if self._downloader.params.get('verbose', False):
180 self._downloader.to_screen('[debug] %s command line: %s' % (self.basename, shell_quote(cmd)))
181 handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE, stdin=subprocess.PIPE)
182 output = handle.communicate()[0]
183 if handle.wait() != 0:
184 return None
185 except (IOError, OSError):
186 return None
187 audio_codec = None
188 for line in output.decode('ascii', 'ignore').split('\n'):
189 if line.startswith('codec_name='):
190 audio_codec = line.split('=')[1].strip()
191 elif line.strip() == 'codec_type=audio' and audio_codec is not None:
192 return audio_codec
193 return None
194
195 def run_ffmpeg(self, path, out_path, codec, more_opts):
196 if codec is None:
197 acodec_opts = []
198 else:
199 acodec_opts = ['-acodec', codec]
200 opts = ['-vn'] + acodec_opts + more_opts
201 try:
202 FFmpegPostProcessor.run_ffmpeg(self, path, out_path, opts)
203 except FFmpegPostProcessorError as err:
204 raise AudioConversionError(err.msg)
205
206 def run(self, information):
207 path = information['filepath']
208
209 filecodec = self.get_audio_codec(path)
210 if filecodec is None:
211 raise PostProcessingError('WARNING: unable to obtain file audio codec with ffprobe')
212
213 more_opts = []
214 if self._preferredcodec == 'best' or self._preferredcodec == filecodec or (self._preferredcodec == 'm4a' and filecodec == 'aac'):
215 if filecodec == 'aac' and self._preferredcodec in ['m4a', 'best']:
216 # Lossless, but in another container
217 acodec = 'copy'
218 extension = 'm4a'
219 more_opts = ['-bsf:a', 'aac_adtstoasc']
220 elif filecodec in ['aac', 'mp3', 'vorbis', 'opus']:
221 # Lossless if possible
222 acodec = 'copy'
223 extension = filecodec
224 if filecodec == 'aac':
225 more_opts = ['-f', 'adts']
226 if filecodec == 'vorbis':
227 extension = 'ogg'
228 else:
229 # MP3 otherwise.
230 acodec = 'libmp3lame'
231 extension = 'mp3'
232 more_opts = []
233 if self._preferredquality is not None:
234 if int(self._preferredquality) < 10:
235 more_opts += ['-q:a', self._preferredquality]
236 else:
237 more_opts += ['-b:a', self._preferredquality + 'k']
238 else:
239 # We convert the audio (lossy)
240 acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'opus': 'opus', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec]
241 extension = self._preferredcodec
242 more_opts = []
243 if self._preferredquality is not None:
244 # The opus codec doesn't support the -aq option
245 if int(self._preferredquality) < 10 and extension != 'opus':
246 more_opts += ['-q:a', self._preferredquality]
247 else:
248 more_opts += ['-b:a', self._preferredquality + 'k']
249 if self._preferredcodec == 'aac':
250 more_opts += ['-f', 'adts']
251 if self._preferredcodec == 'm4a':
252 more_opts += ['-bsf:a', 'aac_adtstoasc']
253 if self._preferredcodec == 'vorbis':
254 extension = 'ogg'
255 if self._preferredcodec == 'wav':
256 extension = 'wav'
257 more_opts += ['-f', 'wav']
258
259 prefix, sep, ext = path.rpartition('.') # not os.path.splitext, since the latter does not work on unicode in all setups
260 new_path = prefix + sep + extension
261
262 # If we download foo.mp3 and convert it to... foo.mp3, then don't delete foo.mp3, silly.
263 if (new_path == path or
264 (self._nopostoverwrites and os.path.exists(encodeFilename(new_path)))):
265 self._downloader.to_screen('[youtube] Post-process file %s exists, skipping' % new_path)
266 return [], information
267
268 try:
269 self._downloader.to_screen('[' + self.basename + '] Destination: ' + new_path)
270 self.run_ffmpeg(path, new_path, acodec, more_opts)
271 except AudioConversionError as e:
272 raise PostProcessingError(
273 'audio conversion failed: ' + e.msg)
274 except Exception:
275 raise PostProcessingError('error running ' + self.basename)
276
277 # Try to update the date time for extracted audio file.
278 if information.get('filetime') is not None:
279 self.try_utime(
280 new_path, time.time(), information['filetime'],
281 errnote='Cannot update utime of audio file')
282
283 information['filepath'] = new_path
284 information['ext'] = extension
285
286 return [path], information
287
288
289 class FFmpegVideoConvertorPP(FFmpegPostProcessor):
290 def __init__(self, downloader=None, preferedformat=None):
291 super(FFmpegVideoConvertorPP, self).__init__(downloader)
292 self._preferedformat = preferedformat
293
294 def run(self, information):
295 path = information['filepath']
296 prefix, sep, ext = path.rpartition('.')
297 outpath = prefix + sep + self._preferedformat
298 if information['ext'] == self._preferedformat:
299 self._downloader.to_screen('[ffmpeg] Not converting video file %s - already is in target format %s' % (path, self._preferedformat))
300 return [], information
301 self._downloader.to_screen('[' + 'ffmpeg' + '] Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + outpath)
302 self.run_ffmpeg(path, outpath, [])
303 information['filepath'] = outpath
304 information['format'] = self._preferedformat
305 information['ext'] = self._preferedformat
306 return [path], information
307
308
309 class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
310 # See http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
311 _lang_map = {
312 'aa': 'aar',
313 'ab': 'abk',
314 'ae': 'ave',
315 'af': 'afr',
316 'ak': 'aka',
317 'am': 'amh',
318 'an': 'arg',
319 'ar': 'ara',
320 'as': 'asm',
321 'av': 'ava',
322 'ay': 'aym',
323 'az': 'aze',
324 'ba': 'bak',
325 'be': 'bel',
326 'bg': 'bul',
327 'bh': 'bih',
328 'bi': 'bis',
329 'bm': 'bam',
330 'bn': 'ben',
331 'bo': 'bod',
332 'br': 'bre',
333 'bs': 'bos',
334 'ca': 'cat',
335 'ce': 'che',
336 'ch': 'cha',
337 'co': 'cos',
338 'cr': 'cre',
339 'cs': 'ces',
340 'cu': 'chu',
341 'cv': 'chv',
342 'cy': 'cym',
343 'da': 'dan',
344 'de': 'deu',
345 'dv': 'div',
346 'dz': 'dzo',
347 'ee': 'ewe',
348 'el': 'ell',
349 'en': 'eng',
350 'eo': 'epo',
351 'es': 'spa',
352 'et': 'est',
353 'eu': 'eus',
354 'fa': 'fas',
355 'ff': 'ful',
356 'fi': 'fin',
357 'fj': 'fij',
358 'fo': 'fao',
359 'fr': 'fra',
360 'fy': 'fry',
361 'ga': 'gle',
362 'gd': 'gla',
363 'gl': 'glg',
364 'gn': 'grn',
365 'gu': 'guj',
366 'gv': 'glv',
367 'ha': 'hau',
368 'he': 'heb',
369 'hi': 'hin',
370 'ho': 'hmo',
371 'hr': 'hrv',
372 'ht': 'hat',
373 'hu': 'hun',
374 'hy': 'hye',
375 'hz': 'her',
376 'ia': 'ina',
377 'id': 'ind',
378 'ie': 'ile',
379 'ig': 'ibo',
380 'ii': 'iii',
381 'ik': 'ipk',
382 'io': 'ido',
383 'is': 'isl',
384 'it': 'ita',
385 'iu': 'iku',
386 'ja': 'jpn',
387 'jv': 'jav',
388 'ka': 'kat',
389 'kg': 'kon',
390 'ki': 'kik',
391 'kj': 'kua',
392 'kk': 'kaz',
393 'kl': 'kal',
394 'km': 'khm',
395 'kn': 'kan',
396 'ko': 'kor',
397 'kr': 'kau',
398 'ks': 'kas',
399 'ku': 'kur',
400 'kv': 'kom',
401 'kw': 'cor',
402 'ky': 'kir',
403 'la': 'lat',
404 'lb': 'ltz',
405 'lg': 'lug',
406 'li': 'lim',
407 'ln': 'lin',
408 'lo': 'lao',
409 'lt': 'lit',
410 'lu': 'lub',
411 'lv': 'lav',
412 'mg': 'mlg',
413 'mh': 'mah',
414 'mi': 'mri',
415 'mk': 'mkd',
416 'ml': 'mal',
417 'mn': 'mon',
418 'mr': 'mar',
419 'ms': 'msa',
420 'mt': 'mlt',
421 'my': 'mya',
422 'na': 'nau',
423 'nb': 'nob',
424 'nd': 'nde',
425 'ne': 'nep',
426 'ng': 'ndo',
427 'nl': 'nld',
428 'nn': 'nno',
429 'no': 'nor',
430 'nr': 'nbl',
431 'nv': 'nav',
432 'ny': 'nya',
433 'oc': 'oci',
434 'oj': 'oji',
435 'om': 'orm',
436 'or': 'ori',
437 'os': 'oss',
438 'pa': 'pan',
439 'pi': 'pli',
440 'pl': 'pol',
441 'ps': 'pus',
442 'pt': 'por',
443 'qu': 'que',
444 'rm': 'roh',
445 'rn': 'run',
446 'ro': 'ron',
447 'ru': 'rus',
448 'rw': 'kin',
449 'sa': 'san',
450 'sc': 'srd',
451 'sd': 'snd',
452 'se': 'sme',
453 'sg': 'sag',
454 'si': 'sin',
455 'sk': 'slk',
456 'sl': 'slv',
457 'sm': 'smo',
458 'sn': 'sna',
459 'so': 'som',
460 'sq': 'sqi',
461 'sr': 'srp',
462 'ss': 'ssw',
463 'st': 'sot',
464 'su': 'sun',
465 'sv': 'swe',
466 'sw': 'swa',
467 'ta': 'tam',
468 'te': 'tel',
469 'tg': 'tgk',
470 'th': 'tha',
471 'ti': 'tir',
472 'tk': 'tuk',
473 'tl': 'tgl',
474 'tn': 'tsn',
475 'to': 'ton',
476 'tr': 'tur',
477 'ts': 'tso',
478 'tt': 'tat',
479 'tw': 'twi',
480 'ty': 'tah',
481 'ug': 'uig',
482 'uk': 'ukr',
483 'ur': 'urd',
484 'uz': 'uzb',
485 've': 'ven',
486 'vi': 'vie',
487 'vo': 'vol',
488 'wa': 'wln',
489 'wo': 'wol',
490 'xh': 'xho',
491 'yi': 'yid',
492 'yo': 'yor',
493 'za': 'zha',
494 'zh': 'zho',
495 'zu': 'zul',
496 }
497
498 @classmethod
499 def _conver_lang_code(cls, code):
500 """Convert language code from ISO 639-1 to ISO 639-2/T"""
501 return cls._lang_map.get(code[:2])
502
503 def run(self, information):
504 if information['ext'] not in ['mp4', 'mkv']:
505 self._downloader.to_screen('[ffmpeg] Subtitles can only be embedded in mp4 or mkv files')
506 return [], information
507 subtitles = information.get('requested_subtitles')
508 if not subtitles:
509 self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to embed')
510 return [], information
511
512 sub_langs = list(subtitles.keys())
513 filename = information['filepath']
514 sub_filenames = [subtitles_filename(filename, lang, sub_info['ext']) for lang, sub_info in subtitles.items()]
515 input_files = [filename] + sub_filenames
516
517 opts = [
518 '-map', '0',
519 '-c', 'copy',
520 # Don't copy the existing subtitles, we may be running the
521 # postprocessor a second time
522 '-map', '-0:s',
523 ]
524 if information['ext'] == 'mp4':
525 opts += ['-c:s', 'mov_text']
526 for (i, lang) in enumerate(sub_langs):
527 opts.extend(['-map', '%d:0' % (i + 1)])
528 lang_code = self._conver_lang_code(lang)
529 if lang_code is not None:
530 opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code])
531
532 temp_filename = prepend_extension(filename, 'temp')
533 self._downloader.to_screen('[ffmpeg] Embedding subtitles in \'%s\'' % filename)
534 self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
535 os.remove(encodeFilename(filename))
536 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
537
538 return sub_filenames, information
539
540
541 class FFmpegMetadataPP(FFmpegPostProcessor):
542 def run(self, info):
543 metadata = {}
544 if info.get('title') is not None:
545 metadata['title'] = info['title']
546 if info.get('upload_date') is not None:
547 metadata['date'] = info['upload_date']
548 if info.get('artist') is not None:
549 metadata['artist'] = info['artist']
550 elif info.get('uploader') is not None:
551 metadata['artist'] = info['uploader']
552 elif info.get('uploader_id') is not None:
553 metadata['artist'] = info['uploader_id']
554 if info.get('description') is not None:
555 metadata['description'] = info['description']
556 metadata['comment'] = info['description']
557 if info.get('webpage_url') is not None:
558 metadata['purl'] = info['webpage_url']
559 if info.get('album') is not None:
560 metadata['album'] = info['album']
561
562 if not metadata:
563 self._downloader.to_screen('[ffmpeg] There isn\'t any metadata to add')
564 return [], info
565
566 filename = info['filepath']
567 temp_filename = prepend_extension(filename, 'temp')
568
569 if info['ext'] == 'm4a':
570 options = ['-vn', '-acodec', 'copy']
571 else:
572 options = ['-c', 'copy']
573
574 for (name, value) in metadata.items():
575 options.extend(['-metadata', '%s=%s' % (name, value)])
576
577 self._downloader.to_screen('[ffmpeg] Adding metadata to \'%s\'' % filename)
578 self.run_ffmpeg(filename, temp_filename, options)
579 os.remove(encodeFilename(filename))
580 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
581 return [], info
582
583
584 class FFmpegMergerPP(FFmpegPostProcessor):
585 def run(self, info):
586 filename = info['filepath']
587 temp_filename = prepend_extension(filename, 'temp')
588 args = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0']
589 self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename)
590 self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
591 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
592 return info['__files_to_merge'], info
593
594 def can_merge(self):
595 # TODO: figure out merge-capable ffmpeg version
596 if self.basename != 'avconv':
597 return True
598
599 required_version = '10-0'
600 if is_outdated_version(
601 self._versions[self.basename], required_version):
602 warning = ('Your copy of %s is outdated and unable to properly mux separate video and audio files, '
603 'youtube-dl will download single file media. '
604 'Update %s to version %s or newer to fix this.') % (
605 self.basename, self.basename, required_version)
606 if self._downloader:
607 self._downloader.report_warning(warning)
608 return False
609 return True
610
611
612 class FFmpegFixupStretchedPP(FFmpegPostProcessor):
613 def run(self, info):
614 stretched_ratio = info.get('stretched_ratio')
615 if stretched_ratio is None or stretched_ratio == 1:
616 return [], info
617
618 filename = info['filepath']
619 temp_filename = prepend_extension(filename, 'temp')
620
621 options = ['-c', 'copy', '-aspect', '%f' % stretched_ratio]
622 self._downloader.to_screen('[ffmpeg] Fixing aspect ratio in "%s"' % filename)
623 self.run_ffmpeg(filename, temp_filename, options)
624
625 os.remove(encodeFilename(filename))
626 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
627
628 return [], info
629
630
631 class FFmpegFixupM4aPP(FFmpegPostProcessor):
632 def run(self, info):
633 if info.get('container') != 'm4a_dash':
634 return [], info
635
636 filename = info['filepath']
637 temp_filename = prepend_extension(filename, 'temp')
638
639 options = ['-c', 'copy', '-f', 'mp4']
640 self._downloader.to_screen('[ffmpeg] Correcting container in "%s"' % filename)
641 self.run_ffmpeg(filename, temp_filename, options)
642
643 os.remove(encodeFilename(filename))
644 os.rename(encodeFilename(temp_filename), encodeFilename(filename))
645
646 return [], info
647
648
649 class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
650 def __init__(self, downloader=None, format=None):
651 super(FFmpegSubtitlesConvertorPP, self).__init__(downloader)
652 self.format = format
653
654 def run(self, info):
655 subs = info.get('requested_subtitles')
656 filename = info['filepath']
657 new_ext = self.format
658 new_format = new_ext
659 if new_format == 'vtt':
660 new_format = 'webvtt'
661 if subs is None:
662 self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to convert')
663 return [], info
664 self._downloader.to_screen('[ffmpeg] Converting subtitles')
665 for lang, sub in subs.items():
666 ext = sub['ext']
667 if ext == new_ext:
668 self._downloader.to_screen(
669 '[ffmpeg] Subtitle file for %s is already in the requested'
670 'format' % new_ext)
671 continue
672 new_file = subtitles_filename(filename, lang, new_ext)
673
674 if ext == 'dfxp' or ext == 'ttml':
675 self._downloader.report_warning(
676 'You have requested to convert dfxp (TTML) subtitles into another format, '
677 'which results in style information loss')
678
679 dfxp_file = subtitles_filename(filename, lang, ext)
680 srt_file = subtitles_filename(filename, lang, 'srt')
681
682 with io.open(dfxp_file, 'rt', encoding='utf-8') as f:
683 srt_data = dfxp2srt(f.read())
684
685 with io.open(srt_file, 'wt', encoding='utf-8') as f:
686 f.write(srt_data)
687
688 ext = 'srt'
689 subs[lang] = {
690 'ext': 'srt',
691 'data': srt_data
692 }
693
694 if new_ext == 'srt':
695 continue
696
697 self.run_ffmpeg(
698 subtitles_filename(filename, lang, ext),
699 new_file, ['-f', new_format])
700
701 with io.open(new_file, 'rt', encoding='utf-8') as f:
702 subs[lang] = {
703 'ext': ext,
704 'data': f.read(),
705 }
706
707 return [], info