From 56e9fda73a32e9e74893d037d4360774934057ff Mon Sep 17 00:00:00 2001 From: kikuyan Date: Tue, 20 Jul 2021 08:42:44 +0900 Subject: [PATCH] [embedthumbnail] use ffmpeg to m4a/mp4 if version >= 4.0 --- youtube_dl/postprocessor/embedthumbnail.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/youtube_dl/postprocessor/embedthumbnail.py b/youtube_dl/postprocessor/embedthumbnail.py index 3990908b6..a4b981ee4 100644 --- a/youtube_dl/postprocessor/embedthumbnail.py +++ b/youtube_dl/postprocessor/embedthumbnail.py @@ -11,6 +11,7 @@ from ..utils import ( check_executable, encodeArgument, encodeFilename, + is_outdated_version, PostProcessingError, prepend_extension, replace_extension, @@ -89,6 +90,28 @@ class EmbedThumbnailPP(FFmpegPostProcessor): os.rename(encodeFilename(temp_filename), encodeFilename(filename)) elif info['ext'] in ['m4a', 'mp4']: + # use ffmpeg if the version supports embedding thumbnails + if self.basename == 'ffmpeg' and not is_outdated_version(self._lavf_version.get('build'), '58.12.100', False): # ffmpeg >= 4.0 + if info['ext'] == 'm4a': + disposition = 0 + else: + disposition = 1 + options = [ + '-c', 'copy', '-map', '0', '-map', '1', + '-disposition:v:%s' % disposition, + 'attached_pic' + ] + self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename) + + self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options) + + if not self._already_have_thumbnail: + os.remove(encodeFilename(thumbnail_filename)) + os.remove(encodeFilename(filename)) + os.rename(encodeFilename(temp_filename), encodeFilename(filename)) + + return [], info + atomicparsley = next((x for x in ['AtomicParsley', 'atomicparsley'] if check_executable(x, ['-v'])), None)