Class: VCSRuby::Frame
- Inherits:
-
Object
- Object
- VCSRuby::Frame
- Defined in:
- lib/frame.rb
Instance Attribute Summary collapse
-
#aspect ⇒ Object
Returns the value of attribute aspect.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#height ⇒ Object
Returns the value of attribute height.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #apply_filters ⇒ Object
- #blank? ⇒ Boolean
- #capture ⇒ Object
- #capture_and_evade(interval = nil) ⇒ Object
- #filename ⇒ Object
- #filename=(file_path) ⇒ Object
- #format ⇒ Object
- #format=(fmt) ⇒ Object
-
#initialize(video, capturer, time) ⇒ Frame
constructor
A new instance of Frame.
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
#aspect ⇒ Object
Returns the value of attribute aspect.
9 10 11 |
# File 'lib/frame.rb', line 9 def aspect @aspect end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
10 11 12 |
# File 'lib/frame.rb', line 10 def filters @filters end |
#height ⇒ Object
Returns the value of attribute height.
9 10 11 |
# File 'lib/frame.rb', line 9 def height @height end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
10 11 12 |
# File 'lib/frame.rb', line 10 def time @time end |
#width ⇒ Object
Returns the value of attribute width.
9 10 11 |
# File 'lib/frame.rb', line 9 def width @width end |
Instance Method Details
#apply_filters ⇒ Object
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
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 |
#capture ⇒ Object
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 |
#filename ⇒ Object
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 |
#format ⇒ Object
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 |