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: