Class: FLV::Video

Inherits:
String
  • Object
show all
Includes:
Body
Defined in:
lib/flvedit/flv/video.rb

Overview

The body of a video tag. The data is quite complex stuff. We make no attempt to understand it all or to be able to modify any of it. We simply consider it a complex string and read the interesting bits to give more info.

Constant Summary collapse

CODECS =
Hash.new(:unknown).merge!(
  1 => :JPEG,
  2 => :h263,
  3 => :screen,
  4 => :on2_vp6,
  5 => :on2_vp6_alpha,
  6 => :screen_v2,
  7 => :AVC
).freeze
FRAMES =
Hash.new(:unknown).merge!(
  1 => :keyframe  ,
  2 => :interframe,
  3 => :disposable_interframe
).freeze
H263_DIMENSIONS =

Dimensions for h263 encoding; either as a bit range or the final value

{
  0 => [41...49, 49...57],
  1 => [41...57, 57...73],
  2 => [352, 288],
  3 => [176, 144],
  4 => [128, 96] ,
  5 => [320, 240],
  6 => [160, 120]
}.freeze

Instance Method Summary collapse

Methods included from Body

included

Instance Method Details

#codecObject



32
33
34
# File 'lib/flvedit/flv/video.rb', line 32

def codec
  CODECS[codec_id]
end

#codec_idObject



28
29
30
# File 'lib/flvedit/flv/video.rb', line 28

def codec_id
  read_bits(4...8)
end

#dimensionsObject

Returns dimensions as => w, :height => h, for Sorensen H.263 and screen video codecs only (otherwise returns nil)



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/flvedit/flv/video.rb', line 48

def dimensions
  w, h = case codec
    when :h263
      H263_DIMENSIONS[read_bits(38...41)]
    when :screen
      [12...24, 24...32]
  end
  return nil unless w
  w, h = [w, h].map{ |r| read_bits(r) } if w.is_a?(Range)
  {:width => w, :height => h}
end

#frame_typeObject



24
25
26
# File 'lib/flvedit/flv/video.rb', line 24

def frame_type
  FRAMES[read_bits(0...4)]
end

#gettersObject



64
65
66
# File 'lib/flvedit/flv/video.rb', line 64

def getters
  super - [:frame_type, :frame_type.to_s]  # Let's exclude the frame_type from the normal attributes... (string vs symbol: ruby 1.8 vs 1.9)
end

#is?(what) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/flvedit/flv/video.rb', line 60

def is?(what)
  frame_type.to_s.downcase == what.to_s.downcase || super
end

#titleObject



68
69
70
# File 'lib/flvedit/flv/video.rb', line 68

def title
  super + " (#{frame_type})"  # ...and include it in the title instead.
end