ffmpeg - 使用 Arc 和 FFmpeg 在 Elixir 中创建上传视频的背景版本

标签 ffmpeg elixir automatic-ref-counting

我尝试使用 Arc 在 Elixir phoenix 项目上进行视频上传。我需要不同大小的视频版本。所以我使用FFmpeg来做到这一点:

def transform(:large, {file, scope}) do
  {:ffmpeg, fn(input, output) -> "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}" end, :mp4}
end

但是,即使是小视频,也需要花费大量时间来创建此版本。所以,我决定在后台进行版本创建。我希望 Arc 上传视频,然后在创建其他版本时用上传的原件给出响应。

我希望在 https://github.com/stavro/arc 找到这样的选项但我没有成功。我只发现“要禁用异步处理,请将 @async false 添加到您的上传定义”,但我不想禁用它,对吧?

我尝试使用 Exq https://github.com/akira/exq用于后台处理,但我没有在 uploader 中使用它。

谁能告诉我应该如何以适当的方式制作它,或者给我一些肮脏的黑客建议以使其工作。谢谢。

我按照评论中的建议尝试了 Task,但我不确定在这种情况下如何使用它们。当我尝试
{:ffmpeg, fn(input, output) -> Task.async(fn -> "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}" end) end, :mp4}

或者
{:ffmpeg, Task.async(fn -> fn(input, output) ->  "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}" end end), :mp4}

我得到“没有为 %Task 实现协议(protocol) String.Chars”。

当我尝试
{:ffmpeg, Task.async(fn(input, output) ->  "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}" end), :mp4}

我得到“MyWebSite.Content.transform/2> 中的#Function<20.83953603/2> 没有参数调用 arity 2”。我试图用“&”将函数作为参数传递,但它也失败了。

我的上传者:
defmodule MyWebSite.Content do
use Arc.Definition
use Arc.Ecto.Definition

@acl :public_read

@versions [:original,  :huge]

def transform(:huge, {file, scope}) do
  {:ffmpeg, Task.async(fn(input, output) ->  "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}" end), :mp4}
end

def s3_object_headers(version, {file, scope}) do
  [timeout: 3_000_00, content_type: Plug.MIME.path(file.file_name)]
end
end

最佳答案

来自 Arc的自述文件(Complex Transformations 部分):

However, the transformation may be done completely outside of Arc. For fine-grained transformations, you should create an executable wrapper in your $PATH (eg. bash script) which takes these proper arguments, runs your transformation, and then moves the file into the correct location**.



也就是说,如果您希望转换完全异步运行,只需在某处创建一个 bash 脚本并调用它(假设它的名称是 myffmpeg):
def transform(:huge, {file, scope}) do
  {:myffmpeg,
     fn ->
       "-i #{input} -c:a copy -s 1920x1080 -f mp4 #{output}"
     end,
   :mp4}
end

脚本应生成 ffmpeg传递参数并将结果移动到文件夹 Arc想要。

关于ffmpeg - 使用 Arc 和 FFmpeg 在 Elixir 中创建上传视频的背景版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47596764/

相关文章:

audio - FFMPEG - 无法使用 av_write_frame() 生成 aac 音频文件

video - 使用FFMPEG,我们如何在黑条区域或视频下方添加字幕?

javascript - 需要帮助在 Node js 中通过 ffmpeg 实现视频中的淡入淡出效果

ios - 使用 ARC 添加 subview 时随机 EXC_BAD_ACCESS

video - FFMPEG YouTube 直播太快了

macros - 可以用宏获得评论吗?

Elixir:如何处理函数和 nil 值中的可选/默认参数?

elixir - 如何在包含的模块中获取调用方模块名称?

macos - 如何销毁(解除分配)从 nib 文件加载的 View 项的实例

ios - UITableViewController 被初始化两次