diff --git a/sigal/gallery.py b/sigal/gallery.py index da9fecc..dc5e7f0 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -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) diff --git a/sigal/image.py b/sigal/image.py index e7a7962..0450ded 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -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 diff --git a/sigal/settings.py b/sigal/settings.py index 2272743..f47cf8b 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -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), diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 5188ed7..752e5b1 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -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 # ------------- diff --git a/sigal/video.py b/sigal/video.py index 83f1014..8d827eb 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -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 diff --git a/tests/test_image.py b/tests/test_image.py index 5d3a488..b6c27b2 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -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