Ruby 关于 Rails 蜻蜓
Ruby on Rails Dragonfly
我有以下模型,它有一个访问器,可以接收 WAV 格式的音频文件,然后存储它
class Audio < ActiveRecord::Base
belongs_to :contribution
belongs_to :recorder
dragonfly_accessor :audio, :app_name => :videos do
storage_options do |audio|
{ path: "audios/#{audio.name}" }
end
end
end
我想做的是在保存之前将此音频从 WAV 转换为 MP3。
Dragonfly默认做不到,需要添加a custom processor and probably use some command line tool for it, here's a few examples
因此,如果您使用该线程的最高响应之一并使用 libav-tools,您的自定义处理器将看起来像这样(您可能还需要将 new_path 文件扩展名更改为 .mp_3):
processor :to_mp3 do |content|
content.shell_update do |old_path, new_path|
"avconv -i #{old_path} #{new_path}"
end
end
我有以下模型,它有一个访问器,可以接收 WAV 格式的音频文件,然后存储它
class Audio < ActiveRecord::Base
belongs_to :contribution
belongs_to :recorder
dragonfly_accessor :audio, :app_name => :videos do
storage_options do |audio|
{ path: "audios/#{audio.name}" }
end
end
end
我想做的是在保存之前将此音频从 WAV 转换为 MP3。
Dragonfly默认做不到,需要添加a custom processor and probably use some command line tool for it, here's a few examples
因此,如果您使用该线程的最高响应之一并使用 libav-tools,您的自定义处理器将看起来像这样(您可能还需要将 new_path 文件扩展名更改为 .mp_3):
processor :to_mp3 do |content|
content.shell_update do |old_path, new_path|
"avconv -i #{old_path} #{new_path}"
end
end