From efcd60416cda2e6a913d933266e499f99cb5be11 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Thu, 26 Dec 2013 16:43:47 +0100 Subject: [PATCH] webm_options is now a list with ffmpeg options (ref #53). To allow better flexibility and compatibility with avconv. --- sigal/settings.py | 4 ++-- sigal/templates/sigal.conf.py | 6 ++---- sigal/video.py | 27 ++++++++++++++++----------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/sigal/settings.py b/sigal/settings.py index 30a500c..2373a8b 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -52,8 +52,8 @@ _DEFAULT_CONFIG = { 'thumb_suffix': '', 'vid_ext_list': ['.MOV', '.mov', '.avi', '.mp4', '.webm', '.ogv'], 'video_size': (480, 360), - 'webm_options': {'crf': '10', 'bitrate': '1.6M', - 'qmin': '4', 'qmax': '63'}, + 'webm_options': ['-crf', '10', '-b:v', '1.6M', + '-qmin', '4', '-qmax', '63'], 'write_html': True, 'zip_gallery': False, } diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 5673f3c..25ef396 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -70,10 +70,8 @@ thumb_size = (280, 210) # 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'} +# webm_options = ['-crf', '10', '-b:v', '1.6M', +# '-qmin', '4', '-qmax', '63'], # Size of resized video (default: (480, 360)) # video_size = (480, 360) diff --git a/sigal/video.py b/sigal/video.py index f217b9a..4f2a415 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -1,6 +1,7 @@ # -*- coding:utf-8 -*- # Copyright (c) 2013 - Christophe-Marie Duquesne +# Copyright (c) 2013 - Simon Conseil # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to @@ -21,17 +22,19 @@ # IN THE SOFTWARE. from __future__ import with_statement -import subprocess + +import logging import os import re import shutil +import subprocess from . import compat, image from .settings import get_thumb def video_size(source): - """Returns the dimensions of the video""" + """Returns the dimensions of the video.""" pattern = re.compile(r'Stream.*Video.* ([0-9]+)x([0-9]+)') p = subprocess.Popen(['ffmpeg', '-i', source], stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -48,7 +51,7 @@ def video_size(source): return x, y -def generate_video(source, outname, size, options={}): +def generate_video(source, outname, size, options=None): """Video processor :param source: path to a video @@ -56,6 +59,8 @@ def generate_video(source, outname, size, options={}): :param options: array of options passed to ffmpeg """ + logger = logging.getLogger(__name__) + # Don't transcode if source is in the required format and # has fitting datedimensions, copy instead. w_src, h_src = video_size(source) @@ -81,14 +86,14 @@ def generate_video(source, outname, size, options={}): # Encoding options improved, thanks to # http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide + cmd = ['ffmpeg', '-i', source, '-y'] # overwrite output files + if options is not None: + cmd += options + cmd += resize_opt + [outname] + + logger.debug('Processing video: %s', ' '.join(cmd)) with open("/dev/null") as 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')] + - resize_opt + [outname], - stderr=devnull) + subprocess.call(cmd, stderr=devnull) def generate_thumbnail(source, outname, box, fit=True, options=None): @@ -112,7 +117,7 @@ def process_video(filepath, outpath, settings): outname = os.path.join(outpath, base + '.webm') generate_video(filepath, outname, settings['video_size'], - settings['webm_options']) + options=settings['webm_options']) if settings['make_thumbs']: thumb_name = os.path.join(outpath, get_thumb(settings, filename))