server/images: work around ffmpeg bug 5609
This commit is contained in:
parent
aa2f4559b7
commit
01c74526c7
1 changed files with 17 additions and 4 deletions
|
@ -1,7 +1,11 @@
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from szurubooru import errors
|
from szurubooru import errors
|
||||||
from szurubooru.func import util
|
from szurubooru.func import mime, util
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_SCALE_FIT_FMT = \
|
_SCALE_FIT_FMT = \
|
||||||
r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)'
|
r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)'
|
||||||
|
@ -39,7 +43,7 @@ class Image(object):
|
||||||
'-i', '{path}',
|
'-i', '{path}',
|
||||||
'-f', 'image2',
|
'-f', 'image2',
|
||||||
'-vframes', '1',
|
'-vframes', '1',
|
||||||
'-vcodec', 'png',
|
'-vcodec', codec,
|
||||||
'-',
|
'-',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -53,7 +57,9 @@ class Image(object):
|
||||||
])
|
])
|
||||||
|
|
||||||
def _execute(self, cli, program='ffmpeg'):
|
def _execute(self, cli, program='ffmpeg'):
|
||||||
with util.create_temp_file() as handle:
|
extension = mime.get_extension(mime.get_mime_type(self.content))
|
||||||
|
assert extension
|
||||||
|
with util.create_temp_file(suffix='.' + extension) as handle:
|
||||||
handle.write(self.content)
|
handle.write(self.content)
|
||||||
handle.flush()
|
handle.flush()
|
||||||
cli = [program, '-loglevel', '24'] + cli
|
cli = [program, '-loglevel', '24'] + cli
|
||||||
|
@ -65,17 +71,24 @@ class Image(object):
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
out, err = proc.communicate(input=self.content)
|
out, err = proc.communicate(input=self.content)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
|
logger.warning(
|
||||||
|
'Failed to execute ffmpeg command (cli=%r, err=%r)',
|
||||||
|
' '.join(shlex.quote(arg) for arg in cli),
|
||||||
|
err)
|
||||||
|
with open('/tmp/tmp', 'wb') as handle:
|
||||||
|
handle.write(self.content)
|
||||||
|
|
||||||
raise errors.ProcessingError(
|
raise errors.ProcessingError(
|
||||||
'Error while processing image.\n' + err.decode('utf-8'))
|
'Error while processing image.\n' + err.decode('utf-8'))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _reload_info(self):
|
def _reload_info(self):
|
||||||
self.info = json.loads(self._execute([
|
self.info = json.loads(self._execute([
|
||||||
|
'-i', '{path}',
|
||||||
'-of', 'json',
|
'-of', 'json',
|
||||||
'-select_streams', 'v',
|
'-select_streams', 'v',
|
||||||
'-show_streams',
|
'-show_streams',
|
||||||
'-count_frames',
|
'-count_frames',
|
||||||
'-i', '-',
|
|
||||||
], program='ffprobe').decode('utf-8'))
|
], program='ffprobe').decode('utf-8'))
|
||||||
assert 'streams' in self.info
|
assert 'streams' in self.info
|
||||||
if len(self.info['streams']) != 1:
|
if len(self.info['streams']) != 1:
|
||||||
|
|
Loading…
Reference in a new issue