summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/video/vinfo.py
blob: e230c4fee320ab3b94a83515fc04ccf388214d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from gl import *
from GL import *
from DEVICE import *
import time
import sys
import getopt

class Struct(): pass
epoch = Struct()
EndOfFile = 'End of file'
bye = 'bye'

def openvideo(filename):
    f = open(filename, 'r')
    line = f.readline()
    if not line: raise EndOfFile
    if line[:4] = 'CMIF': line = f.readline()
    x = eval(line[:-1])
    if len(x) = 3: w, h, pf = x
    else: w, h = x; pf = 2
    return f, w, h, pf

def loadframe(f, w, h, pf):
    line = f.readline()
    if line = '':
	raise EndOfFile
    x = eval(line[:-1])
    if type(x) = type(0) or type(x) = type(0.0):
    	tijd = x
    	if pf = 0:
    		size = w*h*4
    	else:
    		size = (w/pf) * (h/pf)
    else:
    	tijd, size = x
    f.seek(size, 1)
    return tijd

def saveframe(name, w, h, tijd, data):
    f = open(name, 'w')
    f.write(`w,h` + '\n')
    f.write(`tijd` + '\n')
    f.write(data)
    f.close()

def main():
	delta = 0
	opts, names = getopt.getopt(sys.argv[1:], 'd')
	for opt, arg in opts:
		if opt = '-d': delta = 1
	if names = []:
		names = ['film.video']
	for name in names:
	    try:
		f, w, h, pf = openvideo(name)
	    except:
	    	sys.stderr.write(name + ': cannot open\n')
	    	continue
	    print name, ':', w, 'x', h, '; pf =', pf
	    num = 0
	    try:
	    	otijd = 0
		while 1:
		    try:
			tijd = loadframe(f, w, h, pf)
			if delta: print '\t', tijd-otijd,
			else: print '\t', tijd,
			otijd = tijd
			num = num + 1
			if num % 8 = 0:
				print
		    except EndOfFile:
			raise bye
	    except bye:
		pass
	    if num % 8 <> 0:
		print
	    f.close()

main()