Class: Mediakit::FFmpeg::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mediakit/ffmpeg/options.rb

Overview

presentation of ffmpeg runners option

SYNOPSIS ffmpeg [global_options] -i input_file … output_file …

Defined Under Namespace

Classes: GlobalOption, InputFileOption, OptionPathPair, OrderedHash, OutputFileOption, QuoteString, StreamSpecifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options.

Parameters:

  • [Mediakit::FFmpeg::Options::GlobalOption] (Hash)

    a customizable set of options

  • [Mediakit::FFmpeg::Options::InputFileOption] (Hash)

    a customizable set of options

  • [Mediakit::FFmpeg::Options::OutputFileOption] (Hash)

    a customizable set of options



16
17
18
19
20
21
# File 'lib/mediakit/ffmpeg/options.rb', line 16

def initialize(*args)
  @global, @inputs, @output = nil, [], nil
  args.each do |option|
    add_option(option)
  end
end

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



11
12
13
# File 'lib/mediakit/ffmpeg/options.rb', line 11

def global
  @global
end

#inputsObject (readonly)

Returns the value of attribute inputs.



11
12
13
# File 'lib/mediakit/ffmpeg/options.rb', line 11

def inputs
  @inputs
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/mediakit/ffmpeg/options.rb', line 11

def output
  @output
end

Instance Method Details

#add_option(option) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mediakit/ffmpeg/options.rb', line 23

def add_option(option)
  return if option.nil?
  case option
  when GlobalOption
    raise(ArgumentError, 'you can give only a GlobalOption.') if @global
    set_global(option)
  when InputFileOption
    add_input(option)
  when OutputFileOption
    raise(ArgumentError, 'you can give only a OutputFileOption.') if @output
    set_output(option)
  else
    raise(ArgumentError)
  end
end

#compose(default_global = GlobalOption.new) ⇒ Object Also known as: to_s



39
40
41
42
43
44
45
46
# File 'lib/mediakit/ffmpeg/options.rb', line 39

def compose(default_global = GlobalOption.new)
  merged_global = global ? default_global.merge(global) : default_global
  composed_string = ''
  composed_string << "#{merged_global}"
  composed_string << " #{inputs.map(&:compose).join(' ')}" if inputs && !inputs.empty?
  composed_string << " #{output}" if output
  composed_string
end