Parent

Class/Module Index [+]

Quicksearch

Headless::VideoRecorder

Attributes

log_file_path[RW]
pid_file_path[RW]
tmp_file_path[RW]

Public Class Methods

new(display, dimensions, options = {}) click to toggle source
# File lib/headless/video/video_recorder.rb, line 7
def initialize(display, dimensions, options = {})
  CliUtil.ensure_application_exists!('ffmpeg', 'Ffmpeg not found on your system. Install it with sudo apt-get install ffmpeg')

  @display = display
  @dimensions = dimensions

  @pid_file_path = options.fetch(:pid_file_path, "/tmp/.headless_ffmpeg_#{@display}.pid")
  @tmp_file_path = options.fetch(:tmp_file_path, "/tmp/.headless_ffmpeg_#{@display}.mov")
  @log_file_path = options.fetch(:log_file_path, "/dev/null")
  @codec = options.fetch(:codec, "qtrle")
  @frame_rate = options.fetch(:frame_rate, 30)
end

Public Instance Methods

capture_running?() click to toggle source
# File lib/headless/video/video_recorder.rb, line 20
def capture_running?
  CliUtil.read_pid @pid_file_path
end
start_capture() click to toggle source
# File lib/headless/video/video_recorder.rb, line 24
def start_capture
  CliUtil.fork_process("#{CliUtil.path_to('ffmpeg')} -y -r #{@frame_rate} -g 600 -s #{@dimensions} -f x11grab -i :#{@display} -vcodec #{@codec} #{@tmp_file_path}", @pid_file_path, @log_file_path)
  at_exit do
    exit_status = $!.status if $!.is_a?(SystemExit)
    stop_and_discard
    exit exit_status if exit_status
  end
end
stop_and_discard() click to toggle source
# File lib/headless/video/video_recorder.rb, line 44
def stop_and_discard
  CliUtil.kill_process(@pid_file_path, :wait => true)
  begin
    FileUtils.rm(@tmp_file_path)
  rescue Errno::ENOENT
    # that's ok if the file doesn't exist
  end
end
stop_and_save(path) click to toggle source
# File lib/headless/video/video_recorder.rb, line 33
def stop_and_save(path)
  CliUtil.kill_process(@pid_file_path, :wait => true)
  if File.exists? @tmp_file_path
    begin
      FileUtils.mv(@tmp_file_path, path)
    rescue Errno::EINVAL
      nil
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.