aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorrr-2016-06-02 01:34:06 +0200
committerrr-2016-06-02 13:58:08 +0200
commit0743721d062b44f5b81348a0aab2dc96a76edb77 (patch)
tree71e92cccd8e9cd2eb585b55d35ea96d9ecad2ffb /server
parent01c74526c7332fe1e7b753246d241f9bc531d3a1 (diff)
server/images: seek to 30% video before resizing
Diffstat (limited to 'server')
-rw-r--r--server/szurubooru/func/images.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py
index caee652..20b2165 100644
--- a/server/szurubooru/func/images.py
+++ b/server/szurubooru/func/images.py
@@ -2,6 +2,7 @@ import logging
import json
import shlex
import subprocess
+import math
from szurubooru import errors
from szurubooru.func import mime, util
@@ -28,17 +29,26 @@ class Image(object):
return self.info['streams'][0]['nb_read_frames']
def resize_fill(self, width, height):
- self.content = self._execute([
+ cli = [
'-i', '{path}',
'-f', 'image2',
'-vf', _SCALE_FIT_FMT.format(width=width, height=height),
'-vframes', '1',
'-vcodec', 'png',
'-',
- ])
+ ]
+ if 'duration' in self.info['format'] \
+ and float(self.info['format']['duration']) > 3 \
+ and self.info['format']['format_name'] != 'swf':
+ cli = [
+ '-ss',
+ '%d' % math.floor(float(self.info['format']['duration']) * 0.3),
+ ] + cli
+ self.content = self._execute(cli)
+ assert self.content
self._reload_info()
- def to_png(self):
+ def _to_image(self, codec):
return self._execute([
'-i', '{path}',
'-f', 'image2',
@@ -47,14 +57,11 @@ class Image(object):
'-',
])
+ def to_png(self):
+ return self._to_image('png')
+
def to_jpeg(self):
- return self._execute([
- '-i', '{path}',
- '-f', 'image2',
- '-vframes', '1',
- '-vcodec', 'mjpeg',
- '-',
- ])
+ return self._to_image('mjpeg')
def _execute(self, cli, program='ffmpeg'):
extension = mime.get_extension(mime.get_mime_type(self.content))
@@ -87,9 +94,10 @@ class Image(object):
'-i', '{path}',
'-of', 'json',
'-select_streams', 'v',
+ '-show_format',
'-show_streams',
- '-count_frames',
], program='ffprobe').decode('utf-8'))
+ assert 'format' in self.info
assert 'streams' in self.info
if len(self.info['streams']) != 1:
raise errors.ProcessingError('Multiple video streams detected.')

© 2015 - 2026 Jakob L. Kreuze