Created
October 20, 2011 16:37
-
-
Save walterdavis/1301612 to your computer and use it in GitHub Desktop.
Convert MP3 to OGG during upload using Paperclip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
# Converts ogg audio for Firefox | |
class Ogg < Processor | |
attr_accessor :whiny | |
# Creates an Ogg from MP3 | |
def make | |
src = @file | |
dst = Tempfile.new([@basename, '.ogg']) | |
command = <<-end_command | |
- | |
"#{ File.expand_path(src.path) }" | |
| /usr/bin/oggenc - -o | |
"#{ File.expand_path(dst.path) }" | |
end_command | |
begin | |
success = Paperclip.run("/usr/bin/mpg321 -q -w", command.gsub(/\s+/, " ")) | |
Rails.logger.info "Converting #{src.path} to #{dst.path} in the Ogg processor." | |
rescue Cocaine::ExitStatusError => e | |
raise PaperclipError, "There was an error converting #{@basename}" if @whiny | |
end | |
dst | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment