Module: ScreenRecorder::Screenshot Private

Included in:
Desktop, Window
Defined in:
lib/screen-recorder/screenshot.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

All screenshot related code

Since:

  • 1.0.0-beta11

Instance Method Summary collapse

Instance Method Details

#screenshot(filename, resolution = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Takes a screenshot in the current context (input) - desktop or current window

Since:

  • 1.0.0-beta11



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/screen-recorder/screenshot.rb', line 7

def screenshot(filename, resolution = nil)
  ScreenRecorder.logger.debug "Screenshot filename: #{filename}, resolution: #{resolution}"
  cmd = screenshot_cmd(filename: filename, resolution: resolution)
  process = execute_command(cmd)
  exit_code = wait_for_process_exit(process) # 0 (success) or 1 (fail)
  if exit_code&.zero?
    ScreenRecorder.logger.info "Screenshot: #{filename}"
    return filename
  end
  ScreenRecorder.logger.error 'Failed to take a screenshot.'
  nil
end

#screenshot_cmd(filename:, resolution: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters to capture a single frame

Since:

  • 1.0.0-beta11



23
24
25
26
27
# File 'lib/screen-recorder/screenshot.rb', line 23

def screenshot_cmd(filename:, resolution: nil)
  resolution = resolution ? resolution_arg(resolution) : nil
  # -f overwrites existing file
  "#{ffmpeg_bin} -f #{options.capture_device} -i #{options.input} -framerate 1 -frames:v 1 #{resolution}#{filename}"
end