ruby on rails - Convert WAV into MP3 using FFMPG with the carrier_wave gem -
inside "wave_uploader.rb" script have following code:
class pictureuploader < carrierwave::uploader::base include carrierwave::minimagick include carrierwave::mimetypes version :wav process :convert_to_mp3 def convert_to_mp3 temp_path = tempfile.new([file.basename(current_path), '.mp3']).path `ffmpeg -t 15 -i #{current_path} -acodec libmp3lame -f mp3 #{temp_path}` file.unlink(current_path) fileutils.mv(temp_path, current_path) end def full_filename(for_file) super.chomp(file.extname(super)) + '.mp3' end end i trying convert wav file 20 second mp3 file , delete wav file once converted. code above runs can't find converted mp3 file guessing did not work correctly.
at end of wave_uploader.rb have code returns unique name once processed commented out code out thinking code below causing wav file not converted mp3.
# def filename # "#{secure_token}.#{file.extension}" if original_filename.present? # end # def secure_token # var = :"@#{mounted_as}_secure_token" # model.instance_variable_get(var) or model.instance_variable_set(var, securerandom.uuid) end any appreciated on how working right.
one thing see is:
`ffmpeg -t 15 -i #{current_path} -acodec libmp3lame -f mp3 #{temp_path}` if ffmpeg not in path os won't able find it, , return error, however, because you're using backticks, os can't return string stderr, error displayed. backticks return stdout.
to debug try command-line:
which ffmpeg if ffmpeg found, instead of:
`ffmpeg -t 15 -i #{current_path} -acodec libmp3lame -f mp3 #{temp_path}` try:
puts `which ffmpeg` and see output.
i suspect it's not in path, you'll have locate , provide full path on disk.
also, it's better move original file, move new file original file's name, delete original or leave ".bak" file. way original kept until code has processed:
fileutils.mv(current_path, current_path + '.bak') fileutils.mv(temp_path, current_path) file.unlink(current_path + '.bak') # <-- optional
Comments
Post a Comment