ffmpeg needs input from fifo path, not stdin

This commit is contained in:
Mark Felder 2020-08-27 12:47:29 -05:00
parent ef9d12fcc5
commit f1218a2b4e

View File

@ -39,16 +39,16 @@ defmodule Pleroma.Helpers.MediaHelper do
def video_framegrab(url) do def video_framegrab(url) do
with executable when is_binary(executable) <- System.find_executable("ffmpeg"), with executable when is_binary(executable) <- System.find_executable("ffmpeg"),
url = Pleroma.Web.MediaProxy.url(url),
{:ok, env} <- Pleroma.HTTP.get(url),
{:ok, fifo_path} <- mkfifo(),
args = [ args = [
"-i", "-", "-i", fifo_path,
"-vframes", "1", "-vframes", "1",
"-f", "mjpeg", "-f", "mjpeg",
"-loglevel", "error", "-loglevel", "error",
"-" "-"
], ] do
url = Pleroma.Web.MediaProxy.url(url),
{:ok, env} <- Pleroma.HTTP.get(url),
{:ok, fifo_path} <- mkfifo() do
run_fifo(fifo_path, env, executable, args) run_fifo(fifo_path, env, executable, args)
else else
nil -> {:error, {:ffmpeg, :command_not_found}} nil -> {:error, {:ffmpeg, :command_not_found}}
@ -57,7 +57,12 @@ defmodule Pleroma.Helpers.MediaHelper do
end end
defp run_fifo(fifo_path, env, executable, args) do defp run_fifo(fifo_path, env, executable, args) do
args = List.flatten([fifo_path, args]) args =
if _executable = System.find_executable("convert") do
List.flatten([fifo_path, args])
else
args
end
pid = Port.open({:spawn_executable, executable}, [:use_stdio, :stream, :exit_status, :binary, args: args]) pid = Port.open({:spawn_executable, executable}, [:use_stdio, :stream, :exit_status, :binary, args: args])
fifo = Port.open(to_charlist(fifo_path), [:eof, :binary, :stream, :out]) fifo = Port.open(to_charlist(fifo_path), [:eof, :binary, :stream, :out])
true = Port.command(fifo, env.body) true = Port.command(fifo, env.body)