class FFMPEG::RecorderOptions

@since 1.0.0-beta2

Constants

DEFAULT_FPS
DEFAULT_LOG_FILE

Public Class Methods

new(options) click to toggle source
# File lib/ffmpeg/recorder_options.rb, line 7
def initialize(options)
  TypeChecker.check options, Hash
  TypeChecker.check options[:advanced], Hash if options[:advanced]
  @options = verify_options options
end

Public Instance Methods

advanced() click to toggle source

Returns given values that are optional

# File lib/ffmpeg/recorder_options.rb, line 44
def advanced
  @options[:advanced]
end
all() click to toggle source

Returns all given options

# File lib/ffmpeg/recorder_options.rb, line 65
def all
  @options
end
format() click to toggle source

Returns given recording format

# File lib/ffmpeg/recorder_options.rb, line 16
def format
  determine_capture_device
end
framerate() click to toggle source

Returns given framerate

# File lib/ffmpeg/recorder_options.rb, line 23
def framerate
  @options[:framerate] || DEFAULT_FPS
end
input() click to toggle source

Returns given input file or input

# File lib/ffmpeg/recorder_options.rb, line 30
def input
  @options[:input]
end
log() click to toggle source

Returns given log filename

# File lib/ffmpeg/recorder_options.rb, line 51
def log
  @options[:log] || DEFAULT_LOG_FILE
end
log_level() click to toggle source

Returns given log_level

# File lib/ffmpeg/recorder_options.rb, line 58
def log_level
  @options[:log_level]
end
output() click to toggle source

Returns given output filepath

# File lib/ffmpeg/recorder_options.rb, line 37
def output
  @options[:output]
end
parsed() click to toggle source

Returns a String with all options parsed and ready for the ffmpeg process to use

# File lib/ffmpeg/recorder_options.rb, line 73
def parsed
  vals = "-f #{determine_capture_device} "
  vals << "-r #{@options[:framerate]} "
  vals << advanced_options if @options[:advanced]
  vals << "-i #{determine_input} "
  vals << @options[:output]
  vals << ffmpeg_log_to(@options[:log]) # If provided
end

Private Instance Methods

advanced_options() click to toggle source

Returns advanced options parsed and ready for ffmpeg to receive.

# File lib/ffmpeg/recorder_options.rb, line 107
def advanced_options
  return nil unless @options[:advanced]
  raise(ArgumentError, ':advanced cannot be empty.') if @options[:advanced].empty?

  arr = []
  @options[:advanced].each do |k, v|
    arr.push "-#{k} #{v}"
  end
  arr.join(' ') + ' '
end
determine_capture_device() click to toggle source

Returns capture device based on user given value or the current OS.

# File lib/ffmpeg/recorder_options.rb, line 149
def determine_capture_device
  return @options[:format] if @options[:format]

  if OS.windows?
    'gdigrab'
  elsif OS.linux?
    'x11grab'
  elsif OS.mac?
    'avfoundation'
  else
    raise NotImplementedError, 'Your OS is not supported.'
  end
end
determine_input() click to toggle source

Returns final input parameter. Adds title= qualifier to input parameter unless the user is recording the desktop.

# File lib/ffmpeg/recorder_options.rb, line 132
def determine_input
  # x11grab doesn't support window capture
  if OS.linux?
    return ':0.0' if @options[:input] == 'desktop'

    return @options[:input] # User given display number
  end

  return @options[:input] if @options[:input] == 'desktop'

  # Windows only
  %("title=#{@options[:input]}")
end
ffmpeg_log_to(file) click to toggle source

Returns logging command with user given log file from options or the default file.

# File lib/ffmpeg/recorder_options.rb, line 122
def ffmpeg_log_to(file)
  file ||= DEFAULT_LOG_FILE
  " 2> #{file}"
end
required_options() click to toggle source

Returns Array of required options sa Symbols

# File lib/ffmpeg/recorder_options.rb, line 100
def required_options
  %i[input output]
end
verify_options(options) click to toggle source

Verifies the required options are provided and returns the given options Hash. Raises ArgumentError if all required options are not present in the given Hash.

# File lib/ffmpeg/recorder_options.rb, line 89
def verify_options(options)
  missing_options = required_options.select { |req| options[req].nil? }
  err             = "Required options are missing: #{missing_options}"
  raise(ArgumentError, err) unless missing_options.empty?

  options
end