[#2497] Customized `exexec` launch to support root operation (currently required...
[akkoma] / lib / pleroma / helpers / media_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Helpers.MediaHelper do
6 @moduledoc """
7 Handles common media-related operations.
8 """
9
10 def ffmpeg_resize_remote(uri, %{max_width: max_width, max_height: max_height}) do
11 cmd = ~s"""
12 curl -L "#{uri}" |
13 ffmpeg -i pipe:0 -f lavfi -i color=c=white \
14 -filter_complex "[0:v] scale='min(#{max_width},iw)':'min(#{max_height},ih)': \
15 force_original_aspect_ratio=decrease [scaled]; \
16 [1][scaled] scale2ref [bg][img]; [bg] setsar=1 [bg]; [bg][img] overlay=shortest=1" \
17 -f image2 -vcodec mjpeg -frames:v 1 pipe:1 | \
18 cat
19 """
20
21 with {:ok, [stdout: stdout_list]} <- Pleroma.Exec.cmd(cmd) do
22 {:ok, Enum.join(stdout_list)}
23 end
24 end
25 end