[xiph-cvs] cvs commit: ogg-python2/examples writ_decoder.py writ_encode.py
Arc
arc at xiph.org
Sun Nov 30 22:49:04 PST 2003
arc 03/12/01 01:49:04
Modified: examples writ_encode.py
Added: examples writ_decoder.py
Log:
Revision Changes Path
1.2 +3 -1 ogg-python2/examples/writ_encode.py
Index: writ_encode.py
===================================================================
RCS file: /usr/local/cvsroot/ogg-python2/examples/writ_encode.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- writ_encode.py 1 Dec 2003 00:33:43 -0000 1.1
+++ writ_encode.py 1 Dec 2003 06:49:04 -0000 1.2
@@ -67,7 +67,9 @@
texts=((05,10,1,2,3,1,3,3, ( u'Hello World!' ,
u'Hola, Mundo!' ) ),
(12,15,5,6,7,1,3,3, ( u'It\'s a beautiful day to be born.' ,
- u'Es un día hermoso para que se llevará.' ) ) )
+ u'Es un d\N{LATIN SMALL LETTER I WITH ACUTE}'+\
+ u'a hermoso para que se llevar'+\
+ u'\N{LATIN SMALL LETTER A WITH ACUTE}.' ) ) )
bp = BitPacker()
os=ogg2.OggStreamState(5)
<p><p>1.1 ogg-python2/examples/writ_decoder.py
Index: writ_decoder.py
===================================================================
#!/usr/local/bin/python
import ogg2
from struct import unpack
def ilog(num) :
for x in range(17) :
if 2**x >= num+1 :
return x
return 0
# Grab 'em pages!
op = ogg2.OggSyncState()
infile = open('test.writ.ogg','r')
while op.input(infile) :
pass
pages = []
while 1 :
page=op.pageout()
if page == None :
break
else :
pages.append(page)
# Churn 'em into packets!
os = ogg2.OggStreamState(pages[0].serialno)
for page in pages :
os.pagein(page)
while 1 :
packet = os.packetout()
if packet == None :
break
else :
ob=ogg2.OggPackBuff(packet)
if ob.read(8)==0 :
if ob.read(32) == 1953067639 :
version = ob.read(8)
print 'Version: %d' % version
gnum = ob.read(32)
gdom = ob.read(32)
print 'Granulerate: %d/%d' % (gnum, gdom)
lscx = ob.read(16)
lscy = ob.read(16)
bitx = ilog(lscx)
bity = ilog(lscy)
totl = (bitx*2)+(bity*2)+4
bitp = ((((totl-1)/8)+1)*8)-totl
lnum = ob.read(8)
langs = []
print 'langs =', lnum
for l in range(lnum+1) :
llen = ob.read(8)
data = ''
for a in range(llen) :
data = data + chr(ob.read(8))
lname = unicode(data)
llen = ob.read(8)
data = ''
for a in range(llen) :
data = data + chr(ob.read(8))
ldesc = unicode(data)
langs.append((lname,ldesc))
print 'Language: %s (%s)' % (langs[l][0], langs[l][1])
print ''
else :
print 'Non-Writ Packet?'
continue
else :
print 'Phrase:'
gstart = ob.read(32) + (ob.read(32)*4294967296)
gdurat = ob.read(32)
print ' Time: %d - %d' % (gstart, gstart+gdurat)
locx = ob.read(ilog(lscx))
locy = ob.read(ilog(lscy))
print ' Location: %d,%d' % (locx, locy)
locw = ob.read(ilog(lscx))
loch = ob.read(ilog(lscy))
print ' Size: %d,%d' % (locw, loch)
alix = ob.read(2)
aliy = ob.read(2)
print ' Alignment: %d,%d' % (alix, aliy)
ob.read(bitp)
for l in range(lnum+1) :
tlen = ob.read(8)
data = u''
for a in range(tlen) :
inp = ob.read(8)
if inp == None :
print 'ERROR: Premature end of packet.'
break
data = data + unichr(inp)
print (u' '+langs[l][0]+u': '+data).encode('latin-1')
print ''
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list