Class: VCSRuby::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video, capturer, time) ⇒ Frame

Returns a new instance of Frame.



12
13
14
15
16
17
# File 'lib/frame.rb', line 12

def initialize video, capturer, time
  @video = video
  @capturer = capturer
  @time = time
  @filters = []
end

Instance Attribute Details

#aspectObject

Returns the value of attribute aspect.



9
10
11
# File 'lib/frame.rb', line 9

def aspect
  @aspect
end

#filtersObject (readonly)

Returns the value of attribute filters.



10
11
12
# File 'lib/frame.rb', line 10

def filters
  @filters
end

#heightObject

Returns the value of attribute height.



9
10
11
# File 'lib/frame.rb', line 9

def height
  @height
end

#timeObject (readonly)

Returns the value of attribute time.



10
11
12
# File 'lib/frame.rb', line 10

def time
  @time
end

#widthObject

Returns the value of attribute width.



9
10
11
# File 'lib/frame.rb', line 9

def width
  @width
end

Instance Method Details

#apply_filtersObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/frame.rb', line 63

def apply_filters
  MiniMagick::Tool::Convert.new do |convert|
    convert.background 'Transparent'
    convert.fill 'Transparent'
    convert << filename

    sorted_filters.each do |filter|
      call_filter filter, convert
    end

    convert << filename
  end
end

#blank?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/frame.rb', line 56

def blank?
  image = MiniMagick::Image.open filename
  image.colorspace 'Gray'
  mean = image['%[fx:image.mean]'].to_f
  return mean < Configuration.instance.blank_threshold
end

#captureObject



36
37
38
# File 'lib/frame.rb', line 36

def capture
  @capturer.grab @time, filename
end

#capture_and_evade(interval = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/frame.rb', line 40

def capture_and_evade interval = nil
  times = [TimeIndex.new] + Configuration.instance.blank_alternatives
  if interval
    times.select! { |t| (t < interval / 2) and (t > interval / -2) }
  end
  times.map! { |t| @time + t }

  times.each do |time|
    @time = time
    capture
    break unless blank?
    puts "Blank frame detected. => #{@time}" unless Configuration.instance.quiet?
    puts "Giving up!" if time == times.last && !Configuration.instance.quiet?
  end
end

#filenameObject



24
25
26
# File 'lib/frame.rb', line 24

def filename
  File.join(@out_path, "#{@out_filename}.#{@capturer.format_extension}")
end

#filename=(file_path) ⇒ Object



19
20
21
22
# File 'lib/frame.rb', line 19

def filename= file_path
  @out_path = File.dirname(file_path)
  @out_filename = File.basename(file_path,'.*')
end

#formatObject



32
33
34
# File 'lib/frame.rb', line 32

def format
  @capturer.format
end

#format=(fmt) ⇒ Object



28
29
30
# File 'lib/frame.rb', line 28

def format= fmt
  @capturer.format = fmt
end