1

I've searched around on google and have come up with only one site that explains how to do this: http://railsonedge.blogspot.com/2009/01/flash-video-tutorial-with-rails-ffmpeg.html?m=0 I'm already using paperclip and already have everything set up with it and like using it better than the way this site is doing it. Is there a way to convert videos in the background while keeping track of the state of it using paperclip? My Video.rb currently:

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
Matthew
  • 35
  • 1
  • 8

1 Answers1

0

First of all check this answer. For background jobs you want to use sidekiq. You'll need method that'll handle convertion. That method you'll call inside sidekiq's #perform. Inside this method you also can change states(just by changing string field value).

Community
  • 1
  • 1
Vadym Chumel
  • 1,766
  • 13
  • 20
  • Thanks a bunch, but is there a way i could keep :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" or is it necessary to have my own method? Also, I just noticed that Sidekiq requires a separate terminal window, i'm having to ssh into a server so I don't think that this is possible? – Matthew Oct 02 '12 at 23:14
  • I'll assume not, I'll just use that link I found's method. Thanks for the answer though – Matthew Oct 03 '12 at 01:09
  • @DragonFire353 I'm not 100% sure but I think there's no such way. You can run sidekiq in background with various ways. I'm using `screen`. Something like `screen -dmS sidekiq sidekiq` should do the trick. – Vadym Chumel Oct 03 '12 at 08:33
  • I'm having issues starting sidekiq, I'm running rails 3.2.8 and when I try running, bundle exec sidekiq I get the following eror: C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.3.3/lib/sidekiq/c li.rb:12:in `trap': unsupported signal SIGUSR1 (ArgumentError) from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.3.3/ lib/sidekiq/cli.rb:12:in `' from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.3.3/ bin/sidekiq:3:in `require_relative' – Matthew Oct 04 '12 at 00:20
  • from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.3.3/ bin/sidekiq:3:in `' from C:/RailsInstaller/Ruby1.9.3/bin/sidekiq:19:in `load' from C:/RailsInstaller/Ruby1.9.3/bin/sidekiq:19:in `
    ' you ever get this error?
    – Matthew Oct 04 '12 at 00:21
  • @DragonFire353 sorry but looks like it's not compatible with windows. [More info](https://github.com/mperham/sidekiq/issues/205). Using linux or MasOS can protect you from lot of pain. – Vadym Chumel Oct 04 '12 at 11:20
  • Ugh lol... ya, ubuntu doesn't like my laptop because of nvidia... (damn u nvidia and your closed source drivers!!!) and I'm not to fond of any other distributions. I plan on selling my laptop soon for, a much more portable laptop than my current, macbook air soon hopefully... thanks for all your help though – Matthew Oct 04 '12 at 21:46