Class: Falcon::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/profile.rb

Constant Summary collapse

DEFAULTS =
{
  :player => 'flash', 
  :container => "mp4", 
  :extname => 'mp4',
  :width => 480, 
  :height => 320, 
  :fps => 29.97, 
  :video_codec => "libx264",
  :video_bitrate => 500, 
  :command => nil,
  :audio_codec => "libfaac",
  :audio_bitrate => 128, 
  :audio_sample_rate => 48000  
}
@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Profile

Returns a new instance of Profile.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/falcon/profile.rb', line 25

def initialize(name, options = {})
  options.assert_valid_keys(DEFAULTS.keys)
  options = DEFAULTS.merge(options)
  
  @name = name.to_s
  
  if self.class.exists?(@name)
    raise "Profile name: #{@name} already registered."
  end
  
  options.each do |key, value|
    send("#{key}=", value)
  end
  
  @@all << self
end

Instance Attribute Details

#audio_bitrateObject

Returns the value of attribute audio_bitrate.



8
9
10
# File 'lib/falcon/profile.rb', line 8

def audio_bitrate
  @audio_bitrate
end

#audio_codecObject

Returns the value of attribute audio_codec.



8
9
10
# File 'lib/falcon/profile.rb', line 8

def audio_codec
  @audio_codec
end

#audio_sample_rateObject

Returns the value of attribute audio_sample_rate.



8
9
10
# File 'lib/falcon/profile.rb', line 8

def audio_sample_rate
  @audio_sample_rate
end

#commandObject

Returns the value of attribute command.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def command
  @command
end

#containerObject

Returns the value of attribute container.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def container
  @container
end

#extnameObject

Returns the value of attribute extname.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def extname
  @extname
end

#fpsObject

Returns the value of attribute fps.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def fps
  @fps
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def height
  @height
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def name
  @name
end

#playerObject

Returns the value of attribute player.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def player
  @player
end

#video_bitrateObject

Returns the value of attribute video_bitrate.



7
8
9
# File 'lib/falcon/profile.rb', line 7

def video_bitrate
  @video_bitrate
end

#video_codecObject

Returns the value of attribute video_codec.



7
8
9
# File 'lib/falcon/profile.rb', line 7

def video_codec
  @video_codec
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/falcon/profile.rb', line 6

def width
  @width
end

Class Method Details

.[](name) ⇒ Object



83
84
85
# File 'lib/falcon/profile.rb', line 83

def [](name)
  find(name)
end

.detect(name) ⇒ Object



91
92
93
# File 'lib/falcon/profile.rb', line 91

def detect(name)
  name.is_a?(Falcon::Profile) ? name : find(name.to_s)
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/falcon/profile.rb', line 87

def exists?(name)
  !find(name).nil?
end

.find(name) ⇒ Object Also known as: get



78
79
80
# File 'lib/falcon/profile.rb', line 78

def find(name)
  @@all.detect { |p| p.name == name.to_s } 
end

Instance Method Details

#audio_bitrate_in_bitsObject



42
43
44
# File 'lib/falcon/profile.rb', line 42

def audio_bitrate_in_bits
  self.audio_bitrate.to_i * 1024
end

#encode_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/falcon/profile.rb', line 58

def encode_options
  { 
    :container => self.container, 
    :video_codec => self.video_codec,
    :video_bitrate_in_bits => self.video_bitrate_in_bits.to_s, 
    :fps => self.fps,
    :audio_codec => self.audio_codec.to_s, 
    :audio_bitrate => self.audio_bitrate.to_s, 
    :audio_bitrate_in_bits => self.audio_bitrate_in_bits.to_s, 
    :audio_sample_rate => self.audio_sample_rate.to_s
  }
end

#path(source, prefix = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/falcon/profile.rb', line 50

def path(source, prefix = nil)
  dirname = File.dirname(source)
  filename = File.basename(source, File.extname(source))
  filename = [prefix, filename].compact.join('_') + '.' + extname
  
  Pathname.new(File.join(dirname, filename))
end

#update(options) ⇒ Object



71
72
73
74
75
# File 'lib/falcon/profile.rb', line 71

def update(options)
  options.each do |key, value|
    send("#{key}=", value)
  end
end

#video_bitrate_in_bitsObject



46
47
48
# File 'lib/falcon/profile.rb', line 46

def video_bitrate_in_bits
  self.video_bitrate.to_i * 1024
end