2012-10-02 10 views
1

我周围搜查谷歌,并拿出了仅有一个网站,解释如何做到这一点:http://railsonedge.blogspot.com/2009/01/flash-video-tutorial-with-rails-ffmpeg.html?m=0我已经用曲别针和已经拥有一切设置了它,就像使用它比这个网站做的更好。有没有办法在背景中转换视频,同时使用回形针记录它的状态?我的Video.rb当前为:转换视频在后台继续ROR 3

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: "https://stackoverflow.com/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 

回答

0

首先是check this answer。对于您想要使用的背景作业sidekiq。你需要处理转换的方法。您将在sidekiq的#perform中调用该方法。在这个方法内部,你也可以改变状态(只需改变字符串字段值)。

+0

多谢,但有一种方法,我可以保持 :has_attached_file:视频:风格=> { :视频=> {几何: “800×480>”,格式为: 'WEBM'}, :拇指= > {geometry:“200x200>”,format:'png',time:3}, },processors:[:ffmpeg],url:“/ users /:user_id/videos /:id /:basename_:style .:扩展“还是有必要有我自己的方法?此外,我只注意到Sidekiq需要一个单独的终端窗口,我不得不ssh进入服务器,所以我不认为这是可能的? –

+0

我假设没有,我只是使用我找到的方法链接。谢谢你的回答,虽然 –

+0

@ DragonFire353我不是100%确定,但我认为没有这样的方式。你可以用各种方式在后台运行sidekiq。我正在使用'screen'。像'screen -dmS sidekiq sidekiq'应该可以做到这一点。 –