Class: Vidibus::Encoder::Base

Inherits:
Object
  • Object
show all
Extended by:
Helper::Flags
Includes:
Helper::Base, Helper::Tools
Defined in:
lib/vidibus/encoder/base.rb

Overview

This is the main encoder that you can build your own encoders on.

The workflow of an encoder is as follows:

initialize run

validate_options
prepare
=> for each profile:
  next unless process?
  preprocess
  process
  postprocess
finish

Each step of the workflow is represented by a method that you may redefine in your custom encoder class.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper::Flags

extended, flag

Methods included from Helper::Tools

#matching_frame_rate

Methods included from Helper::Base

#logger, #uuid

Constructor Details

#initialize(options = {}) ⇒ Base

Initialize an encoder instance with given options. Two options are mandatory:

:input [String] The path to the input file :output [String] The path to the output file or directory

You may define one or several profiles to perform. If you provide a hash, all profile settings required for your recipe must be included.

:profile [Hash] The configuration hash of one profile :profiles [Hash] Hashes of several profiles with namespace

Single profile example:

:profile => {
  :video_bit_rate => 110000,
  :dimensions => '240x160'
}

Multi-profile example:

:profiles => {
  :low => {
    :video_bit_rate => 110000,
    :dimensions => '240x160'
  },
  :high => {
    :video_bit_rate => 800000,
    :dimensions => '600x400'
  }
}

If you have registered profiles for your encoder, you may refer to one or several profiles by providing its name. Without a profile, the default one will be performed. To register a profile, call YourEncoder.register_profile

:profile [Symbol] The name of one profile :profiles [Array] A list of profile names



69
70
71
72
73
74
75
# File 'lib/vidibus/encoder/base.rb', line 69

def initialize(options = {})
  @options = options
  [:tmp, :input, :output, :profile, :profiles].each do |attribute|
    self.send("#{attribute}=", options[attribute]) if options[attribute]
  end
  set_default_options
end

Class Attribute Details

.registered_profilesObject

Returns the value of attribute registered_profiles.



118
119
120
# File 'lib/vidibus/encoder/base.rb', line 118

def registered_profiles
  @registered_profiles
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def options
  @options
end

#outputObject (readonly)

Returns the value of attribute output.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def output
  @output
end

#profileObject (readonly)

Returns the value of attribute profile.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def profile
  @profile
end

#profilesObject (readonly)

Returns the value of attribute profiles.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def profiles
  @profiles
end

#tmpObject (readonly)

Returns the value of attribute tmp.



26
27
28
# File 'lib/vidibus/encoder/base.rb', line 26

def tmp
  @tmp
end

Class Method Details

.file_extensionObject

Define a default file extension for your encoder. Or define one in a profile configuration.



115
# File 'lib/vidibus/encoder/base.rb', line 115

def self.file_extension; end

.profile_presetsObject

Fixed profile presets for this encoder. You may define profile presets inside your encoder class.

When defining settings, you should define a :default setting as well to support single profile encodings. An example:

{
  :low => {
    :video_bit_rate => 110000,
    :dimensions => '240x160'
  },
  :high => {
    :video_bit_rate => 800000,
    :dimensions => '600x400'
  }
}.tap do |p|
  p[:default] = p[:high]
end


111
# File 'lib/vidibus/encoder/base.rb', line 111

def self.profile_presets; end

.register_profile(name, settings) ⇒ Object

Register a profile with given name and settings.



122
123
124
# File 'lib/vidibus/encoder/base.rb', line 122

def register_profile(name, settings)
  @registered_profiles[name] = settings
end

Instance Method Details

#runObject

Perform the encoding workflow. All profiles will be performed in order. Lowest bit_rate first.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vidibus/encoder/base.rb', line 79

def run
  validate_options
  prepare
  profiles.sorted.each do |p|
    @profile = p
    next unless process?
    preprocess
    process
    postprocess
  end
  finish
end