1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Helpers.MediaHelper do
7 Handles common media-related operations.
10 def ffmpeg_resize_remote(uri, %{max_width: max_width, max_height: max_height}) do
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 | \
21 with {:ok, [stdout: stdout_list]} <- Pleroma.Exec.cmd(cmd) do
22 {:ok, Enum.join(stdout_list)}