source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/site_ruby/1.8/flv/video_tag.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 3.7 KB
Line 
1# Copyright (c) 2005 Norman Timmler (inlet media e.K., Hamburg, Germany)
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10# notice, this list of conditions and the following disclaimer in the
11# documentation and/or other materials provided with the distribution.
12# 3. The name of the author may not be used to endorse or promote products
13# derived from this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26require 'flv/amf_string_buffer'
27
28module FLV
29
30 class FLVVideoTag < FLVTag
31
32 H263VIDEOPACKET = 2
33 SCREENVIDEOPACKET = 3
34 ON2VP6 = 4
35
36 KEYFRAME = 1
37 INTERFRAME = 2
38 DISPOSABLEINTERFRAME = 3
39
40 attr_reader :frame_type,
41 :codec_id,
42 :width,
43 :height
44
45 def after_initialize(new_object)
46 @tag_type = VIDEO
47 read_header
48 end
49
50 def name
51 case frame_type
52 when KEYFRAME
53 'Video Tag (Keyframe)'
54 when INTERFRAME
55 'Video Tag (Interframe)'
56 when DISPOSABLEINTERFRAME
57 'Video Tag (disposable Interframe)'
58 else
59 'Video Tag'
60 end
61 end
62
63 def keyframe?
64 frame_type == KEYFRAME
65 end
66
67 def interframe?
68 frame_type == INTERFRAME || frame_type == DISPOSABLEINTERFRAME
69 end
70
71 def read_header
72 data_stream = AMFStringBuffer.new(@data)
73
74 # the sequence is swaped in the swf-file-format description
75 # frame_type <-> codec_id (description: 1. codec_id, 2. frame_type)
76 codec_id_and_frame_type = data_stream.read__UI8
77 @frame_type = codec_id_and_frame_type >> 4
78 @codec_id = codec_id_and_frame_type & 0xf
79
80 bit_sequence = data_stream.read(9).unpack('B72').to_s
81
82 if @codec_id == H263VIDEOPACKET
83 @width, @height = case bit2uint bit_sequence[30,3]
84 when 0
85 [bit2uint(bit_sequence[33,8]), bit2uint(bit_sequence[41,8])]
86 when 1
87 [bit2uint(bit_sequence[33,16]), bit2uint(bit_sequence[49,16])]
88 when 2
89 [352, 288]
90 when 3
91 [176, 144]
92 when 4
93 [128, 96]
94 when 5
95 [320, 240]
96 when 6
97 [160, 120]
98 end
99 elsif @codec_id == SCREENVIDEOPACKET
100 @width, @height = bit2uint(bit_sequence[4,12]), bit2uint(bit_sequence[16,12])
101 end
102 end
103
104 def inspect
105 out = super
106 out << "frame_type: #{%w{ Keyframe Interframe DisposableInterframe }[@frame_type]}"
107 out << "codec_id: #{@codec_id}"
108 out << "width: #{@width}"
109 out << "height: #{@height}"
110 out << "data_size: #{data_size}"
111 out
112 end
113 end
114end
Note: See TracBrowser for help on using the repository browser.