Class: UEncode::Medium

Inherits:
Object
  • Object
show all
Defined in:
lib/uencode/elements.rb

Overview

Medium is a single video to transcode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMedium

Returns a new instance of Medium.



122
123
124
125
# File 'lib/uencode/elements.rb', line 122

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

Instance Attribute Details

#audio_configObject (readonly)

Returns the value of attribute audio_config.



120
121
122
# File 'lib/uencode/elements.rb', line 120

def audio_config
  @audio_config
end

#video_configObject (readonly)

Returns the value of attribute video_config.



120
121
122
# File 'lib/uencode/elements.rb', line 120

def video_config
  @video_config
end

Instance Method Details

#audioObject



166
167
168
# File 'lib/uencode/elements.rb', line 166

def audio
  @audio_config
end

#configure(hash) ⇒ Object

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.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/uencode/elements.rb', line 142

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

#configure_audio {|@audio_config| ... } ⇒ Object

Yields:



158
159
160
# File 'lib/uencode/elements.rb', line 158

def configure_audio
  yield @audio_config
end

#configure_video {|@video_config| ... } ⇒ Object

Yields:



154
155
156
# File 'lib/uencode/elements.rb', line 154

def configure_video
  yield @video_config
end

#to_xmlObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/uencode/elements.rb', line 170

def to_xml
  %Q{
    <medium>
      <video>
        <bitrate>#{video.bitrate}</birate>
        <codec>#{video.codec}</birate>
        #{!video.cbr.nil? ? '<cbr>' + video.cbr.to_s + '</cbr>' : ""}
        #{video.crop ? video.crop.to_xml : ""}
        #{video.deinterlace.nil? ? "" : '<deinterlace>' + video.deinterlace.to_s + '</deinterlace>'}
        #{video.framerate ? video.framerate.to_xml : ""}
        #{video.height.nil? ? "" : '<height>' + video.height.to_s + '</height>'}
        #{video.keyframe_interval.nil? ? "" : '<keyframe_interval>' + video.keyframe_interval.to_s + '</keyframe_interval>'}
        #{video.maxbitrate.nil? ? "" : '<maxbitrate>' + video.maxbitrate.to_s + '</maxbitrate>'}
        #{video.par ? video.par.to_xml : ""}
        #{video.profile.nil? ? "" : '<profile>' + video.profile + '</profile>'}
        #{video.passes.nil? ? "" : '<passes>' + video.passes.to_s + '</passes>'}
        #{[nil, false].include?(video.stretch) ? "" : '<stretch>' + video.stretch.to_s + '</stretch>'}
        #{video.width.nil? ? "" : '<width>' + video.width.to_s + '</width>'}
      </video>
      <audio>
        #{audio.codec.nil? ? "" : '<codec>' + audio.codec + '</codec>'}
        #{audio.bitrate.nil? ? "" : '<bitrate>' + audio.bitrate.to_s + '</bitrate>'}
        #{audio.channels.nil? ? "" : '<channels>' + audio.channels.to_s + '</channels>'}
        #{audio.samplerate.nil? ? "" : '<samplerate>' + audio.samplerate.to_s + '</samplerate>'}
      </audio>
    </medium>
  }
end

#videoObject



162
163
164
# File 'lib/uencode/elements.rb', line 162

def video
  @video_config
end