在背景ROR 3中转换视频

时间:2012-10-02 02:30:41

标签: ruby-on-rails ffmpeg paperclip

我在google上搜索并且只提出了一个解释如何执行此操作的网站:http://railsonedge.blogspot.com/2009/01/flash-video-tutorial-with-rails-ffmpeg.html?m=0我已经使用了回形针,并且已经使用它设置了所有内容并且比使用它更好这个网站的方式。有没有办法在后台转换视频,同时使用回形针跟踪它的状态?我的Video.rb目前:

class Video < ActiveRecord::Base
  belongs_to :user
  has_many :comments, dependent: :destroy
  attr_accessible :video, :user_id, :video_file_name, :title, :public, :description, :views

  has_attached_file :video, :styles => { 
    :video => { geometry: "800x480>", format: 'webm' },
    :thumb => { geometry: "200x200>", format: 'png', time: 3 },
  }, processors: [:ffmpeg], url: "/users/:user_id/videos/:id/:basename_:style.:extension"

  #process_in_background :video #causes death

  validates :video, presence: true
  validates :description, presence: true, length: { minimum: 5, maximum: 100}
  validates :title, presence: true, length: { minimum: 1, maximum: 15 }

  validates_attachment_size :video, less_than: 1.gigabytes
  validates_attachment :video, presence: true

  default_scope order: 'created_at DESC'

  Paperclip.interpolates :user_id do |attachment, style|attachment.instance.user_id
  end

  def self.search(search)
    if search
      find(:all, conditions: ["public = 't' AND title LIKE ?", "%#{search}%"], order: "created_at DESC")
    else
      find(:all, conditions: ["public = 't'"], order: "created_at DESC")
    end
  end

  def self.admin_search(search)
    if search
      find(:all, conditions: ['title LIKE ?', "%#{search}%"], order: "created_at DESC")
    else
      find(:all, order: "created_at DESC")
    end
  end

end

1 个答案:

答案 0 :(得分:0)

首先check this answer。对于您要使用sidekiq的后台作业。你需要处理转换的方法。您将在sidekiq的#perform中调用该方法。在此方法中,您还可以更改状态(只需更改字符串字段值)。