Class: EncodingDotCom::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/encoding_dot_com/format.rb

Constant Summary collapse

OUTPUTS =
[:"3gp", :appletv, :fl9, :flv, :iphone, :ipod, :m4v, :mp3, :mp4, :psp, :wma, :wmv, :zune]
VIDEO_CODECS =
[:flv, :libx264, :mpeg4, :msmpeg4, :h263, :vp6, :wmv2]
AUDIO_CODECS =
[:libmp3lame, :libfaac, :wmav2, :libamr_nb]
BOOLEAN_FIELDS =
[:stereo, :two_pass, :constant_bitrate, :deinterlace, :turbo]
INTEGER_FIELDS =
[:video_bitrate, :framerate, :audio_bitrate, :audio_sample_rate, :max_bitrate, :min_bitrate, :key_frame_interval ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Format



28
29
30
31
32
33
# File 'lib/encoding_dot_com/format.rb', line 28

def initialize(attributes = {})
  self.output = attributes.delete(:output)
  attributes.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#audio_bitrateObject

Returns the value of attribute audio_bitrate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def audio_bitrate
  @audio_bitrate
end

#audio_codecObject

Returns the value of attribute audio_codec.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def audio_codec
  @audio_codec
end

#audio_sample_rateObject

Returns the value of attribute audio_sample_rate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def audio_sample_rate
  @audio_sample_rate
end

#constant_bitrateObject

Returns the value of attribute constant_bitrate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def constant_bitrate
  @constant_bitrate
end

#deinterlaceObject

Returns the value of attribute deinterlace.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def deinterlace
  @deinterlace
end

#destinationObject

Returns the value of attribute destination.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def destination
  @destination
end

#dimensionsObject

Returns the value of attribute dimensions.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def dimensions
  @dimensions
end

#framerateObject

Returns the value of attribute framerate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def framerate
  @framerate
end

#key_frame_intervalObject

Returns the value of attribute key_frame_interval.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def key_frame_interval
  @key_frame_interval
end

#max_bitrateObject

Returns the value of attribute max_bitrate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def max_bitrate
  @max_bitrate
end

#min_bitrateObject

Returns the value of attribute min_bitrate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def min_bitrate
  @min_bitrate
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def output
  @output
end

#stereoObject

Returns the value of attribute stereo.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def stereo
  @stereo
end

#turboObject

Returns the value of attribute turbo.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def turbo
  @turbo
end

#two_passObject

Returns the value of attribute two_pass.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def two_pass
  @two_pass
end

#video_bitrateObject

Returns the value of attribute video_bitrate.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def video_bitrate
  @video_bitrate
end

#video_codecObject

Returns the value of attribute video_codec.



10
11
12
# File 'lib/encoding_dot_com/format.rb', line 10

def video_codec
  @video_codec
end

Instance Method Details

#to_hashObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/encoding_dot_com/format.rb', line 168

def to_hash
  hash = {
    :output => output,
    :stereo => stereo,
    :turbo => turbo
  }

  hash[:dimensions] = dimensions unless dimensions.nil?
  hash[:video_bitrate] = video_bitrate unless video_bitrate.nil?
  hash[:framerate] = framerate unless framerate.nil?
  hash[:video_codec] = video_codec unless video_codec.nil?
  hash[:audio_bitrate] = audio_bitrate unless audio_bitrate.nil?
  hash[:audio_sample_rate] = audio_sample_rate unless audio_sample_rate.nil?
  hash[:audio_codec] = audio_codec unless audio_codec.nil?
  hash[:two_pass] = two_pass unless two_pass.nil?
  hash[:constant_bitrate] = constant_bitrate unless constant_bitrate.nil?
  hash[:max_bitrate] = max_bitrate unless max_bitrate.nil?
  hash[:min_bitrate] = min_bitrate unless min_bitrate.nil?
  hash[:key_frame_interval] = key_frame_interval unless key_frame_interval.nil?
  hash[:deinterlace] = deinterlace unless deinterlace.nil?

  hash
end

#to_xml(options = {}) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/encoding_dot_com/format.rb', line 144

def to_xml(options = {})
  xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent] ||= 2)

  xml.format do
    xml.output(output.to_s)
    xml.video_codec(video_codec.to_s) if video_codec
    xml.audio_codec(audio_codec.to_s) if audio_codec
    xml.bitrate("#{video_bitrate}k") if video_bitrate
    xml.audio_bitrate("#{audio_bitrate}k") if audio_bitrate
    xml.audio_sample_rate(audio_sample_rate.to_s) if audio_sample_rate
    xml.size("#{dimensions[0]}x#{dimensions[1]}") if dimensions
    xml.minrate("#{min_bitrate}k") if min_bitrate
    xml.maxrate("#{max_bitrate}k") if max_bitrate
    xml.keyframe(key_frame_interval) if key_frame_interval
    xml.framerate(framerate.is_a?(Array) ? "#{framerate[0]}/#{framerate[1]}" : framerate.to_s) if framerate
    xml.audio_channels_number(stereo ? '2' : '1') unless stereo.nil?
    xml.two_pass(two_pass ? 'yes' : 'no') unless two_pass.nil?
    xml.cbr(constant_bitrate ? 'yes' : 'no') unless constant_bitrate.nil?
    xml.deinterlacing(deinterlace ? 'yes' : 'no') unless deinterlace.nil?
    xml.destination(destination) unless destination.nil?
    xml.turbo(turbo ? 'yes' : 'no') unless turbo.nil?
  end
end