Class: Paperclip::AudioCrop

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AudioCrop.



5
6
7
8
9
10
11
# File 'lib/paperclip_processors/audio_crop.rb', line 5

def initialize file, options = {}, attachment = nil
  super
  @offset = options[:offset]
  @duration = options[:duration]
  @current_format = File.extname(@file.path)
  @basename = File.basename(file.path)
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



3
4
5
# File 'lib/paperclip_processors/audio_crop.rb', line 3

def duration
  @duration
end

#offsetObject

Returns the value of attribute offset.



3
4
5
# File 'lib/paperclip_processors/audio_crop.rb', line 3

def offset
  @offset
end

Instance Method Details

#makeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/paperclip_processors/audio_crop.rb', line 13

def make
  src = @file
  dst = Tempfile.new([@basename, @current_format])
  dst.binmode
  begin
    success = Paperclip.run("ffmpeg -y -ss #{@offset} -t #{@duration} -i #{src.path} -acodec copy #{dst.path}")
  rescue PaperclipCommandLineError => e
    raise Paperclip::Error, "error while processing audio for #{@file}: #{e}"
  end
  dst
end