views:

68

answers:

1

I am using the rvideo gem to transcode files to a .flv format.

  class Video < ActiveRecord::Base
  include AASM
  aasm_column :status
  aasm_initial_state :initial

  aasm_state :initial
  aasm_state :converting, :exit => :transcode
  aasm_state :transfering , :exit => :send_s3
   aasm_state :completed
   aasm_state :failed

  aasm_event :convert do
   transitions :from => [:initial], :to => :converting
    end

   aasm_event :transfer do
   transitions :from => [:converting], :to => :transfering
    end

   aasm_event :complete do
    transitions :from => [:transfering], :to => :completed
   end

    aasm_event :error do
     transitions :from => [:initial, :converting, :transfering, :completed]
     end

   has_attached_file :asset, 
     :path => "uploads/:attachment/:id.:basename.:extension"

     def flash_path
    return self.asset.path + '.flv'
    end

    def flash_name
      return File::basename(self.asset.path)# + '.flv'
     end

    def flash_url
    return "#{AWS_HOST}/#{AWS_BUCKET}/#{self.flash_name}"
   end

  # transcode file
   def transcode
     begin
    RVideo::Transcoder.logger = logger
     file = RVideo::Inspector.new(:file => self.asset.path)
  command = "ffmpeg -i $input_file$ -y -s $resolution$ -ar 44100 -b 64k -r 15 -sameq  $output_file$"
    options = {
    :input_file => "#{RAILS_ROOT}/#{self.asset.path}",
    :output_file => "#{RAILS_ROOT}/#{self.flash_path}",
    :resolution => "320x200" 
  }


  transcoder = RVideo::Transcoder.new
  transcoder.execute(command, options)
  rescue RVideo::TranscoderError => e
    logger.error "Encountered error transcoding #{self.asset.path}"
    logger.error e.message
  end
 end

The input file is added to the asset directory, but I never get an outputted file. On the view page aasm hangs on "converting".

+1  A: 

This might sound ridiculous, but what do your server logs say when it hangs? It's likely a server problem. In fact, it seems that rvideo needs alot of ram, so if you are running this on a shared host, or some slice that has only 256 ram or something you may need alot more.

Try running it in production mode on your development machine.

Joseph Silvashy
Well it works ok in production mode on my machine with mongrel. I have a 360 RAM linode going with passenger for the server.
maps
Well for this example the file is less than 1MB. I found the error message..Processing VideosController#create (for IP at 2010-03-19 14:25:06) [$ Parameters: {"commit"=>"Create", "action"=>"create", "authenticity_token"=>"b$[paperclip] Saving attachments.[paperclip] saving uploads/assets/1.HPIM0958.AVI[paperclip] Saving attachments.Encountered error uploading uploads/assets/1.HPIM0958.AVIffmpeg could not be found (expected ffmpeg to be found in the Unix path)spawn> child[12735] took 0.099789 secI think this is coming from the rvideo inspector.rb file.
maps