defp prepare_image_resize_args(_), do: {:error, :missing_options}
+ def video_framegrab(url) do
+ with executable when is_binary(executable) <- System.find_executable("ffmpeg"),
+ args = [
+ "-i", "-",
+ "-vframes", "1",
+ "-f", "mjpeg",
+ "-loglevel", "error",
+ "-"
+ ],
+ url = Pleroma.Web.MediaProxy.url(url),
+ {:ok, env} <- Pleroma.HTTP.get(url),
+ {:ok, fifo_path} <- mkfifo() do
+ run_fifo(fifo_path, env, executable, args)
+ else
+ nil -> {:error, {:ffmpeg, :command_not_found}}
+ {:error, _} = error -> error
+ end
+ end
+
defp run_fifo(fifo_path, env, executable, args) do
args = List.flatten([fifo_path, args])
pid = Port.open({:spawn_executable, executable}, [:use_stdio, :stream, :exit_status, :binary, args: args])
end
defp handle_preview("video/" <> _ = _content_type, conn, url) do
- mediaproxy_url = url |> MediaProxy.url()
-
- redirect(conn, external: mediaproxy_url)
+ handle_video_preview(conn, url)
end
defp handle_preview(content_type, conn, _url) do
end
end
+ defp handle_video_preview(conn, url) do
+ with {:ok, thumbnail_binary} <-
+ MediaHelper.video_framegrab(url) do
+ conn
+ |> put_resp_header("content-type", "image/jpeg")
+ |> put_resp_header("content-disposition", "inline; filename=\"preview.jpg\"")
+ |> send_resp(200, thumbnail_binary)
+ else
+ _ ->
+ send_resp(conn, :failed_dependency, "Can't handle preview.")
+ end
+ end
+
defp thumbnail_max_dimensions(params) do
config = Config.get([:media_preview_proxy], [])