Class: Lolcommits::CaptureLinux

Inherits:
Capturer
  • Object
show all
Defined in:
lib/lolcommits/capture_linux.rb

Instance Attribute Summary

Attributes inherited from Capturer

#animated_duration, #capture_delay, #capture_device, #font, #frames_location, #snapshot_location, #video_location

Instance Method Summary collapse

Methods inherited from Capturer

#initialize

Constructor Details

This class inherits a constructor from Lolcommits::Capturer

Instance Method Details

#captureObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lolcommits/capture_linux.rb', line 8

def capture
  debug 'LinuxCapturer: making tmp directory'
  tmpdir = Dir.mktmpdir

  # Default delay is 1s
  delay = if capture_delay != 0 then capture_delay else 1 end

  # There's no way to give a capture delay in mplayer, but a number of frame
  # mplayer's "delay" is actually a number of frames at 25fps
  # multiply the set value (in seconds) by 25
  frames = delay.to_i * 25

  debug 'LinuxCapturer: calling out to mplayer to capture image'
  # mplayer's output is ugly and useless, let's throw it away
  _, r, _ = Open3.popen3("#{executable_path} -vo jpeg:outdir=#{tmpdir} #{capture_device_string} -frames #{frames} tv://")
  # looks like we still need to read the output for something to happen
  r.read

  # the below SHOULD tell FileUtils actions to post their output if we are in debug mode
  include FileUtils::Verbose if logger.level == 0

  debug 'LinuxCapturer: calling out to mplayer to capture image'
  FileUtils.mv(tmpdir + '/%08d.jpg' % frames, snapshot_location)
  debug 'LinuxCapturer: cleaning up'
  FileUtils.rm_rf(tmpdir)
end

#capture_device_stringObject



4
5
6
# File 'lib/lolcommits/capture_linux.rb', line 4

def capture_device_string
  @capture_device.nil? ? nil : "-tv device=\"#{@capture_device}\""
end

#executable_pathObject



35
36
37
# File 'lib/lolcommits/capture_linux.rb', line 35

def executable_path
  'mplayer'
end