Merge branch 'pr/153'
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -3,6 +3,7 @@ alphabetical order):
|
||||
|
||||
- Christophe-Marie Duquesne
|
||||
- Jonas Kaufmann
|
||||
- Juan A. Suarez Romero
|
||||
- Antoine Pitrou
|
||||
- Giel van Schijndel
|
||||
- Matthias Vogelgesang
|
||||
|
||||
@@ -44,7 +44,8 @@ from .compat import PY2, UnicodeMixin, strxfrm, url_quote, text_type
|
||||
from .image import process_image, get_exif_tags, get_exif_data
|
||||
from .settings import get_thumb
|
||||
from .utils import (Devnull, copy, check_or_create_dir, url_from_path,
|
||||
read_markdown, cached_property)
|
||||
read_markdown, cached_property, is_valid_html5_video,
|
||||
get_mime)
|
||||
from .video import process_video
|
||||
from .writer import Writer
|
||||
|
||||
@@ -176,11 +177,15 @@ class Video(Media):
|
||||
|
||||
def __init__(self, filename, path, settings):
|
||||
super(Video, self).__init__(filename, path, settings)
|
||||
base = splitext(filename)[0]
|
||||
(base, ext) = splitext(filename)
|
||||
self.date = None
|
||||
self.src_filename = filename
|
||||
self.filename = self.url = base + '.webm'
|
||||
self.dst_path = join(settings['destination'], path, base + '.webm')
|
||||
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')
|
||||
else:
|
||||
self.mime = get_mime(ext)
|
||||
|
||||
|
||||
class Album(UnicodeMixin):
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<div style='display:none'>
|
||||
<div id="{{ mhash }}">
|
||||
<video controls>
|
||||
<source src='{{ media.filename }}' type='video/webm' />
|
||||
<source src='{{ media.filename }}' type='{{ media.mime }}' />
|
||||
</video>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -28,6 +28,10 @@ from subprocess import Popen, PIPE
|
||||
|
||||
from . import compat
|
||||
|
||||
VIDEO_MIMES = {'.mp4': 'video/mp4',
|
||||
'.webm': 'video/webm',
|
||||
'.ogv': 'video/ogg'}
|
||||
|
||||
|
||||
class Devnull(object):
|
||||
"""'Black hole' for output that should not be printed"""
|
||||
@@ -100,6 +104,16 @@ def call_subprocess(cmd):
|
||||
return p.returncode, stdout, stderr
|
||||
|
||||
|
||||
def is_valid_html5_video(ext):
|
||||
"""Checks if ext is a supported HTML5 video."""
|
||||
return ext in VIDEO_MIMES.keys()
|
||||
|
||||
|
||||
def get_mime(ext):
|
||||
"""Returns mime type for extension."""
|
||||
return VIDEO_MIMES[ext]
|
||||
|
||||
|
||||
class cached_property(object):
|
||||
""" A property that is only computed once per instance and then replaces
|
||||
itself with an ordinary attribute. Deleting the attribute resets the
|
||||
|
||||
@@ -29,9 +29,9 @@ import re
|
||||
import shutil
|
||||
from os.path import splitext
|
||||
|
||||
from . import image
|
||||
from . import image, utils
|
||||
from .settings import get_thumb, Status
|
||||
from .utils import call_subprocess
|
||||
from .utils import call_subprocess, is_valid_html5_video
|
||||
|
||||
|
||||
class SubprocessException(Exception):
|
||||
@@ -75,12 +75,12 @@ def video_size(source):
|
||||
return x, y
|
||||
|
||||
|
||||
def generate_video(source, outname, size, options=None):
|
||||
def generate_video(source, outname, settings, options=None):
|
||||
"""Video processor.
|
||||
|
||||
:param source: path to a video
|
||||
:param outname: path to the generated video
|
||||
:param size: size of the resized video `(width, height)`
|
||||
:param settings: settings dict
|
||||
:param options: array of options passed to ffmpeg
|
||||
|
||||
"""
|
||||
@@ -89,7 +89,7 @@ def generate_video(source, outname, size, 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_dst, h_dst = size
|
||||
w_dst, h_dst = settings['video_size']
|
||||
logger.debug('Video size: %i, %i -> %i, %i', w_src, h_src, w_dst, h_dst)
|
||||
|
||||
base, src_ext = splitext(source)
|
||||
@@ -149,12 +149,16 @@ def process_video(filepath, outpath, settings):
|
||||
"""Process a video: resize, create thumbnail."""
|
||||
|
||||
filename = os.path.split(filepath)[1]
|
||||
basename = splitext(filename)[0]
|
||||
outname = os.path.join(outpath, basename + '.webm')
|
||||
(basename, ext) = splitext(filename)
|
||||
|
||||
try:
|
||||
generate_video(filepath, outname, settings['video_size'],
|
||||
options=settings['webm_options'])
|
||||
if settings['use_orig'] and is_valid_html5_video(ext):
|
||||
outname = os.path.join(outpath, filename)
|
||||
utils.copy(filepath, outname, symlink=settings['orig_link'])
|
||||
else:
|
||||
outname = os.path.join(outpath, basename + '.webm')
|
||||
generate_video(filepath, outname, settings,
|
||||
options=settings['webm_options'])
|
||||
except Exception:
|
||||
return Status.FAILURE
|
||||
|
||||
@@ -162,8 +166,9 @@ def process_video(filepath, outpath, settings):
|
||||
thumb_name = os.path.join(outpath, get_thumb(settings, filename))
|
||||
try:
|
||||
generate_thumbnail(
|
||||
outname, thumb_name, settings['thumb_size'], settings['thumb_video_delay'],
|
||||
fit=settings['thumb_fit'], options=settings['jpg_options'])
|
||||
outname, thumb_name, settings['thumb_size'],
|
||||
settings['thumb_video_delay'], fit=settings['thumb_fit'],
|
||||
options=settings['jpg_options'])
|
||||
except Exception:
|
||||
return Status.FAILURE
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import division
|
||||
import os
|
||||
|
||||
from sigal.video import video_size, generate_video
|
||||
from sigal.settings import create_settings
|
||||
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
TEST_VIDEO = 'stallman software-freedom-day-low.ogv'
|
||||
@@ -21,7 +22,8 @@ def test_generate_video_fit_height(tmpdir):
|
||||
|
||||
base, ext = os.path.splitext(TEST_VIDEO)
|
||||
dstfile = str(tmpdir.join(base + '.webm'))
|
||||
generate_video(SRCFILE, dstfile, (50, 100))
|
||||
settings = create_settings(video_size=(50, 100))
|
||||
generate_video(SRCFILE, dstfile, settings)
|
||||
|
||||
size_src = video_size(SRCFILE)
|
||||
size_dst = video_size(dstfile)
|
||||
@@ -36,7 +38,8 @@ def test_generate_video_fit_width(tmpdir):
|
||||
|
||||
base, ext = os.path.splitext(TEST_VIDEO)
|
||||
dstfile = str(tmpdir.join(base + '.webm'))
|
||||
generate_video(SRCFILE, dstfile, (100, 50))
|
||||
settings = create_settings(video_size=(100, 50))
|
||||
generate_video(SRCFILE, dstfile, settings)
|
||||
|
||||
size_src = video_size(SRCFILE)
|
||||
size_dst = video_size(dstfile)
|
||||
@@ -51,7 +54,8 @@ def test_generate_video_dont_enlarge(tmpdir):
|
||||
|
||||
base, ext = os.path.splitext(TEST_VIDEO)
|
||||
dstfile = str(tmpdir.join(base + '.webm'))
|
||||
generate_video(SRCFILE, dstfile, (1000, 1000))
|
||||
settings = create_settings(video_size=(1000, 1000))
|
||||
generate_video(SRCFILE, dstfile, settings)
|
||||
|
||||
size_src = video_size(SRCFILE)
|
||||
size_dst = video_size(dstfile)
|
||||
|
||||
Reference in New Issue
Block a user