[ffmpeg] convert format ext to ffmpeg output formats codes
[youtube-dl] / youtube_dl / postprocessor / ffmpeg.py
index 7e85a702d22180c015c768f563f41d498419d629..cc7aaeda397ba8b5dd368c770e39a7a4c34f4719 100644 (file)
@@ -25,6 +25,19 @@ from ..utils import (
 )
 
 
+EXT_TO_OUT_FORMATS = {
+    "aac": "adts",
+    "m4a": "ipod",
+    "mka": "matroska",
+    "mkv": "matroska",
+    "mpg": "mpeg",
+    "ogv": "ogg",
+    "ts": "mpegts",
+    "wma": "asf",
+    "wmv": "asf",
+}
+
+
 class FFmpegPostProcessorError(PostProcessingError):
     pass
 
@@ -392,7 +405,7 @@ class FFmpegMetadataPP(FFmpegPostProcessor):
             options.extend(['-metadata', '%s=%s' % (name, value)])
 
         # https://github.com/rg3/youtube-dl/issues/8350
-        if info.get('protocol') == 'm3u8_native' or self._downloader.params.get('hls_prefer_native', False):
+        if info.get('protocol') == 'm3u8_native' or info.get('protocol') == 'm3u8' and self._downloader.params.get('hls_prefer_native', False):
             options.extend(['-bsf:a', 'aac_adtstoasc'])
 
         self._downloader.to_screen('[ffmpeg] Adding metadata to \'%s\'' % filename)
@@ -508,8 +521,8 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
 
                 with io.open(srt_file, 'wt', encoding='utf-8') as f:
                     f.write(srt_data)
+                old_file = srt_file
 
-                ext = 'srt'
                 subs[lang] = {
                     'ext': 'srt',
                     'data': srt_data
@@ -517,12 +530,14 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
 
                 if new_ext == 'srt':
                     continue
+                else:
+                    sub_filenames.append(srt_file)
 
             self.run_ffmpeg(old_file, new_file, ['-f', new_format])
 
             with io.open(new_file, 'rt', encoding='utf-8') as f:
                 subs[lang] = {
-                    'ext': ext,
+                    'ext': new_ext,
                     'data': f.read(),
                 }