blob: d8b49d0bec6bb09a1cb397416f140fcb04f690d7 [file] [log] [blame]
Guido van Rossum74a3f8b1992-08-18 14:47:41 +00001# Capture a movie using the Indigo video library and board
2
3import sv, SV
4import VFile
5import gl, GL, DEVICE
6
7import time
8import sys
9import posix
10import getopt
11import string
12
13def main():
14 QSIZE = 16
15 TIME = 5
16
17 opts, args = getopt.getopt(sys.argv[1:], 'q:t:')
18 for opt, arg in opts:
19 if opt == '-q':
20 QSIZE = string.atoi(arg)
21 elif opt == '-t':
22 TIME = string.atoi(arg)
23
24 if args:
25 filename = args[0]
26 if args[1:]:
27 print 'Warning: only first filename arg is used'
28 else:
29 filename = 'film.video'
30
31 gl.foreground()
32
33 x, y = SV.PAL_XMAX / 4, SV.PAL_YMAX / 4
34 print x, 'x', y
35
36 gl.minsize(40, 30)
37 gl.stepunit(8, 6)
38 gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX)
39 gl.keepaspect(SV.PAL_XMAX, SV.PAL_YMAX)
40 win = gl.winopen(filename)
41 x, y = gl.getsize()
42 print x, 'x', y
43
44 v = sv.OpenVideo()
45 v.BindGLWindow(win, SV.IN_REPLACE)
46 v.SetSize(x, y)
47 v.BindGLWindow(win, SV.IN_REPLACE)
48
49 v.SetCaptureFormat(SV.RGB_FRAMES)
50 v.SetCaptureMode(SV.BLOCKING_CAPTURE)
51 v.SetQueueSize(QSIZE)
52 v.InitCapture()
53 if v.GetQueueSize() != QSIZE:
54 QSIZE = v.GetQueueSize()
55 print 'Warning: QSIZE reduced to', QSIZE
56
57 gl.qdevice(DEVICE.LEFTMOUSE)
58 gl.qdevice(DEVICE.WINQUIT)
59 gl.qdevice(DEVICE.WINSHUT)
60 gl.qdevice(DEVICE.ESCKEY)
61
62 print 'Click left mouse to start recording', TIME, 'seconds'
63 ofile = None
64 # Mouse down opens the file & freezes window
65 # Mouse up starts recording frames
66
67 while 1:
68 dev, val = gl.qread()
69 if dev == DEVICE.LEFTMOUSE:
70 # Start recording
71 if val == 1:
72 # Mouse down -- preparations
73 if ofile == None:
74 ofile = VFile.VoutFile().init(filename)
75 ofile.format = 'rgb8'
76 ofile.width = x
77 ofile.height = y
78 ofile.writeheader()
79 # XXX other format bits?
80 # The window can't be resized from now
81 gl.prefsize(x, y)
82 gl.winconstraints()
83 gl.wintitle('* ' + filename)
84 continue
85
86 # Mouse up -- actual recording
87 t0 = time.millitimer()
88 v.StartCapture()
89 while 1:
90 t = time.millitimer() - t0
91 if t >= TIME*1000:
92 break
93 if v.GetCaptured() > 2:
94 print '(1)',
95 doframe(v, ofile, x, y, t)
96 v.StopCapture()
97 while v.GetCaptured() > 0:
98 print '(2)',
99 doframe(v, ofile, x, y, t)
100 t = time.millitimer() - t0
101 gl.wintitle(filename)
102 elif dev == DEVICE.REDRAW:
103 # Window resize (or move)
104 x, y = gl.getsize()
105 print x, 'x', y
106 v.SetSize(x, y)
107 v.BindGLWindow(win, SV.IN_REPLACE)
108 elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
109 # Quit
110 if ofile:
111 ofile.close()
112 posix._exit(0)
113 # EndCapture dumps core...
114 v.EndCapture()
115 v.CloseVideo()
116 gl.winclose(win)
117
118def doframe(v, ofile, x, y, t):
119 cd, start = v.GetCaptureData()
120 data = cd.interleave(x, y)
121 cd.UnlockCaptureData()
122 ofile.writeframe(t, data, None)
123
124main()