summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/video/vcopy.py
blob: 1842094a44661536ce1525ee8bd68b9f79282770 (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
# Copy a video file, interactively, frame-by-frame.

import sys
import getopt
from gl import *
from DEVICE import *
import VFile

def report(time, iframe):
	print 'Frame', iframe, ': t =', time

def usage():
	sys.write('usage: vcopy infile outfile\n')
	sys.exit(2)

def help():
	print 'Command summary:'
	print 'n   get next image from input'
	print 'w   write current image to output'

def main():
	foreground()
	opts, args = getopt.getopt(sys.argv[1:], 't:a')
	if len(args) <> 2:
		usage()
	[ifile, ofile] = args
	print 'open film ', ifile
	ifilm = VFile.VinFile().init(ifile)
	print 'open output ', ofile
	ofilm = VFile.VoutFile().init(ofile)
	
	ofilm.setinfo(ifilm.getinfo())

	use_grabber = 0
	continuous = 0
	for o, a in opts:
		if o == '-t':
			ofilm.format = a
			use_grabber = 1
		if o == '-a':
			continuous = 1
	ofilm.writeheader()
	#
	prefsize(ifilm.width, ifilm.height)
	w = winopen(ifile)
	qdevice(KEYBD)
	qdevice(ESCKEY)
	qdevice(WINQUIT)
	qdevice(WINSHUT)
	print 'qdevice calls done'
	#
	help()
	#
	time, data, cdata = ifilm.getnextframe()
	ifilm.showframe(data, cdata)
	iframe = 1
	report(time, iframe)
	#
	while 1:
		if continuous:
			dev = KEYBD
		else:
			dev, val = qread()
		if dev in (ESCKEY, WINQUIT, WINSHUT):
			break
		if dev == REDRAW:
			reshapeviewport()
		elif dev == KEYBD:
			if continuous:
				c = '0'
			else:
				c = chr(val)
			#XXX Debug
			if c == 'R':
				c3i(255,0,0)
				clear()
			if c == 'G':
				c3i(0,255,0)
				clear()
			if c == 'B':
				c3i(0,0,255)
				clear()
			if c == 'w' or continuous:
				if use_grabber:
					data, cdata = ofilm.grabframe()
				ofilm.writeframe(time, data, cdata)
				print 'Frame', iframe, 'written.'
			if c == 'n' or continuous:
				try:
					time,data,cdata = ifilm.getnextframe()
					ifilm.showframe(data, cdata)
					iframe = iframe+1
					report(time, iframe)
				except EOFError:
					print 'EOF'
					if continuous:
						break
					ringbell()
		elif dev == INPUTCHANGE:
			pass
		else:
			print '(dev, val) =', (dev, val)
	ofilm.close()

main()