2 function: Ogg Writ reference encoder
3 last mod: $Id: writ_decoder.py,v 1.2 2003/12/01 07:18:51 arc Exp $
5 This is an example for how py-ogg2 can be used to rapidly design a new
6 Ogg codec or test an existing codec's specifications for accuracy.
11 from struct
import unpack
20 op
= ogg2
.OggSyncState()
21 infile
= open('test.writ.ogg','r')
22 while op
.input(infile
) :
32 # Churn 'em into packets!
33 os
= ogg2
.OggStreamState(pages
[0].serialno
)
38 packet
= os
.packetout()
42 ob
=ogg2
.OggPackBuff(packet
)
44 if ob
.read(32) == 1953067639 :
46 print 'Version: %d' % version
49 print 'Granulerate: %d/%d' % (gnum
, gdom
)
54 totl
= (bitx
*2)+(bity
*2)+4
55 bitp
= ((((totl
-1)/8)+1)*8)-totl
59 for l
in range(lnum
+1) :
62 for a
in range(llen
) :
63 data
= data
+ chr(ob
.read(8))
67 for a
in range(llen
) :
68 data
= data
+ chr(ob
.read(8))
70 langs
.append((lname
,ldesc
))
71 print 'Language: %s (%s)' % (langs
[l
][0], langs
[l
][1])
74 print 'Non-Writ Packet?'
78 gstart
= ob
.read(32) + (ob
.read(32)*4294967296)
80 print ' Time: %d - %d' % (gstart
, gstart
+gdurat
)
81 locx
= ob
.read(ilog(lscx
))
82 locy
= ob
.read(ilog(lscy
))
83 print ' Location: %d,%d' % (locx
, locy
)
84 locw
= ob
.read(ilog(lscx
))
85 loch
= ob
.read(ilog(lscy
))
86 print ' Size: %d,%d' % (locw
, loch
)
89 print ' Alignment: %d,%d' % (alix
, aliy
)
91 for l
in range(lnum
+1) :
94 for a
in range(tlen
) :
97 print 'ERROR: Premature end of packet.'
99 data
= data
+ unichr(inp
)
100 print (u
' '+langs
[l
][0]+u
': '+data
).encode('latin-1')