Declare encode job classes that can be run by a variety of encoding services
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
db/migrate
lib
spec
.coveralls.yml
.gitignore
.rubocop.yml
.travis.yml
CONTRIBUTING.md
Gemfile
LICENSE
README.md
Rakefile
active_encode.gemspec

README.md

ActiveEncode

This gem serves as the basis for the interface between a Ruby (Rails) application and a provider of transcoding services such as Opencast Matterhorn, Zencoder, and Amazon Elastic Transcoder.

Installation

Add this line to your application's Gemfile:

gem 'active_encode'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_encode

Usage

Set the engine adapter (default: test), configure it (if neccessary), then submit encoding jobs!

ActiveEncode::Base.engine_adapter = :matterhorn
ActiveEncode::Base.create(File.open('spec/fixtures/Bars_512kb.mp4'))

Create returns an encoding job that has been submitted to the encoding engine for processing. At this point it will have an id, a state, the input, and any additional information the encoding engine returns.

#<ActiveEncode::Base:0x00000003f3cd90 @input="http://localhost:8080/files/mediapackage/edcac316-1f98-44b1-88ca-0ce6f80aebc0/ff43c56f-7b8f-4d9c-a846-6e51de2e8cb4/Bars_512kb.mp4", @options={:preset=>"avalon", :stream_base=>"file:///home/cjcolvar/Code/avalon/avalon/red5/webapps/avalon/streams"}, @id="12154", @state=:running, @current_operations=[], @percent_complete=0.0, @output=[], @errors=[], @tech_metadata={}>
encode.id  # "12103"
encode.state  # :running

This encode can be looked back up later using #find. Alternatively, use #reload to refresh an instance with the latest information from the

encode = ActiveEncode::Base.find("12103")
encode.reload

Progress of a running encode is shown with a current operation (multiple possible if outputs are generated in parallel) and percent complete. Technical metadata about the input file is added by the encoding engine. This should include a mime type, checksum, duration, and basic technical details of the audio and video content of the file (codec, audio channels, bitrate, framerate, and dimensions). Outputs are added once they are created and should include the same technical metadata along with an id, label, and url.

If the encoding job should be stopped, call cancel:

encode.cancel!
encode.cancelled?  # true

An encoding job is meant to be the record of the work of the encoding engine and not the current state of the outputs. Therefore removed outputs will not be reflected in the encoding job.

Custom jobs

Subclass ActiveEncode::Base to add custom callbacks or default options. Available callbacks are before, after, and around the create and cancel actions.

class CustomEncode < ActiveEncode::Base
  after_create do
    logger.info "Created encode with id #{self.reload.id}"
  end

  def self.default_options(input)
    {preset: 'avalon-skip-transcoding'}
  end
end

Engine Adapters

Engine adapters are shims between ActiveEncode and the back end encoding service. Each service has its own API and idiosyncracies so consult the table below to see what features are supported by each adapter. Add an additional engines by creating an engine adapter class that implements :create, :find, and :cancel.

Adapter/Feature Create Find Cancel Preset Multiple Outputs
Test X X X
AWS Elastic Transcoder X X X
Zencoder X X X
Matterhorn X X X X X

Contributing

  1. Fork it ( https://github.com/projecthydra-labs/active_encode/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request