Class: AviGlitch::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/aviglitch/frame.rb

Overview

Frame is the struct of the frame data and meta-data. You can access this class through AviGlitch::Frames. To modify the binary data, operate the data property.

Constant Summary collapse

AVIIF_LIST =
0x00000001
AVIIF_KEYFRAME =
0x00000010
AVIIF_NO_TIME =
0x00000100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, id, flag) ⇒ Frame

Creates a new AviGlitch::Frame object.

The arguments are:

data

just data, without meta-data

id

id for the stream number and content type code (like “00dc”)

flag

flag that describes the chunk type (taken from idx1)



23
24
25
26
27
# File 'lib/aviglitch/frame.rb', line 23

def initialize data, id, flag
  @data = data
  @id = id
  @flag = flag
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/aviglitch/frame.rb', line 12

def data
  @data
end

#flagObject

Returns the value of attribute flag.



12
13
14
# File 'lib/aviglitch/frame.rb', line 12

def flag
  @flag
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/aviglitch/frame.rb', line 12

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object

Compares its content.



75
76
77
78
79
# File 'lib/aviglitch/frame.rb', line 75

def == other
  self.id == other.id &&
  self.flag == other.flag &&
  self.data == other.data
end

#is?(frame_type) ⇒ Boolean

Returns if it is a frame in frame_type.

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
# File 'lib/aviglitch/frame.rb', line 63

def is? frame_type
  return true if frame_type == :all
  detection = "is_#{frame_type.to_s.sub(/frames$/, 'frame')}?"
  begin 
    self.send detection
  rescue NoMethodError => e
    false
  end
end

#is_audioframe?Boolean

Returns if it is an audio frame.

Returns:

  • (Boolean)


57
58
59
# File 'lib/aviglitch/frame.rb', line 57

def is_audioframe?
  @id[2, 2] == 'wb'
end

#is_deltaframe?Boolean Also known as: is_pframe?

Returns if it is a video frame and also not a key frame.

Returns:

  • (Boolean)


41
42
43
# File 'lib/aviglitch/frame.rb', line 41

def is_deltaframe?
  is_videoframe? && @flag & AVIIF_KEYFRAME == 0
end

#is_keyframe?Boolean Also known as: is_iframe?

Returns if it is a video frame and also a key frame.

Returns:

  • (Boolean)


31
32
33
# File 'lib/aviglitch/frame.rb', line 31

def is_keyframe?
  is_videoframe? && @flag & AVIIF_KEYFRAME != 0
end

#is_videoframe?Boolean

Returns if it is a video frame.

Returns:

  • (Boolean)


51
52
53
# File 'lib/aviglitch/frame.rb', line 51

def is_videoframe?
  @id[2, 2] == 'db' || @id[2, 2] == 'dc'
end