UEncode

A Ruby gem to interact with the uEncode API. This extends the work of Cássio Marques.

Creating a job

require 'uencode'

# In Rails you can put this inside an initializer
UEncode.configure do |c|
  c.customer_key = "your_uencode_api_key"
end


#create job and set source video
job = UEncode::Job.new :userdata => "AnyDataUsefulToYou", :callback => "Your Email Address or Callack Url", :source_video => {:url => "http://your.source.url/foo.flv", :timeout => 600}

#create configuration for a video output
configuration = {:video => {:bitrate => 1000, :codec => 'h264', :profile => 'baseline', :size => {:width => 640, :height => 480}, :fix_rotation => true, :force_sqare_pixels => true}}
configuration[:audio] = {:codec => "aac", :bitrate => 128000, :channels => 2, :samplerate => 36000}

#create video output and set configuration created above
out = UEncode::VideoOutput.new :container => 'mpeg4'
out.streams.configure configuration

#add a destination to the output and add output to the job object
out.add_destination UEncode::Destination.new :url => "http://your.desstination.url/foo.mp4", :timeout => 600
job.add_video(out)

#create a capture output
out = UEncode::CaptureOutput.new :rate=>'every 5s', :size=>{:width=>640, :height=>480}, :zip=>true, :prefix=>'frames'
out.add_destination UEncode::Destination.new :url=>'http://your.destination.url/capture.zip'
job.add_capture(out)

#create a request from the job and send to uEncode.
request = UEncode::Request.new job
response = request.send

#response.code contains the status code returned by the server (200, 400, 406, 500, etc).
puts response.code

#response.data is a hash created from the xml returned by the server. Included is the key used to check status of the job.
puts response.data

Advanced output options

#add an overlay to a video or capture output
out = UEncode::VideoOutput.new :container => 'mpeg4', :overlay => {:quadrant=>'Lower-Right', :source_image=>{:url=>'http://your.source.url/logo.png'}}

#encode only a portion of input video (values are seconds)
out = UEncode::VideoOutput.new :container => 'mpeg4', :clip => {:start => 30, :duration => 60}

#add metadata to a video
out = UEncode::VideoOutput.new :container => 'mpeg4', :metadata => {:title => 'Video Title', :author => 'Video Author'}

Checking job status

require 'uencode'

UEncode.configure do |c|
  c.customer_key = "your_uencode_api_key"
end

#Get a list of jobs. Including the userdata parameter will return all jobs where the userdata matches the value you specified. Otherwise, all current active (not completed) jobs will be returned.
status = UEncode::JobStatus.new :userdata => 'AnyDataUsefulToYou'
request = UEncode::Request.new status
response = request.send

#Data is a hash created from the xml returned by the API. Consult the API docs for details.
puts response.code
puts response.data

#Get details, including progress of individual tasks, of a specific job.
status = UEncode::JobStatus.new :key => 'API job key'
request = UEncode::Request.new status
response = request.send

puts response.code
puts response.data

Parameters

All version 300 uEncode API parameters are supported.

The gem does not validate input. Consult the uEncode API documentation for all parameters and their accepted values.

License

This project is released under The MIT License

Copyright © 2011, uEncode, Cássio Marques

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.