diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ba435ea42..cc70d82cd 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -287,7 +287,8 @@ def _real_main(argv=None): already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails postprocessors.append({ 'key': 'EmbedThumbnail', - 'already_have_thumbnail': already_have_thumbnail + 'already_have_thumbnail': already_have_thumbnail, + 'crop_thumbnail': opts.cropthumbnail, }) if not already_have_thumbnail: opts.writethumbnail = True diff --git a/youtube_dl/options.py b/youtube_dl/options.py index e7d8e8910..5348e7dca 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -814,6 +814,10 @@ def parseOpts(overrideArguments=None): '--embed-thumbnail', action='store_true', dest='embedthumbnail', default=False, help='Embed thumbnail in the audio as cover art') + postproc.add_option( + '--crop-thumbnail', + action='store_true', dest='cropthumbnail', default=False, + help='Crop the thumbnail to an square; No effect without --embed-thumbnail') postproc.add_option( '--add-metadata', action='store_true', dest='addmetadata', default=False, diff --git a/youtube_dl/postprocessor/embedthumbnail.py b/youtube_dl/postprocessor/embedthumbnail.py index 56be914b8..fd2bc66f6 100644 --- a/youtube_dl/postprocessor/embedthumbnail.py +++ b/youtube_dl/postprocessor/embedthumbnail.py @@ -22,9 +22,10 @@ class EmbedThumbnailPPError(PostProcessingError): class EmbedThumbnailPP(FFmpegPostProcessor): - def __init__(self, downloader=None, already_have_thumbnail=False): + def __init__(self, downloader=None, already_have_thumbnail=False, crop_thumbnail=False): super(EmbedThumbnailPP, self).__init__(downloader) self._already_have_thumbnail = already_have_thumbnail + self._crop_thumbnail = crop_thumbnail def run(self, info): filename = info['filepath'] @@ -42,8 +43,17 @@ class EmbedThumbnailPP(FFmpegPostProcessor): return [], info if info['ext'] == 'mp3': - options = [ - '-c', 'copy', '-map', '0', '-map', '1', + options = [] + if self._crop_thumbnail: + options.append( + '-c:a', 'copy', '-c:v', 'mjpeg', # Copy audio stream, re-encode resulting thumb + '-vf', 'crop="\'if(gt(ih,iw),iw,ih)\':\'if(gt(iw,ih),ih,iw)\'"' # Use the crop filter on the image + ) + else: + options.append('-c', 'copy') # Copy both streams instead + + options += [ + '-map', '0', '-map', '1', '-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment="Cover (Front)"'] self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)