Class: Vidibus::Encoder::Base
- Inherits:
-
Object
- Object
- Vidibus::Encoder::Base
- 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
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
-
.registered_profiles ⇒ Object
Returns the value of attribute registered_profiles.
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
-
#tmp ⇒ Object
readonly
Returns the value of attribute tmp.
Class Method Summary collapse
-
.file_extension ⇒ Object
Define a default file extension for your encoder.
-
.profile_presets ⇒ Object
Fixed profile presets for this encoder.
-
.register_profile(name, settings) ⇒ Object
Register a profile with given name and settings.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
Initialize an encoder instance with given options.
-
#run ⇒ Object
Perform the encoding workflow.
Methods included from Helper::Flags
Methods included from Helper::Tools
Methods included from Helper::Base
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( = {}) = [:tmp, :input, :output, :profile, :profiles].each do |attribute| self.send("#{attribute}=", [attribute]) if [attribute] end end |
Class Attribute Details
.registered_profiles ⇒ Object
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
#input ⇒ Object (readonly)
Returns the value of attribute input.
26 27 28 |
# File 'lib/vidibus/encoder/base.rb', line 26 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/vidibus/encoder/base.rb', line 26 def end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
26 27 28 |
# File 'lib/vidibus/encoder/base.rb', line 26 def output @output end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
26 27 28 |
# File 'lib/vidibus/encoder/base.rb', line 26 def profile @profile end |
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
26 27 28 |
# File 'lib/vidibus/encoder/base.rb', line 26 def profiles @profiles end |
#tmp ⇒ Object (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_extension ⇒ Object
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_presets ⇒ Object
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
#run ⇒ Object
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 prepare profiles.sorted.each do |p| @profile = p next unless process? preprocess process postprocess end finish end |