0
我想MP3文件的比特率轉換上傳到S3之前的FFmpeg處理後到S3,我能創造版本的MP3文件,但該版本沒有在S3中保存原來的文件正在上傳到S3。如何保存文件使用carrierwave
version :bitrate_96k do
process :resample => "96"
end
def resample(bitrate)
tmp_path = File.join(File.basename(current_path), "tmpfile")
File.rename current_path, tmp_path
audio_details = `ffmpeg -i '#{tmp_path}' 2>&1`.split(",").split("\n").flatten
file_bitrate = audio_details.grep(/bitrate/).grep(/bitrate/).join.split("bitrate: ").last.split("\s").first
unless file_bitrate == bitrate
`ffmpeg -i #{tmp_path.shellescape} -acodec libmp3lame -y -ab 96k #{current_path.path}`
File.unlink(current_path)
FileUtils.mv(temp_path, current_path)
end
end