我正在使用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
输入文件被添加到资产目录中,但我从未获得输出文件。在视图页面上,aasm挂起“转换”。
答案 0 :(得分:1)
这可能听起来很荒谬,但是你的服务器日志挂起时会说些什么呢?这可能是服务器问题。事实上,似乎rvideo
需要很多ram,所以如果你在共享主机上运行它,或者只有256 ram或者某些东西,你可能需要更多。
尝试在开发计算机上以生产模式运行它。