ruby-on-rails - 功能在生产模式下不起作用

标签 ruby-on-rails

我正在使用 rvideo gem 将文件转码为 .flv 格式。

  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

输入文件已添加到 Assets 目录,但我从未得到输出文件。在 View 页面上,aasm 卡在“正在转换”上。

最佳答案

这听起来可能很荒谬,但是当它挂起时,您的服务器日志会说什么?很可能是服务器问题。其实好像rvideo需要很多内存,所以如果你在共享主机上运行它,或者一些只有 256 内存的切片或其他东西,你可能需要更多。

尝试在您的开发机器上以生产模式运行它。

关于ruby-on-rails - 功能在生产模式下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2474580/

相关文章:

ruby-on-rails - 动态根路径路由

ruby-on-rails - Rails ActiveRecord : Pluck from multiple tables with same column name

ruby-on-rails - Rails 测试套件中显示的数据库调用

ruby-on-rails - crontab + rails3 + bundler

ruby-on-rails - 查找没有关联或关联属性值 !=? 的记录

ruby-on-rails - ActiveRecord :inverse_of does not work on has_many :through on the join model on create

ruby-on-rails - Rails 声誉系统

ruby-on-rails - RVM 的 Rails 脚本段错误

ruby-on-rails - Rails : What is an API's endpoint?

ruby-on-rails - Rails rake 测试返回错误消息