This commit is contained in:
Oliver Hattshire 2020-09-24 08:02:47 +00:00 committed by GitHub
commit 884e00b110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -289,7 +289,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

View File

@ -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,

View File

@ -23,9 +23,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']
@ -75,8 +76,17 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
thumbnail_filename = thumbnail_jpg_filename
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)