Merge branch 'fix-framegrabs' into 'develop'

Fix ffmpeg framegrabs with Exile

See merge request pleroma/pleroma!4087
This commit is contained in:
feld 2024-03-08 14:48:26 +00:00
commit 72daf522c9
2 changed files with 21 additions and 16 deletions

View file

@ -0,0 +1 @@
Video framegrabs were not working correctly after the change to use Exile to execute ffmpeg

View file

@ -40,12 +40,14 @@ defmodule Pleroma.Helpers.MediaHelper do
end end
# Note: video thumbnail is intentionally not resized (always has original dimensions) # Note: video thumbnail is intentionally not resized (always has original dimensions)
@spec video_framegrab(String.t()) :: {:ok, binary()} | {:error, any()}
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"),
{:ok, env} <- HTTP.get(url, [], pool: :media), {:ok, env} <- HTTP.get(url, [], pool: :media),
{:ok, pid} <- StringIO.open(env.body) do {:ok, pid} <- StringIO.open(env.body) do
body_stream = IO.binstream(pid, 1) body_stream = IO.binstream(pid, 1)
result =
Exile.stream!( Exile.stream!(
[ [
executable, executable,
@ -62,6 +64,8 @@ defmodule Pleroma.Helpers.MediaHelper do
stderr: :disable stderr: :disable
) )
|> Enum.into(<<>>) |> Enum.into(<<>>)
{:ok, result}
else else
nil -> {:error, {:ffmpeg, :command_not_found}} nil -> {:error, {:ffmpeg, :command_not_found}}
{:error, _} = error -> error {:error, _} = error -> error