2016-11-11 2 views
2

그래서 mp3 파일을 Paperclip 사용자 정의 프로세서 및 ffmpeg로 .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 
+0

'mp3 into .flac' - 손실에서 무손실로 = 시도 불가능 함. 아니. 이것은 100 x 100 픽셀의 이미지를 1000 x 1000 크기로 조정하는 것과 같습니다. –

+0

오디오의 품질보다 확장 정도가 더 중요합니다. 나는 단지 flac이나 raw audio만을 받아들이는 google speech api를 사용하고있다. –

+0

Paperclip 설정에'log_command : true'가 있습니까? 그렇지 않더라도 로그에 오류가 없는지 확인하십시오. – Eric

답변

0

달렸다. 당신은 직접적으로는 FFmpeg를 사용할 수 있습니다

`ffmpeg -i <original_file_path.mp3> <new_file_path.flac>` 

은 당신이 할 수있는 다양한 일이있다합니다 (역 따옴표를주의) (구글 음성 API의 경우에 필요).

그렇지 않으면 API는하지 않습니다

`ffmpeg -i file.mp3 -map_channel 0.0.0 left_file.flac -map_channel 0.0.1 right_file.flac` 

: 당신은 스테레오 mp3 파일이있는 경우 모노 하나

압축 할 필요 해요 :

`ffmpeg -i file.mp3 -ac 1 file_mono.flac` 

또는 채널을 분할 그것을 받아 들인다.