Class: VideoScreenshoter::Image

Inherits:
Abstract
  • Object
show all
Defined in:
lib/video_screenshoter/image.rb

Instance Attribute Summary

Attributes inherited from Abstract

#duration, #exact, #ffmpeg, #imagemagick, #input, #offset_end, #offset_start, #output_dir, #output_file, #presets, #size, #times, #verbose

Instance Method Summary collapse

Methods inherited from Abstract

#ffmpeg_command, #ffmpeg_run, #imagemagick_command, #imagemagick_run, #output_fullpath, #output_with_preset

Constructor Details

#initialize(params) ⇒ Image

Returns a new instance of Image.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/video_screenshoter/image.rb', line 6

def initialize params
  params.each_with_index do |param, index|
    params[index] = Shellwords.escape(param) if param.is_a?(String)
  end
  [:ffmpeg, :imagemagick, :output_dir, :output_file, :verbose].each do |attr|
    self.send("#{attr}=".to_sym, params[attr].nil? ? VideoScreenshoter.send(attr) : params[attr])
  end
  FileUtils.mkdir_p self.output_dir
  self.input = params[:input]
  if params[:presets] && params[:presets].is_a?(Hash)
    self.presets = {}
    params[:presets].each do |name, preset|
      self.presets[name.to_sym] = !preset || preset.empty? || preset.index('-') == 0 ? preset : "-resize #{preset}"
    end
  end
  raise ArgumentError.new('Presets are needed') if presets.nil? || presets.empty?
end

Instance Method Details

#runObject Also known as: make_screenshots, make_thumbnails



24
25
26
27
# File 'lib/video_screenshoter/image.rb', line 24

def run
  imagemagick_run input
  Hash[*presets.keys.map { |p| [p, output_with_preset(input, p)] }.flatten]
end