server/images: use mozjpeg/libjpeg-turbo for jpeg conversion
This commit is contained in:
parent
782f069031
commit
80840b9509
1 changed files with 11 additions and 19 deletions
|
@ -96,24 +96,13 @@ class Image:
|
||||||
def to_jpeg(self) -> bytes:
|
def to_jpeg(self) -> bytes:
|
||||||
return self._execute(
|
return self._execute(
|
||||||
[
|
[
|
||||||
"-f",
|
"-quality",
|
||||||
"lavfi",
|
"85",
|
||||||
"-i",
|
"-sample",
|
||||||
"color=white:s=%dx%d" % (self.width, self.height),
|
"1x1",
|
||||||
"-i",
|
|
||||||
"{path}",
|
"{path}",
|
||||||
"-f",
|
],
|
||||||
"image2",
|
program="cjpeg",
|
||||||
"-filter_complex",
|
|
||||||
"overlay",
|
|
||||||
"-map",
|
|
||||||
"0:v:0",
|
|
||||||
"-vframes",
|
|
||||||
"1",
|
|
||||||
"-vcodec",
|
|
||||||
"mjpeg",
|
|
||||||
"-",
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_webm(self) -> bytes:
|
def to_webm(self) -> bytes:
|
||||||
|
@ -274,7 +263,10 @@ class Image:
|
||||||
with util.create_temp_file(suffix="." + extension) as handle:
|
with util.create_temp_file(suffix="." + extension) as handle:
|
||||||
handle.write(self.content)
|
handle.write(self.content)
|
||||||
handle.flush()
|
handle.flush()
|
||||||
cli = [program, "-loglevel", "32" if get_logs else "24"] + cli
|
if program in ["ffmpeg", "ffprobe"]:
|
||||||
|
cli = [program, "-loglevel", "32" if get_logs else "24"] + cli
|
||||||
|
else:
|
||||||
|
cli = [program] + cli
|
||||||
cli = [part.format(path=handle.name) for part in cli]
|
cli = [part.format(path=handle.name) for part in cli]
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
cli,
|
cli,
|
||||||
|
@ -285,7 +277,7 @@ class Image:
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Failed to execute ffmpeg command (cli=%r, err=%r)",
|
"Failed to execute {program} command (cli=%r, err=%r)".format(program=program),
|
||||||
" ".join(shlex.quote(arg) for arg in cli),
|
" ".join(shlex.quote(arg) for arg in cli),
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
|
|
Reference in a new issue