Class: Vidibus::Encoder::Util::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/vidibus/encoder/util/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Profile

Returns a new instance of Profile.



7
8
9
10
11
# File 'lib/vidibus/encoder/util/profile.rb', line 7

def initialize(options = {})
  @name = options[:name]
  @settings = options[:settings] || {}
  @base = options[:base]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *arguments) ⇒ Object (private)

Try to return value from settings hash. Return nil if setting is undefined or nil.



108
109
110
111
112
113
114
115
# File 'lib/vidibus/encoder/util/profile.rb', line 108

def method_missing(sym, *arguments)
  if settings && value = settings[sym]
    value
  # elseif TODO: check if it's a setter
  else
    nil
  end
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



5
6
7
# File 'lib/vidibus/encoder/util/profile.rb', line 5

def base
  @base
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/vidibus/encoder/util/profile.rb', line 5

def name
  @name
end

#settingsObject

Returns the value of attribute settings.



5
6
7
# File 'lib/vidibus/encoder/util/profile.rb', line 5

def settings
  @settings
end

Instance Method Details

#aspect_ratio(modulus = 1) ⇒ String

Return the aspect ratio of width to height as string like “16:9”. Define a modulus attribute to adjust dimensions.

Returns:

  • (String)

    The dimensions



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vidibus/encoder/util/profile.rb', line 88

def aspect_ratio(modulus = 1)
  @aspect_ratio ||= settings[:aspect_ratio] ||= begin
    w = width(modulus)
    h = height(modulus)
    if w > 0 && h > 0
      w/h.to_f
    else
      1
    end
  end
end

#attributesObject

Return a list of all profile attributes including the given settings.



28
29
30
# File 'lib/vidibus/encoder/util/profile.rb', line 28

def attributes
  @attributes ||= (settings.keys.map(&:to_s) + %w[width height dimensions]).sort.uniq
end

#bit_rateObject

Sum up audio and video bit_rate unless bit_rate has been defined in settings.



15
16
17
# File 'lib/vidibus/encoder/util/profile.rb', line 15

def bit_rate
  settings[:bit_rate] || audio_bit_rate.to_i + video_bit_rate.to_i
end

#dimensions(modulus = 1) ⇒ String

Return dimensions. If wanted dimensions exceed the input’s ones, they will be scaled down.

Define a modulus attribute to adjust dimensions. For best encoding results, the modulus should be 16. 8, 4, and even 2 will also work, but image quality increases with higher numbers because compression works better.

Returns:

  • (String)

    The dimensions



75
76
77
78
79
80
# File 'lib/vidibus/encoder/util/profile.rb', line 75

def dimensions(modulus = 1)
  @dimensions ||= {}
  @dimensions[modulus] = begin
    "#{width(modulus)}x#{height(modulus)}"
  end
end

#file_extensionObject



100
101
102
# File 'lib/vidibus/encoder/util/profile.rb', line 100

def file_extension
  @file_extension ||= settings[:file_extension] || base.class.file_extension || raise(ProfileError, 'Define a file extension for this profile')
end

#height(modulus = 1) ⇒ Integer

Return the height. If the wanted height exceeds the input’s one, it will be scaled down.

Define a modulus attribute to adjust dimensions. For best encoding results, the modulus should be 16. 8, 4, and even 2 will also work, but image quality increases with higher numbers because compression works better.

Returns:

  • (Integer)

    The height



59
60
61
62
# File 'lib/vidibus/encoder/util/profile.rb', line 59

def height(modulus = 1)
  @height ||= {}
  @height[modulus] = dim(:height, modulus)
end

#validateObject

Ensure that all required attribtues have been set.

Raises:



20
21
22
23
24
# File 'lib/vidibus/encoder/util/profile.rb', line 20

def validate
  raise(ProfileError, 'Define a name for this profile') if [nil, ''].include?(name)
  raise(ProfileError, 'Define a settings hash for this profile') unless settings.is_a?(Hash) && settings.any?
  raise(ProfileError, 'Define an encoder class for this profile') unless base
end

#width(modulus = 1) ⇒ Integer

Return the width. If the wanted width exceeds the input’s one, it will be scaled down.

Define a modulus attribute to adjust dimensions. For best encoding results, the modulus should be 16. 8, 4, and even 2 will also work, but image quality increases with higher numbers because compression works better.

Returns:

  • (Integer)

    The width



43
44
45
46
# File 'lib/vidibus/encoder/util/profile.rb', line 43

def width(modulus = 1)
  @width ||= {}
  @width[modulus] = dim(:width, modulus)
end