1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

[PostProcessing] Crop mp3 thumbnails

This commit is contained in:
Hattshire 2019-02-26 23:41:58 -03:00
parent 55b8588f0e
commit af03a4e5f5
3 changed files with 19 additions and 4 deletions

View File

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

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

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