rails 和回形针中的异步视频处理

Async video processing in rails and paperclip

我正在使用 gem 'paperclip-av-transcoder'、“0.6.2”进行视频处理。

我只需要编写这段代码就可以将我的视频转换成多种格式:

has_attached_file :video, :styles => {
  :mp4 => { :format => 'mp4', :convert_options => { :output => { :vcodec => 'libx264', :acodec => 'copy' } } },
  :ogg => { :format => 'ogg', :auto_rotate => true  },
  :webm => { :format => 'webm', :auto_rotate => true  },
  :flv => { :format => 'flv', :convert_options => { :output => { :ar => 44100 } }, :auto_rotate => true  },
  :thumb => { :geometry => "300x300#", :format => 'jpg', :time => 1, :auto_rotate => true }
}, :processors => [:transcoder]

但是这段代码是同步的,上传视频的用户在转换过程中卡住了。

我想在 :transcoder 周围添加一个异步包装器(worker),这样我就可以调用:

has_attached_file :video, :styles => {... }, :processors => [:wrapper_transcoder_worker]

我已经安装了 resque 和 redis,一切正常。

关于如何围绕转码器编写异步工作器,您有什么想法吗?

你试过delayed_paperclipgem了吗?它将所有处理推入后台并支持 resque(以及其他)。

将回形针锁定在版本 4.2.0