Skip to content

Commit

Permalink
Adds configuration for transcoding using hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiomarques committed Jul 7, 2011
1 parent 45e6f82 commit 3228e1c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/uencode/elements.rb
Expand Up @@ -111,11 +111,40 @@ def to_xml

# Medium is a single video to transcode
class Medium
attr_reader :video_config, :audio_config

def initialize
@video_config = VideoConfig.new
@audio_config = AudioConfig.new
end

# Configures the transcoding using a nested hash with the following format:
#
# config = {"video" => { ... }, "audio" => { ... }
#
# The keys for the "video" hash can be any of the following: bitrate, codec, cbr, crop,
# deinterlace, framerate, height, keyframe_interval, maxbitrate, par, profile, passes,
# stretch, width.
#
# The "framerate" and "par" values must be also hashes, with the following format:
#
# {"numerator" => 10, "denominator" => 11}
#
# The keys for the "audio" hash can be any of the following:
# codec, bitrate, channels, samplerate.
#
def configure(hash)
video = hash["video"]
audio = hash["audio"]
configure_video do |c|
video.each_pair { |key, value| c.send("#{key}=", value) }
end

configure_audio do |c|
audio.each_pair { |key, value| c.send("#{key}=", value) }
end
end

def configure_video
yield @video_config
end
Expand Down Expand Up @@ -186,6 +215,10 @@ class Job

include Enumerable

def self.from_hash(hash)
new({})
end

def initialize(options)
@video_output = VideoOutput.new options[:video_output] || {}
@captures = []
Expand Down
33 changes: 33 additions & 0 deletions spec/elements_spec.rb
Expand Up @@ -31,6 +31,9 @@

describe "#configure_video" do
let(:medium) { UEncode::Medium.new }
let(:config) { YAML::load_file("spec/fixtures/configuration.yaml") }
let(:video_config) { config["video"] }
let(:audio_config) { config["audio"] }

it { medium.video.bitrate.should == 10000 }
it { medium.video.codec.should == "mp4" }
Expand All @@ -46,6 +49,36 @@
it { medium.video.passes.should == 1 }
it { medium.video.stretch.should == false }
it { medium.video.width.should == 400 }

context "from a hash (video parameters)" do
before { medium.configure config }
subject { medium.video_config }

its(:bitrate) { should == video_config["bitrate"] }
its(:codec) { should == video_config["codec"] }
its(:cbr) { should == video_config["cbr"] }
its(:crop) { should == video_config["crop"] }
its(:deinterlace) { should == video_config["deinterlace"] }
its(:framerate) { should == video_config["framerate"] }
its(:height) { should == video_config["height"] }
its(:keyframe_interval) { should == video_config["keyframe_interval"] }
its(:maxbitrate) { should == video_config["maxbitrate"] }
its(:par) { should == video_config["par"] }
its(:profile) { should == video_config["profile"] }
its(:passes) { should == video_config["passes"] }
its(:stretch) { should == video_config["stretch"] }
its(:width) { should == video_config["width"] }
end

context "from a hash (audio parameters)" do
before { medium.configure config }
subject { medium.audio_config }

its(:codec) { should == audio_config["codec"] }
its(:bitrate) { should == audio_config["bitrate"] }
its(:channels) { should == audio_config["channels"] }
its(:samplerate) { should == audio_config["samplerate"] }
end
end

describe "#configure_audio" do
Expand Down
23 changes: 23 additions & 0 deletions spec/fixtures/configuration.yaml
@@ -0,0 +1,23 @@
video:
bitrate: 4500000
codec: "mp4"
width: 1920
height: 1080
passes: 1
maxbitrate: 2000000
deinterlace: false
cbr: false
stretch: false
profile: "baseline"
framerate:
numerator: 30000
denominator: 1001
par:
numerator: 1
denominator: 1
keyframe_interval: 60
audio:
codec: "aac"
bitrate: 256000
channels: 2
samplerate: 44100
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -3,7 +3,6 @@
require 'rspec/autorun'
require "vcr"


VCR.config do |c|
library_dir = File.join(File.dirname(__FILE__), 'fixtures/')
c.cassette_library_dir = library_dir
Expand Down

0 comments on commit 3228e1c

Please sign in to comment.