Class: Paperclip::Poster

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Poster.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/paperclip_processors/poster.rb', line 9

def initialize(file, options = {}, attachment = nil)
  super
  @time_offset = options[:time_offset] || '-4'
  @instance = attachment.instance
        
  @video = RVideo::Inspector.new(:file => file.path)
  @instance.width = @video.width
  @instance.height = @video.height
  
  @whiny = options[:whiny].nil? ? true : options[:whiny]
  @basename = File.basename(file.path, File.extname(file.path))
end

Instance Attribute Details

#geometryObject

Returns the value of attribute geometry.



7
8
9
# File 'lib/paperclip_processors/poster.rb', line 7

def geometry
  @geometry
end

#time_offsetObject

Returns the value of attribute time_offset.



7
8
9
# File 'lib/paperclip_processors/poster.rb', line 7

def time_offset
  @time_offset
end

#whinyObject

Returns the value of attribute whiny.



7
8
9
# File 'lib/paperclip_processors/poster.rb', line 7

def whiny
  @whiny
end

Instance Method Details

#makeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/paperclip_processors/poster.rb', line 22

def make
  dst = Tempfile.new([ @basename, 'jpg' ].compact.join("."))
  dst.binmode

  cmd = %Q[-itsoffset #{time_offset} -i "#{File.expand_path(file.path)}" -y -vcodec mjpeg -vframes 1 -an -f rawvideo ]
  cmd << "-s #{@video.resolution} " if @video && @video.resolution
  cmd << %Q["#{File.expand_path(dst.path)}"]

  begin
    success = Paperclip.run('ffmpeg', cmd)
  rescue PaperclipCommandLineError
    raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if whiny
  end
  dst
end