mirror of
https://github.com/l1ving/youtube-dl
synced 2020-11-18 19:53:54 -08:00
[PostProcessing] Crop mp3 thumbnails
This commit is contained in:
parent
55b8588f0e
commit
af03a4e5f5
@ -287,7 +287,8 @@ def _real_main(argv=None):
|
|||||||
already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
|
already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
|
||||||
postprocessors.append({
|
postprocessors.append({
|
||||||
'key': 'EmbedThumbnail',
|
'key': 'EmbedThumbnail',
|
||||||
'already_have_thumbnail': already_have_thumbnail
|
'already_have_thumbnail': already_have_thumbnail,
|
||||||
|
'crop_thumbnail': opts.cropthumbnail,
|
||||||
})
|
})
|
||||||
if not already_have_thumbnail:
|
if not already_have_thumbnail:
|
||||||
opts.writethumbnail = True
|
opts.writethumbnail = True
|
||||||
|
@ -814,6 +814,10 @@ def parseOpts(overrideArguments=None):
|
|||||||
'--embed-thumbnail',
|
'--embed-thumbnail',
|
||||||
action='store_true', dest='embedthumbnail', default=False,
|
action='store_true', dest='embedthumbnail', default=False,
|
||||||
help='Embed thumbnail in the audio as cover art')
|
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(
|
postproc.add_option(
|
||||||
'--add-metadata',
|
'--add-metadata',
|
||||||
action='store_true', dest='addmetadata', default=False,
|
action='store_true', dest='addmetadata', default=False,
|
||||||
|
@ -22,9 +22,10 @@ class EmbedThumbnailPPError(PostProcessingError):
|
|||||||
|
|
||||||
|
|
||||||
class EmbedThumbnailPP(FFmpegPostProcessor):
|
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)
|
super(EmbedThumbnailPP, self).__init__(downloader)
|
||||||
self._already_have_thumbnail = already_have_thumbnail
|
self._already_have_thumbnail = already_have_thumbnail
|
||||||
|
self._crop_thumbnail = crop_thumbnail
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
filename = info['filepath']
|
filename = info['filepath']
|
||||||
@ -42,8 +43,17 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
return [], info
|
return [], info
|
||||||
|
|
||||||
if info['ext'] == 'mp3':
|
if info['ext'] == 'mp3':
|
||||||
options = [
|
options = []
|
||||||
'-c', 'copy', '-map', '0', '-map', '1',
|
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)"']
|
'-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment="Cover (Front)"']
|
||||||
|
|
||||||
self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)
|
self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user