]> jfr.im git - yt-dlp.git/commitdiff
[FixupM3u8] Fixup MPEG-TS in MP4 container
authorpukkandan <redacted>
Sat, 27 Nov 2021 13:50:39 +0000 (19:20 +0530)
committerpukkandan <redacted>
Sat, 27 Nov 2021 13:51:47 +0000 (19:21 +0530)
Closes #1701, https://github.com/ytdl-org/youtube-dl/issues/26410

yt_dlp/YoutubeDL.py
yt_dlp/postprocessor/ffmpeg.py

index b983b17752687031c6ab3c288f872c6a76f1a5d3..3a409b652391be6fbbf76439640a6cad7c36ffed 100644 (file)
@@ -2934,9 +2934,10 @@ def ffmpeg_fixup(cndn, msg, cls):
                     downloader = get_suitable_downloader(info_dict, self.params) if 'protocol' in info_dict else None
                     downloader = downloader.__name__ if downloader else None
                     ffmpeg_fixup(info_dict.get('requested_formats') is None and downloader == 'HlsFD',
-                                 'malformed AAC bitstream detected', FFmpegFixupM3u8PP)
-                    ffmpeg_fixup(downloader == 'WebSocketFragmentFD', 'malformed timestamps detected', FFmpegFixupTimestampPP)
-                    ffmpeg_fixup(downloader == 'WebSocketFragmentFD', 'malformed duration detected', FFmpegFixupDurationPP)
+                                 'Possible MPEG-TS in MP4 container or malformed AAC timestamps',
+                                 FFmpegFixupM3u8PP)
+                    ffmpeg_fixup(downloader == 'WebSocketFragmentFD', 'Malformed timestamps detected', FFmpegFixupTimestampPP)
+                    ffmpeg_fixup(downloader == 'WebSocketFragmentFD', 'Malformed duration detected', FFmpegFixupDurationPP)
 
                 fixup()
                 try:
index 1bde170ce62fd14b7596879abefffda4618dd43b..e8b569d72887164242f378cb356611dce2f66254 100644 (file)
@@ -855,10 +855,21 @@ def run(self, info):
 
 
 class FFmpegFixupM3u8PP(FFmpegFixupPostProcessor):
+    def _needs_fixup(self, info):
+        yield info['ext'] in ('mp4', 'm4a')
+        yield info['protocol'].startswith('m3u8')
+        try:
+            metadata = self.get_metadata_object(info['filepath'])
+        except PostProcessingError as e:
+            self.report_warning(f'Unable to extract metadata: {e.msg}')
+            yield True
+        else:
+            yield traverse_obj(metadata, ('format', 'format_name'), casesense=False) == 'mpegts'
+
     @PostProcessor._restrict_to(images=False)
     def run(self, info):
-        if self.get_audio_codec(info['filepath']) == 'aac':
-            self._fixup('Fixing malformed AAC bitstream', info['filepath'], [
+        if all(self._needs_fixup(info)):
+            self._fixup('Fixing MPEG-TS in MP4 container', info['filepath'], [
                 '-c', 'copy', '-map', '0', '-dn', '-f', 'mp4', '-bsf:a', 'aac_adtstoasc'])
         return [], info