Class: Paperclip::VideoThumbnail

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of VideoThumbnail.



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

def initialize(file, options = {}, attachment = nil)
  super
  @time_offset = options[:time_offset] || '-4'
  
  logger = Logger.new(STDOUT)
  
  logger.debug("FILE : #{file.inspect}")
  logger.debug("FILE PATH : #{file.path}")
  
  video = RVideo::Inspector.new(:file => file.path)
  logger.debug("VIDEO : #{video.inspect}")
  logger.debug("VIDEO WIDTH : #{video.width}")
  
  @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/video_thumbnail.rb', line 7

def geometry
  @geometry
end

#time_offsetObject

Returns the value of attribute time_offset.



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

def time_offset
  @time_offset
end

#whinyObject

Returns the value of attribute whiny.



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

def whiny
  @whiny
end

Instance Method Details

#makeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/paperclip_processors/video_thumbnail.rb', line 26

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