summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/video/Vplay.py
blob: ce82b68cdb4b6ec8dae58929e5d905d17e066277 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/local/python

# Play CMIF movie files


# Usage:
#
# Vplay [-l] [-m maginfy] [file] ...


# Options:
#
# -l         : loop, playing the movie over and over again
# -m magnify : magnify the image by the given factor
# file ...   : file(s) to play; default film.video


# User interface:
#
# Place the windo where you want it.  The size is determined by the
# movie file and the -m option.
#
# Press ESC or select the window manager Quit or Close window option
# to close a window; if more files are given the window for the next
# file now pops up.


import sys
sys.path.append('/ufs/guido/src/video')
import VFile
import time
import gl, GL
from DEVICE import *
import getopt
import string


# Global options

magnify = 1
looping = 0


# Main program -- mostly command line parsing

def main():
	global magnify, looping
	opts, args = getopt.getopt(sys.argv[1:], 'lm:')
	for opt, arg in opts:
		if opt == '-l':
			looping = 1
		elif opt == '-m':
			magnify = string.atoi(arg)
	if not args:
		args = ['film.video']
	for filename in args:
		process(filename)


# Process one file

def process(filename):
	vin = VFile.VinFile().init(filename)
	print 'File:    ', filename
	print 'Version: ', vin.version
	print 'Size:    ', vin.width, 'x', vin.height
	print 'Pack:    ', vin.packfactor, '; chrom:', vin.chrompack
	print 'Bits:    ', vin.c0bits, vin.c1bits, vin.c2bits
	print 'Format:  ', vin.format
	print 'Offset:  ', vin.offset
	vin.magnify = magnify
	
	gl.foreground()
	gl.prefsize(vin.width * magnify, vin.height * magnify)
	win = gl.winopen('* ' + filename)
	vin.initcolormap()

	gl.qdevice(ESCKEY)
	gl.qdevice(WINSHUT)
	gl.qdevice(WINQUIT)

	t0 = time.millitimer()
	running = 1
	data = None
	t = 0
	n = 0
	while 1:
		if running:
			try:
				t, data, chromdata = vin.getnextframe()
				n = n+1
			except EOFError:
				t1 = time.millitimer()
				gl.wintitle(filename)
				print 'Recorded:', n,
				print 'frames in', t*0.001, 'sec.',
				if t:
					print '-- average',
					print int(n*10000.0/t)*0.1,
					print 'frames/sec',
				print
				t = t1-t0
				print 'Played:', n,
				print 'frames in', t*0.001, 'sec.',
				if t:
					print '-- average',
					print int(n*10000.0/t)*0.1,
					print 'frames/sec',
				print
				if looping and n > 0:
					vin.rewind()
					vin.magnify = magnify
					continue
				else:
					running = 0
		if running:
			dt = t + t0 - time.millitimer()
			if dt > 0:
				time.millisleep(dt)
			vin.showframe(data, chromdata)
		if not running or gl.qtest():
			dev, val = gl.qread()
			if dev in (ESCKEY, WINSHUT, WINQUIT):
				gl.winclose(win)
				break
			if dev == REDRAW:
				gl.reshapeviewport()
				if data:
					vin.showframe(data, chromdata)


# Don't forget to call the main program

main()