Sha256: 26fa9825588b7cc9f17fc59ed607326ffbca0a48c47eaa832198572abc21b70e

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

module Lolcommits
  class CaptureLinux < Capturer
    MPLAYER_FPS = 25

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

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

      # Default delay is 1s
      delay = capture_delay != 0 ? capture_delay : 1

      # 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 25 fps
      # multiply the set value (in seconds) by 25
      frames = delay.to_i * MPLAYER_FPS

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

      debug 'LinuxCapturer: calling out to mplayer to capture image'

      # get last frame from tmpdir (regardless of fps)
      all_frames = Dir.glob("#{tmpdir}/*.jpg").sort_by do |f|
        File.mtime(f)
      end

      if all_frames.empty?
        debug 'LinuxCapturer: failed to capture any image'
      else
        FileUtils.mv(all_frames.last, snapshot_location)
        debug 'LinuxCapturer: cleaning up'
      end

      FileUtils.rm_rf(tmpdir)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lolcommits-0.12.1 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.12.0 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.11.0 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.11.0.pre lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.10.0 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.10.0.pre1 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.8 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.7 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.7.pre1 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.6 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.5 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.5.pre1 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.4 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.4.pre1 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.3 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.3.pre3 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.3.pre2 lib/lolcommits/capturer/capture_linux.rb
lolcommits-0.9.3.pre1 lib/lolcommits/capturer/capture_linux.rb