Class: Paperclip::Waveform

Inherits:
Processor
  • Object
show all
Defined in:
lib/paperclip_processors/waveform.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Waveform

Returns a new instance of Waveform.



3
4
5
6
7
8
9
# File 'lib/paperclip_processors/waveform.rb', line 3

def initialize file, options = {}, attachment = nil
  super

  @basename = File.basename(file.path)
  @waveform_opts = options[:convert_options]
  @waveform_opts[:force] = true
end

Instance Method Details

#makeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/paperclip_processors/waveform.rb', line 11

def make
  wav = Tempfile.new [ @basename, '.wav']
  wav.binmode

  begin
    Paperclip.run("ffmpeg", "-y -i :source -f wav :dest", :source => "#{File.expand_path(file.path)}", :dest => File.expand_path(wav.path))
  rescue Cocaine::ExitStatusError => e
    raise Paperclip::Error, "error while processing wav for #{@basename}: #{e}"
  end

  png = Tempfile.new [ @basename, 'png' ]

  ::Waveform.generate wav, png, @waveform_opts

  png
end