From 004aefdeca14e21f286ec7bd267642c5551636c8 Mon Sep 17 00:00:00 2001 From: Christophe-Marie Duquesne Date: Thu, 18 Jul 2013 14:14:39 +0200 Subject: [PATCH] Make the video encoding user configurable --- sigal/gallery.py | 3 ++- sigal/settings.py | 1 + sigal/templates/sigal.conf.py | 12 +++++++++++- sigal/video.py | 12 ++++++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sigal/gallery.py b/sigal/gallery.py index e7cd5ce..ec85a40 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -291,7 +291,8 @@ def process_video(filepath, outpath, settings): shutil.copy(filepath, join(outpath, settings['orig_dir'], filename)) # TODO: Add specific video size settings - sigal.video.generate_video(filepath, outname, settings['img_size']) + sigal.video.generate_video(filepath, outname, settings['img_size'], + settings['webm_options']) if settings['make_thumbs']: thumb_name = join(outpath, get_thumb(settings, filename)) diff --git a/sigal/settings.py b/sigal/settings.py index cf5598d..05a7294 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -37,6 +37,7 @@ _DEFAULT_CONFIG = { 'keep_orig': False, 'orig_dir': 'original', 'jpg_options': {'quality': 85, 'optimize': True, 'progressive': True}, + 'webm_options': {'crf': '10', 'bitrate': '1.6M', 'qmin': '4', 'qmax': '63'}, 'copyright': '', 'img_ext_list': ['.jpg', '.jpeg', '.JPG', '.JPEG', '.png'], 'vid_ext_list': ['.MOV', '.mov', '.avi', '.mp4', '.webm', '.ogv'], diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 1c6b50d..841bd2c 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -16,7 +16,7 @@ source = 'pictures' # - colorbox (default), galleria, or the path to a custom theme directory theme = 'galleria' -# Size of resized image +# Size of resized image (default: (640, 480)) img_size = (800, 600) # Pilkit processor used to resize the image @@ -55,6 +55,16 @@ thumb_size = (280, 210) # 'optimize': True, # 'progressive': True} +# Webm options +# Options used in ffmpeg to encode the webm video. You may want to read +# http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide +# Be aware of the fact these options need to be passed as strings. +# webm_options = {'crf': '10', +# 'bitrate': '1.6M', +# 'qmin': '4', +# 'qmax': '63'} + + # Write HTML files. If False, sigal will only process the images. # write_html = True diff --git a/sigal/video.py b/sigal/video.py index e0a807b..aff4383 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -25,7 +25,7 @@ import subprocess import os import sigal.image -def generate_video(source, outname, size, options=[]): +def generate_video(source, outname, size, options={}): """Video processor :param source: path to an image @@ -42,9 +42,13 @@ def generate_video(source, outname, size, options=[]): # http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide (w, h) = size with open("/dev/null") as devnull: - subprocess.call(['ffmpeg', '-i', source, '-y', '-crf', '10', - '-b:v', '1.6M','-vf', "scale=%i:trunc(ow/a/2)*2'" % w] + - options + [outname], stderr=devnull) + subprocess.call(['ffmpeg', '-i', source, '-y', + '-crf', options.get('crf', '10'), + '-b:v', options.get('bitrate', '1.6M'), + '-qmin', options.get('qmin', '4'), + '-qmax',options.get('qmax', '63'), + '-vf', "scale=%i:trunc(ow/a/2)*2'" % w, + outname], stderr=devnull) def generate_thumbnail(source, outname, box, format, fit=True, options=None): "Create a thumbnail image"