diff options
| author | rr- | 2016-06-02 01:15:26 +0200 |
|---|---|---|
| committer | rr- | 2016-06-02 13:58:08 +0200 |
| commit | 01c74526c7332fe1e7b753246d241f9bc531d3a1 (patch) | |
| tree | 1af4ff29bdb7427d1b648a146ddd4e4c704e6431 /server | |
| parent | aa2f4559b76a34ae61e3e61d4ad0f169e4bb2f1e (diff) | |
server/images: work around ffmpeg bug 5609
Diffstat (limited to 'server')
| -rw-r--r-- | server/szurubooru/func/images.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index 2ac079e..caee652 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -1,7 +1,11 @@ +import logging import json +import shlex import subprocess from szurubooru import errors -from szurubooru.func import util +from szurubooru.func import mime, util + +logger = logging.getLogger(__name__) _SCALE_FIT_FMT = \ r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)' @@ -39,7 +43,7 @@ class Image(object): '-i', '{path}', '-f', 'image2', '-vframes', '1', - '-vcodec', 'png', + '-vcodec', codec, '-', ]) @@ -53,7 +57,9 @@ class Image(object): ]) 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.flush() cli = [program, '-loglevel', '24'] + cli @@ -65,17 +71,24 @@ class Image(object): stderr=subprocess.PIPE) out, err = proc.communicate(input=self.content) 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( 'Error while processing image.\n' + err.decode('utf-8')) return out def _reload_info(self): self.info = json.loads(self._execute([ + '-i', '{path}', '-of', 'json', '-select_streams', 'v', '-show_streams', '-count_frames', - '-i', '-', ], program='ffprobe').decode('utf-8')) assert 'streams' in self.info if len(self.info['streams']) != 1: |