Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Demo / sgi / video / vinfo.py
blob7f98237a97433532e43cfed017cb8d0f4d2edf9c
1 from gl import *
2 from GL import *
3 from DEVICE import *
4 import time
5 import sys
6 import getopt
8 class Struct(): pass
9 epoch = Struct()
10 EndOfFile = 'End of file'
11 bye = 'bye'
13 def openvideo(filename):
14 f = open(filename, 'r')
15 line = f.readline()
16 if not line: raise EndOfFile
17 if line[:4] == 'CMIF': line = f.readline()
18 x = eval(line[:-1])
19 if len(x) == 3: w, h, pf = x
20 else: w, h = x; pf = 2
21 return f, w, h, pf
23 def loadframe(f, w, h, pf):
24 line = f.readline()
25 if line == '':
26 raise EndOfFile
27 x = eval(line[:-1])
28 if type(x) == type(0) or type(x) == type(0.0):
29 tijd = x
30 if pf == 0:
31 size = w*h*4
32 else:
33 size = (w/pf) * (h/pf)
34 else:
35 tijd, size = x
36 f.seek(size, 1)
37 return tijd
39 def main():
40 delta = 0
41 short = 0
42 try:
43 opts, names = getopt.getopt(sys.argv[1:], 'ds')
44 except getopt.error, msg:
45 sys.stderr.write(msg + '\n')
46 sys.stderr.write('usage: vinfo [-d] [-s] [file] ...\n')
47 sys.exit(2)
48 for opt, arg in opts:
49 if opt == '-d': delta = 1 # print delta between frames
50 elif opt == '-s': short = 1 # short: don't print times
51 if names == []:
52 names = ['film.video']
53 for name in names:
54 try:
55 f, w, h, pf = openvideo(name)
56 except:
57 sys.stderr.write(name + ': cannot open\n')
58 continue
59 if pf == 0:
60 size = w*h*4
61 else:
62 size = (w/pf) * (h/pf)
63 print name, ':', w, 'x', h, '; pf =', pf, ', size =', size,
64 if pf == 0:
65 print '(color)',
66 else:
67 print '(' + `(w/pf)` + 'x' + `(h/pf)` + ')',
68 if (w/pf)%4 <> 0: print '!!!',
69 print
70 num = 0
71 try:
72 otijd = 0
73 while not short:
74 try:
75 tijd = loadframe(f, w, h, pf)
76 if delta: print '\t' + `tijd-otijd`,
77 else: print '\t' + `tijd`,
78 otijd = tijd
79 num = num + 1
80 if num % 8 == 0:
81 print
82 except EndOfFile:
83 raise bye
84 except bye:
85 pass
86 if num % 8 <> 0:
87 print
88 f.close()
90 main()