Merge pull request #143 from jdn06/thumb-videos
Avoid black thumbnails with fade-in videos
This commit is contained in:
@@ -122,6 +122,7 @@ class Media(UnicodeMixin):
|
||||
try:
|
||||
generator(self.src_path, self.thumb_path,
|
||||
self.settings['thumb_size'],
|
||||
self.settings['thumb_video_delay'],
|
||||
fit=self.settings['thumb_fit'])
|
||||
except Exception as e:
|
||||
self.logger.error('Failed to generate thumbnail: %s', e)
|
||||
|
||||
@@ -112,7 +112,7 @@ def generate_image(source, outname, settings, options=None):
|
||||
save_image(img, outname, outformat, options=options, autoconvert=True)
|
||||
|
||||
|
||||
def generate_thumbnail(source, outname, box, fit=True, options=None):
|
||||
def generate_thumbnail(source, outname, box, delay, fit=True, options=None):
|
||||
"""Create a thumbnail image."""
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -151,7 +151,8 @@ def process_image(filepath, outpath, settings):
|
||||
if settings['make_thumbs']:
|
||||
thumb_name = os.path.join(outpath, get_thumb(settings, filename))
|
||||
generate_thumbnail(outname, thumb_name, settings['thumb_size'],
|
||||
fit=settings['thumb_fit'], options=options)
|
||||
settings['thumb_video_delay'], fit=settings['thumb_fit'],
|
||||
options=options)
|
||||
except Exception as e:
|
||||
logger.info('Failed to process: %r', e)
|
||||
return Status.FAILURE
|
||||
|
||||
@@ -62,6 +62,7 @@ _DEFAULT_CONFIG = {
|
||||
'thumb_prefix': '',
|
||||
'thumb_size': (200, 150),
|
||||
'thumb_suffix': '',
|
||||
'thumb_video_delay': '0',
|
||||
'title': '',
|
||||
'use_orig': False,
|
||||
'video_size': (480, 360),
|
||||
|
||||
@@ -80,6 +80,9 @@ thumb_size = (280, 210)
|
||||
# Crop the image to fill the box
|
||||
# thumb_fit = True
|
||||
|
||||
# Delay in seconds to avoid black thumbnails in videos with fade-in
|
||||
# thumb_video_delay = '0'
|
||||
|
||||
# -------------
|
||||
# Album options
|
||||
# -------------
|
||||
|
||||
@@ -123,7 +123,7 @@ def generate_video(source, outname, size, options=None):
|
||||
check_subprocess(cmd, source, outname)
|
||||
|
||||
|
||||
def generate_thumbnail(source, outname, box, fit=True, options=None):
|
||||
def generate_thumbnail(source, outname, box, delay, fit=True, options=None):
|
||||
"""Create a thumbnail image for the video source, based on ffmpeg."""
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -131,7 +131,7 @@ def generate_thumbnail(source, outname, box, fit=True, options=None):
|
||||
|
||||
# dump an image of the video
|
||||
cmd = ['ffmpeg', '-i', source, '-an', '-r', '1',
|
||||
'-vframes', '1', '-y', tmpfile]
|
||||
'-ss', delay, '-vframes', '1', '-y', tmpfile]
|
||||
logger.debug('Create thumbnail for video: %s', ' '.join(cmd))
|
||||
|
||||
try:
|
||||
@@ -162,7 +162,7 @@ def process_video(filepath, outpath, settings):
|
||||
thumb_name = os.path.join(outpath, get_thumb(settings, filename))
|
||||
try:
|
||||
generate_thumbnail(
|
||||
outname, thumb_name, settings['thumb_size'],
|
||||
outname, thumb_name, settings['thumb_size'], settings['thumb_video_delay'],
|
||||
fit=settings['thumb_fit'], options=settings['jpg_options'])
|
||||
except Exception:
|
||||
return Status.FAILURE
|
||||
|
||||
@@ -65,14 +65,15 @@ def test_generate_thumbnail(tmpdir):
|
||||
"Test the generate_thumbnail function."
|
||||
|
||||
dstfile = str(tmpdir.join(TEST_IMAGE))
|
||||
delay = 0
|
||||
for size in [(200, 150), (150, 200)]:
|
||||
generate_thumbnail(SRCFILE, dstfile, size)
|
||||
generate_thumbnail(SRCFILE, dstfile, size, delay)
|
||||
im = Image.open(dstfile)
|
||||
assert im.size == size
|
||||
|
||||
for size, thumb_size in [((200, 150), (185, 150)),
|
||||
((150, 200), (150, 122))]:
|
||||
generate_thumbnail(SRCFILE, dstfile, size, fit=False)
|
||||
generate_thumbnail(SRCFILE, dstfile, size, delay, fit=False)
|
||||
im = Image.open(dstfile)
|
||||
assert im.size == thumb_size
|
||||
|
||||
|
||||
Reference in New Issue
Block a user