aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/helpers
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-08-18 18:23:27 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-08-18 18:23:27 +0300
commitda116d81fb0028913c2a0f30ac35532fb500e8fc (patch)
tree6b257d2bafd01fb5937bc5f541f9e1a4d9dd3b75 /lib/pleroma/helpers
parent27e7999a151d8068ec503c9a25aff352f4d31068 (diff)
downloadpleroma-da116d81fb0028913c2a0f30ac35532fb500e8fc.tar.gz
[#2497] Added video preview proxy. Switched from exexec to Port.
Diffstat (limited to 'lib/pleroma/helpers')
-rw-r--r--lib/pleroma/helpers/media_helper.ex19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/pleroma/helpers/media_helper.ex b/lib/pleroma/helpers/media_helper.ex
index ecd234558..ca46698cc 100644
--- a/lib/pleroma/helpers/media_helper.ex
+++ b/lib/pleroma/helpers/media_helper.ex
@@ -7,19 +7,24 @@ defmodule Pleroma.Helpers.MediaHelper do
Handles common media-related operations.
"""
- def ffmpeg_resize_remote(uri, %{max_width: max_width, max_height: max_height}) do
+ def ffmpeg_resize(uri_or_path, %{max_width: max_width, max_height: max_height}) do
cmd = ~s"""
- curl -L "#{uri}" |
- ffmpeg -i pipe:0 -f lavfi -i color=c=white \
+ 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" \
- -f image2 -vcodec mjpeg -frames:v 1 pipe:1 | \
- cat
+ -loglevel quiet -f image2 -vcodec mjpeg -frames:v 1 pipe:1
"""
- with {:ok, [stdout: stdout_list]} <- Pleroma.Exec.cmd(cmd) do
- {:ok, Enum.join(stdout_list)}
+ pid = Port.open({:spawn, cmd}, [:use_stdio, :in, :stream, :exit_status, :binary])
+
+ receive do
+ {^pid, {:data, data}} ->
+ send(pid, {self(), :close})
+ {:ok, data}
+
+ {^pid, {:exit_status, status}} when status > 0 ->
+ {:error, status}
end
end
end