aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-08-21 08:59:08 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-08-21 08:59:08 +0300
commitaa0a5ffb4849880b5adbcc9188de01ef778381e3 (patch)
tree3a87c2e5a2aae7ef790a03a1da3729a0e0720cdc /lib
parent02ad1cd8e97c44824b92b53ea1879a965bbd8358 (diff)
downloadpleroma-aa0a5ffb4849880b5adbcc9188de01ef778381e3.tar.gz
[#2497] Media preview proxy: added `quality` config setting, adjusted width/height defaults.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/helpers/media_helper.ex6
-rw-r--r--lib/pleroma/web/media_proxy/media_proxy_controller.ex4
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/pleroma/helpers/media_helper.ex b/lib/pleroma/helpers/media_helper.ex
index ca46698cc..e11038052 100644
--- a/lib/pleroma/helpers/media_helper.ex
+++ b/lib/pleroma/helpers/media_helper.ex
@@ -7,13 +7,15 @@ defmodule Pleroma.Helpers.MediaHelper do
Handles common media-related operations.
"""
- def ffmpeg_resize(uri_or_path, %{max_width: max_width, max_height: max_height}) do
+ def ffmpeg_resize(uri_or_path, %{max_width: max_width, max_height: max_height} = options) do
+ quality = options[:quality] || 1
+
cmd = ~s"""
ffmpeg -i #{uri_or_path} -f lavfi -i color=c=white \
-filter_complex "[0:v] scale='min(#{max_width},iw)':'min(#{max_height},ih)': \
force_original_aspect_ratio=decrease [scaled]; \
[1][scaled] scale2ref [bg][img]; [bg] setsar=1 [bg]; [bg][img] overlay=shortest=1" \
- -loglevel quiet -f image2 -vcodec mjpeg -frames:v 1 pipe:1
+ -loglevel quiet -f image2 -vcodec mjpeg -frames:v 1 -q:v #{quality} pipe:1
"""
pid = Port.open({:spawn, cmd}, [:use_stdio, :in, :stream, :exit_status, :binary])
diff --git a/lib/pleroma/web/media_proxy/media_proxy_controller.ex b/lib/pleroma/web/media_proxy/media_proxy_controller.ex
index 5513432f0..1c51aa5e3 100644
--- a/lib/pleroma/web/media_proxy/media_proxy_controller.ex
+++ b/lib/pleroma/web/media_proxy/media_proxy_controller.ex
@@ -78,12 +78,14 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
end
defp handle_image_or_video_preview(%{params: params} = conn, url) do
+ quality = Config.get!([:media_preview_proxy, :quality])
+
with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params),
media_proxy_url <- MediaProxy.url(url),
{:ok, thumbnail_binary} <-
MediaHelper.ffmpeg_resize(
media_proxy_url,
- %{max_width: thumbnail_max_width, max_height: thumbnail_max_height}
+ %{max_width: thumbnail_max_width, max_height: thumbnail_max_height, quality: quality}
) do
conn
|> put_resp_header("content-type", "image/jpeg")