Correct size on videos; Got the video centered in galleria.

This commit is contained in:
Christophe-Marie Duquesne
2013-07-17 11:37:54 +02:00
parent 6df0f58a88
commit 96539dc3cc
5 changed files with 52 additions and 24 deletions

View File

@@ -103,11 +103,11 @@ class PathsDb(object):
self.db[relpath].update(get_metadata(path))
path_media = [path for path in self.db['paths_list']
if (self.db[path]['img'] or self.db[path]['vid']) and
path != '.']
path_nomedia = [path for path in self.db['paths_list'] if not
(self.db[path]['img'] or self.db[path]['vid']) and path !=
'.']
if (self.db[path]['img'] or self.db[path]['vid'])
and path != '.']
path_nomedia = [path for path in self.db['paths_list']
if not (self.db[path]['img'] or self.db[path]['vid'])
and path !='.']
# dir with images: check the thumbnail, and find it if necessary
for path in path_media:
@@ -264,14 +264,15 @@ def process_image(filepath, outpath, settings):
if settings['keep_orig']:
shutil.copy(filepath, join(outpath, settings['orig_dir'], filename))
sigal.image.generate_image(filepath, outname, settings['img_size'], None,
options=options, copyright_text=settings['copyright'],
method=settings['img_processor'])
sigal.image.generate_image(filepath, outname, settings['img_size'],
None, options=options, copyright_text=settings['copyright'],
method=settings['img_processor'])
if settings['make_thumbs']:
thumb_name = join(outpath, get_thumb(settings, filename))
sigal.image.generate_thumbnail(outname, thumb_name, settings['thumb_size'], None,
fit=settings['thumb_fit'], options=options)
sigal.image.generate_thumbnail(outname, thumb_name,
settings['thumb_size'], None, fit=settings['thumb_fit'],
options=options)
def process_video(filepath, outpath, settings):
"""Process one image: resize, create thumbnail."""
@@ -283,11 +284,13 @@ def process_video(filepath, outpath, settings):
if settings['keep_orig']:
shutil.copy(filepath, join(outpath, settings['orig_dir'], filename))
sigal.video.generate_video(filepath, outname)
# TODO: Add specific video size settings
sigal.video.generate_video(filepath, outname, settings['img_size'])
if settings['make_thumbs']:
thumb_name = join(outpath, get_thumb(settings, base + '.jpg'))
sigal.video.generate_thumbnail(outname, thumb_name)
thumb_name = join(outpath, get_thumb(settings, filename))
sigal.video.generate_thumbnail(outname, thumb_name,
settings['thumb_size'])
def get_metadata(path):

View File

@@ -49,10 +49,23 @@ _DEFAULT_CONFIG = {
def get_thumb(settings, filename):
"""Return the path to the thumb."""
"""Return the path to the thumb.
examples:
>>> get_thumb(default_settings, "bar/foo.jpg")
"bar/thumbnails/foo.jpg"
>>> get_thumb(default_settings, "bar/foo.png")
"bar/thumbnails/foo.png"
for videos, it returns a jpg file:
>>> get_thumb(default_settings, "bar/foo.webm")
"bar/thumbnails/foo.jpg"
"""
path, filen = os.path.split(filename)
name, ext = os.path.splitext(filen)
if ext in settings['vid_ext_list']:
ext = '.jpg'
return os.path.join(path, settings['thumb_dir'], settings['thumb_prefix'] +
name + settings['thumb_suffix'] + ext)

View File

@@ -57,7 +57,7 @@
</div>
{% endif %}
{% if image or videos %}
{% if images or videos %}
<div id="gallery">
{% for image in images %}
<a href="{{ image.file }}">
@@ -69,7 +69,13 @@
{% for video in videos %}
<a href="{{ theme.url }}/img/empty.png">
<img src="{{ video.thumb }}" alt="{{ video.file }}"
data-layer="<video controls> <source src={{ video.file }} type='video/webm' /></video>" />
{# TODO: stop using inline css, put this in the main css file #}
data-layer="<video style='position:absolute;
top:10%;
width:100%;
margin=0 auto;' controls>
<source src={{ video.file }} type='video/webm' />
</video>" />
</a>
{% endfor %}
</div>

View File

@@ -23,8 +23,7 @@
from __future__ import with_statement
import subprocess
def generate_video(source, outname, options=['-vf', 'scale=800:trunc(ow/a/2)*2']):
# http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio
def generate_video(source, outname, size, options=[]):
"""Video processor
:param source: path to an image
@@ -32,13 +31,20 @@ def generate_video(source, outname, options=['-vf', 'scale=800:trunc(ow/a/2)*2']
:param options: array of options passed to ffmpeg
"""
# We don't keep the h param, because we want to keep the same ratio as
# the original file (resizeToFit is not available in ffmpeg)
# see http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio
(w, h) = size
with open("/dev/null") as devnull:
subprocess.call(['ffmpeg', '-i', source, '-y'] + options +
[outname], stderr=devnull)
subprocess.call(['ffmpeg', '-i', source, '-y', '-vf',
"scale=%i:trunc(ow/a/2)*2'" % w] + options + [outname],
stderr=devnull)
def generate_thumbnail(source, outname, options=['-vf', 'scale=80:trunc(ow/a/2)*2']):
# http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio
def generate_thumbnail(source, outname, box, options=[]):
"Create a thumbnail image"
# See comment in the previous function
(w, h) = box
with open("/dev/null") as devnull:
subprocess.call(['ffmpeg', '-i', source, '-an', '-r', '1',
'-vframes', '1', '-y'] + options + [outname], stderr=devnull)
'-vframes', '1', '-y', '-vf', "scale=%i:trunc(ow/a/2)*2" % h]
+ options + [outname], stderr=devnull)

View File

@@ -145,7 +145,7 @@ class Writer(object):
for i in paths[relpath]['vid']:
base, ext = os.path.splitext(i)
vid_ctx = {'file': base + '.webm',
'thumb': get_thumb(self.settings, base + '.jpg')}
'thumb': get_thumb(self.settings, i)}
if self.settings['keep_orig']:
vid_ctx['big'] = get_orig(self.settings, i)
ctx['videos'].append(vid_ctx)