2
所以我试图用Paperclip自定义处理器和ffmpeg将mp3文件转换为.flac。以下代码运行ffmpeg命令并创建临时flac文件。但是,它没有保存?目前只有原始文件被保存。我在这里错过了什么?如何使用回形针为Ruby on Rails(5)创建音频文件的自定义处理器
class AudioFile < ApplicationRecord
has_attached_file :raw_audio, processors: [:custom], styles: { original: {}}
定制处理器
module Paperclip
class Custom < Processor
def initialize(file, options = {}, attachment = nil)
super
@file = file
@basename = File.basename(@file.path)
@format = options[:format] || 'flac'
@params = options[:params] || '-y -i'
end
def make
source = @file
output = Tempfile.new([@basename, ".#{@format}"])
begin
parameters = [@params, ':source',':dest'].join(' ')
Paperclip.run('ffmpeg', parameters, :source => File.expand_path(source.path), :dest => File.expand_path(output.path), :sample_rate => @sample_rate, :bit_rate => @bit_rate)
end
output
end
end
end
'mp3 into .flac' - 试图从有损到无损=不可能。不。这就像是拍摄一张100 x 100像素的图像并将其大小调整为1000 x 1000. –
它比扩展音频的质量更重要。我正在使用仅接受flac或原始音频的google语音api –
您的Paperclip配置中是否包含'log_command:true'?即使没有,请检查您的日志是否有错误。 – Eric