From c5fb2645ff3fbc163f949f61b1959ba73b13e9c7 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 14 Nov 2017 16:02:48 +0100 Subject: [PATCH] Allow to configure the ffmpeg binary Can be 'avconv' in certain distributions. --- sigal/templates/sigal.conf.py | 3 +++ sigal/video.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sigal/templates/sigal.conf.py b/sigal/templates/sigal.conf.py index 3b743aa..8fe1889 100644 --- a/sigal/templates/sigal.conf.py +++ b/sigal/templates/sigal.conf.py @@ -143,6 +143,9 @@ ignore_files = [] # Video options # ------------- +# Video converter binary (can be 'avconv' on certain GNU/Linux distributions) +# video_converter = 'ffmpeg' + # File extensions that should be treated as video files # video_extensions = ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp'] diff --git a/sigal/video.py b/sigal/video.py index 90d803f..8466bc5 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -61,10 +61,14 @@ def check_subprocess(cmd, source, outname): raise SubprocessException('Failed to process ' + source) -def video_size(source): - """Returns the dimensions of the video.""" +def video_size(source, settings={}): + """Returns the dimensions of the video. + :param source: path to a video + :param settings: settings dict + """ - ret, stdout, stderr = call_subprocess(['ffmpeg', '-i', source]) + converter = settings.get('video_converter', 'ffmpeg') + ret, stdout, stderr = call_subprocess([converter, '-i', source]) pattern = re.compile(r'Stream.*Video.* ([0-9]+)x([0-9]+)') match = pattern.search(stderr) rot_pattern = re.compile(r'rotate\s*:\s*-?(90|270)') @@ -92,7 +96,7 @@ def generate_video(source, outname, settings, options=None): # Don't transcode if source is in the required format and # has fitting datedimensions, copy instead. - w_src, h_src = video_size(source) + w_src, h_src = video_size(source, settings) w_dst, h_dst = settings['video_size'] logger.debug('Video size: %i, %i -> %i, %i', w_src, h_src, w_dst, h_dst) @@ -118,7 +122,8 @@ def generate_video(source, outname, settings, options=None): # Encoding options improved, thanks to # http://ffmpeg.org/trac/ffmpeg/wiki/vpxEncodingGuide - cmd = ['ffmpeg', '-i', source, '-y'] # -y to overwrite output files + converter = settings.get('video_converter', 'ffmpeg') + cmd = [converter, '-i', source, '-y'] # -y to overwrite output files if options is not None: cmd += options cmd += resize_opt + [outname] @@ -134,7 +139,8 @@ def generate_thumbnail(source, outname, box, delay, fit=True, options=None): tmpfile = outname + ".tmp.jpg" # dump an image of the video - cmd = ['ffmpeg', '-i', source, '-an', '-r', '1', + converter = settings.get('video_converter', 'ffmpeg') + cmd = [converter, '-i', source, '-an', '-r', '1', '-ss', delay, '-vframes', '1', '-y', tmpfile] logger.debug('Create thumbnail for video: %s', ' '.join(cmd)) check_subprocess(cmd, source, outname)