class FFMPEG::RecorderOptions
@since 1.0.0-beta2
Constants
- DEFAULT_FPS
- DEFAULT_LOG_FILE
Public Class Methods
# 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
Returns given values that are optional
# File lib/ffmpeg/recorder_options.rb, line 44 def advanced @options[:advanced] end
Returns all given options
# File lib/ffmpeg/recorder_options.rb, line 65 def all @options end
Returns given recording format
# File lib/ffmpeg/recorder_options.rb, line 16 def format determine_capture_device end
Returns given framerate
# File lib/ffmpeg/recorder_options.rb, line 23 def framerate @options[:framerate] || DEFAULT_FPS end
Returns given input file or input
# File lib/ffmpeg/recorder_options.rb, line 30 def input @options[:input] end
Returns given log filename
# File lib/ffmpeg/recorder_options.rb, line 51 def log @options[:log] || DEFAULT_LOG_FILE end
Returns given log_level
# File lib/ffmpeg/recorder_options.rb, line 58 def log_level @options[:log_level] end
Returns given output filepath
# File lib/ffmpeg/recorder_options.rb, line 37 def output @options[:output] end
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
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
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
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
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
Returns Array of required options sa Symbols
# File lib/ffmpeg/recorder_options.rb, line 100 def required_options %i[input output] end
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