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.



116
117
118
119
# File 'lib/uencode/elements.rb', line 116

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

Instance Attribute Details

#audio_configObject (readonly)

Returns the value of attribute audio_config.



114
115
116
# File 'lib/uencode/elements.rb', line 114

def audio_config
  @audio_config
end

#video_configObject (readonly)

Returns the value of attribute video_config.



114
115
116
# File 'lib/uencode/elements.rb', line 114

def video_config
  @video_config
end

Instance Method Details

#audioObject



160
161
162
# File 'lib/uencode/elements.rb', line 160

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.



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/uencode/elements.rb', line 136

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:



152
153
154
# File 'lib/uencode/elements.rb', line 152

def configure_audio
  yield @audio_config
end

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

Yields:



148
149
150
# File 'lib/uencode/elements.rb', line 148

def configure_video
  yield @video_config
end

#to_xmlObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/uencode/elements.rb', line 164

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



156
157
158
# File 'lib/uencode/elements.rb', line 156

def video
  @video_config
end