2 Xinloe -- A Python-Based Non-Linear Ogg Editor
3 Copyright (C) 2004 Arc Riley <arc@Xiph.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 def __init__(self
, header
):
30 def PageIn(self
, page
):
31 self
.bytes
= self
.bytes
+ len(page
)
33 class Vorbis(GenCodec
):
34 def __init__(self
, header
):
35 GenCodec
.__init
__(self
, '')
36 if header
[:7] == '\x01vorbis':
38 if header
[7:11] == '\x00\x00\x00\x00' :
39 self
.name
= 'Vorbis I'
40 self
.desc
= 'General Purpose Audio'
42 self
.channels
= ord(header
[11])
43 self
.samplerate
= ord(header
[12]) + (ord(header
[13])*256) + \
44 (ord(header
[14])*65536) + (ord(header
[15])*16777216)
46 self
.name
= 'Vorbis (Unsupported Version)'
47 self
.version
= chr(ord(header
[7]) + (ord(header
[8])*256) + \
48 (ord(header
[9])*65536) + (ord(header
[10])*16777216))
51 def PageIn(self
, page
):
52 self
.bytes
= self
.bytes
+ len(page
)
53 if self
.samplerate
> 0 :
54 self
.length
= page
.granulepos
/ self
.samplerate
57 class Theora(GenCodec
):
58 def __init__(self
, header
):
59 GenCodec
.__init
__(self
, '')
60 if header
[:7] == '\x80theora':
62 if header
[7:9] == '\x03\x02' :
63 self
.name
= 'Theora I'
64 self
.desc
= 'General Purpose Video'
65 self
.version
= '3.2.'+str(ord(header
[9]))
66 self
.size
= str(ord(header
[16]) + (ord(header
[15])*256) + \
67 (ord(header
[14])*65536)) + 'x' + \
68 str(ord(header
[19]) + (ord(header
[18])*256) +
69 (ord(header
[17])*65536))
70 n
= ord(header
[25]) + (ord(header
[24])*256) + \
71 (ord(header
[23])*65536) + (ord(header
[22])*16777216)
72 d
= ord(header
[29]) + (ord(header
[28])*256) + \
73 (ord(header
[27])*65536) + (ord(header
[26])*16777216)
74 self
.framerate
= float(n
)/float(d
)
75 self
.b
= ord(header
[39]) + (ord(header
[38])*256) + \
76 (ord(header
[37])*65536)
77 self
.q
= int(round((((ord(header
[40]) & 252) >> 2) / 6.3)))
78 self
.keyshift
= ((ord(header
[40]) & 3) << 3)+\
79 ((ord(header
[41]) & 224) >> 5)
82 self
.name
= 'Theora (Unsupported Version)'
83 self
.version
= str(ord(header
[7])) + '.' + \
84 str(ord(header
[8])) + '.' + \
88 def PageIn(self
, page
):
89 self
.bytes
= self
.bytes
+ len(page
)
90 if self
.framerate
> 0 :
91 self
.length
= int((page
.granulepos
>>self
.keyshift
) / self
.framerate
)
93 class Speex(GenCodec
):
94 def __init__(self
, header
):
95 GenCodec
.__init
__(self
, '')
96 if header
[:8] == 'Speex ':
98 self
.version
= header
[8:28]
99 if header
[28:32] == '\x01\x00\x00\x00' :
100 self
.name
= 'Speex I'
101 self
.desc
= 'Low Bitrate Voice'
102 self
.samplerate
= ord(header
[36]) + (ord(header
[37])*256) + \
103 (ord(header
[38])*65536) + (ord(header
[39])*16777216)
104 if header
[40] == '\x00' :
105 self
.q
= 'NarrowBand'
106 elif header
[40] == '\x01' :
108 elif header
[40] == '\x02' :
109 self
.q
= 'UltraWideBand'
110 else : self
.q
= 'Unknown'
111 self
.channels
= ord(header
[48])
112 if header
[52:56] == '\xff\xff\xff\xff' :
115 self
.b
= ord(header
[52]) + (ord(header
[53])*256) + \
116 (ord(header
[54])*65536) + (ord(header
[55])*16777216)
117 self
.framesize
= ord(header
[56]) + (ord(header
[57])*256) + \
118 (ord(header
[58])*65536) + (ord(header
[59])*16777216)
120 self
.name
= 'Speex (Unsupported Version)'
121 self
.version
= str(ord(header
[28]) + (ord(header
[29])*256) + \
122 (ord(header
[30])*65536) + (ord(header
[31])*16777216))
125 def PageIn(self
, page
):
126 self
.bytes
= self
.bytes
+ len(page
)
127 if self
.samplerate
> 0 :
128 self
.length
= page
.granulepos
/ self
.samplerate
130 class FLAC(GenCodec
):
131 def __init__(self
, header
):
132 GenCodec
.__init
__(self
, '')
133 if header
[:4] == 'fLaC':
135 self
.desc
= 'Lossless Audio'
138 # need samplerate, channels, samplesize, and bitrate
140 class Writ(GenCodec
):
141 def __init__(self
, header
):
142 GenCodec
.__init
__(self
, '')
143 if header
[:5] == '\x00writ':
144 if header
[5] == '\x01' :
146 self
.desc
= 'Timed Text Phrases'
148 self
.version
= '1.'+str(ord(header
[6]))
149 n
= ord(header
[7]) + (ord(header
[8])*256) + \
150 (ord(header
[9])*65536) + (ord(header
[10])*16777216)
151 d
= ord(header
[11]) + (ord(header
[12])*256) + \
152 (ord(header
[13])*65536) + (ord(header
[14])*16777216)
153 self
.granulerate
= float(n
)/float(d
)
155 self
.name
= 'Writ (Unsupported Version)'
156 self
.version
= str(ord(header
[5]))
159 def PageIn(self
, page
):
160 self
.bytes
= self
.bytes
+ len(page
)
161 if self
.granulerate
> 0 :
162 self
.length
= int(page
.granulepos
/ self
.granulerate
)
164 codecs
= (Vorbis
, Theora
, Speex
, FLAC
, Writ
, GenCodec
)