2013-09-23 2 views
0

내가 MP3 파일의 비트 레이트를 변환하려고를 사용 FFmpeg에 의해 처리 후 (S3)에 파일을 저장하는 방법, 나는 MP3 파일 버전을 수 만들 수 있지만 버전 (S3)에 저장되지 않는다 대신 원본 파일이 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

당신이 File.unlink는 96K 출력이 아닌 입력을 보내고있는 것처럼 보이는 내 머리에 resample을 통해 스테핑, 다음은 해제 변환 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) 

관련 문제