Sha256: caf402d29835d179fd286774b86160ca97567857996ca07c1332545cb312ca46

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'rvideo'
require 'logger'

module Paperclip
  class Poster < Processor

    attr_accessor :time_offset, :geometry, :whiny

    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

    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/poster.rb
merrycms-0.1.4 lib/paperclip_processors/poster.rb