[#2497] Media preview proxy: added `quality` config setting, adjusted width/height...
[akkoma] / lib / pleroma / helpers / media_helper.ex
index ca46698ccfb98a296d52a102a1a030f9e57e831e..e11038052d6bd5df2c99c91617bf13cfd85901ac 100644 (file)
@@ -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])