Sha256: c5cdc9a54e56333b30be929cfb3b2acc834e38386815c66213a967d288114933
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
require 'rvideo' require 'logger' module Paperclip class VideoThumbnail < Processor attr_accessor :time_offset, :geometry, :whiny 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 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
merrycms-0.1.7 | lib/paperclip_processors/video_thumbnail.rb |
merrycms-0.1.4 | lib/paperclip_processors/video_thumbnail.rb |