2013-09-23 53 views
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 

回答

0

在我的腦海步進通過resample它看起來就像你File.unlink荷蘭國際集團的96K輸出,而不是輸入,然後你複製未轉換tmp_file回的current_path。嘗試改變:

File.unlink(current_path) 
    FileUtils.mv(tmp_path, current_path) 

File.unlink(tmp_path) 
else 
    FileUtils.mv(tmp_path, current_path)