From 01d442d3ef234d8aa23f4ea7f9f6333f67714ba0 Mon Sep 17 00:00:00 2001 From: Miroslav Pavleski Date: Sun, 24 May 2015 15:50:30 +0200 Subject: [PATCH] added support for mp4, manually tested, mp4 files transcoded and links correctly populated in html --- sigal/gallery.py | 10 +++++++--- sigal/plugins/upload_s3.py | 2 +- sigal/settings.py | 2 ++ sigal/video.py | 10 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index 62e2689..9eef6c8 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -181,9 +181,13 @@ class Video(Media): self.date = None self.src_filename = filename if not settings['use_orig'] or not is_valid_html5_video(ext): - self.filename = self.url = base + '.webm' - self.mime = get_mime('.webm') - self.dst_path = join(settings['destination'], path, base + '.webm') + video_format = settings['video_format'] + + ext = '.' + video_format + + self.filename = self.url = base + ext + self.mime = get_mime(ext) + self.dst_path = join(settings['destination'], path, base + ext) else: self.mime = get_mime(ext) diff --git a/sigal/plugins/upload_s3.py b/sigal/plugins/upload_s3.py index 3025f0c..0594ab0 100644 --- a/sigal/plugins/upload_s3.py +++ b/sigal/plugins/upload_s3.py @@ -72,7 +72,7 @@ def generate_cache_metadata(gallery, f): proposed_cache_control = None if 'media_max_age' in gallery.settings['upload_s3_options'] and \ - file_extension in ['.jpg','.png','.webm']: + file_extension in ['.jpg','.png','.webm','.mp4']: proposed_cache_control = "max-age=%s" % \ gallery.settings['upload_s3_options']['media_max_age'] elif 'max_age' in gallery.settings['upload_s3_options']: diff --git a/sigal/settings.py b/sigal/settings.py index e6518cc..cf0fc72 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -67,8 +67,10 @@ _DEFAULT_CONFIG = { 'use_orig': False, 'video_size': (480, 360), 'watermark': '', + 'video_format': 'webm', 'webm_options': ['-crf', '10', '-b:v', '1.6M', '-qmin', '4', '-qmax', '63'], + 'mp4_options': ['-crf', '23' ], 'write_html': True, 'zip_gallery': False, 'zip_media_format': 'resized', diff --git a/sigal/video.py b/sigal/video.py index 0d7aed3..aed6514 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -156,9 +156,15 @@ def process_video(filepath, outpath, settings): outname = os.path.join(outpath, filename) utils.copy(filepath, outname, symlink=settings['orig_link']) else: - outname = os.path.join(outpath, basename + '.webm') + valid_formats = ['mp4', 'webm'] + video_format = settings['video_format'] + + if video_format not in valid_formats: + raise ValueError('Invalid video_format. Please choose one of: ' + str(valid_formats)) + + outname = os.path.join(outpath, basename + '.' + video_format) generate_video(filepath, outname, settings, - options=settings['webm_options']) + options=settings[video_format + '_options']) except Exception: return Status.FAILURE