Recognizes if input is ogg or not.
[xiph.git] / py-ogg2 / examples / reserializer.py
blob36e68892a3eb02a3e4312714d2bbbaaf2d398c02
1 '''
2 function: Ogg ReSerializer
3 last mod: $Id: reserializer.py
5 This is a useful tool for changing the serial number of an Ogg stream.
6 Why is it useful? Because you can't chain two logical streams together
7 in the same physical stream which have the same serial numbers.
9 '''
11 import ogg2
12 import random
14 infilename = raw_input('Input File: ')
15 outfilename = raw_input('Output File: ')
17 inf=open(infilename, 'r')
18 otf=open(outfilename, 'w')
20 syncin=ogg2.OggSyncState()
21 syncout=ogg2.OggSyncState()
23 serials = {}
25 while 1: # While there's data to input
26 if syncin.input(inf) == 0 : break
27 while 1: # While there are pages to output
28 page = syncin.pageout()
29 if page==None : break
30 if page.bos :
31 serials[page.serialno] = int(random.random()*2147483647)
32 print 'ReSerializing stream %d to %d' % (page.serialno,
33 serials[page.serialno])
34 if serials.has_key(page.serialno) :
35 page.serialno = serials[page.serialno]
36 syncout.pagein(page)
37 while 1:
38 if syncout.output(otf) == 0 : break
39 else :
40 print 'Headless stream %d found, skipping' % page.serialno
42 print "Done."