11 # Preallocation parameter
12 PREALLOC
= 4 # Megabyte
14 # Sync audio parameters
24 w
= getvideo(VP_WIDTH
)
25 h
= getvideo(VP_HEIGHT
)
26 print 'WIDTH,HEIGHT:', w
, h
27 print 'GB{X,Y}ORG:', getvideo(VP_GBXORG
), getvideo(VP_GBYORG
)
28 print 'FB{X,Y}ORG:', getvideo(VP_FBXORG
), getvideo(VP_FBYORG
)
37 limit
= PREALLOC
*1024*1024
40 print 'Prealloc to', PREALLOC
, 'Megabytes...'
41 while total
+nbytes
<= limit
:
42 list.append('x'*nbytes
)
43 total
= total
+ nbytes
46 def grabframe(f
,x
,y
,w
,h
,pf
):
51 data
= lrectread(x
,y
,x
+w
-1,y
+h
-1)
52 t
= time
.millitimer()-epoch
.epoch
53 framelist
.append(data
, t
)
54 readsource(SRC_FRAMEGRABBER
)
56 def saveframes(f
, w
, h
, pf
):
57 for data
, t
in framelist
:
61 data
= packrect(w
,h
,pf
,data
)
62 f
.write(`t`
+ ',' + `
len(data
)`
+ '\n')
66 def saveframe(f
,x
,y
,w
,h
,pf
, notime
):
71 data
= lrectread(x
,y
,x
+w
-1,y
+h
-1)
72 if pf
: data
= packrect(w
,h
,pf
,data
)
74 else: t
= time
.millitimer()-epoch
.epoch
75 f
.write(`t`
+ ',' + `
len(data
)`
+ '\n')
77 readsource(SRC_FRAMEGRABBER
)
79 def drawframe(x
,y
,w
,h
,col
):
83 v2i(x
-1,y
-1) ; v2i(x
+w
,y
-1); v2i(x
+w
,y
+h
); v2i(x
-1,y
+h
); v2i(x
-1,y
-1)
88 sys
.stderr
.write('Usage: camcorder ' + \
89 '[-c] [-p packfactor] [-a audiomachine [-s]] [outputfile]\n')
92 def wrheader(f
, w
, h
, pf
):
93 f
.write('CMIF video 1.0\n')
94 f
.write(`w
,h
,pf`
+ '\n')
95 print 'width,height,pf:', w
, h
, pf
,
97 print '(i.e.,', w
*h
*pf
, 'bytes/frame)'
104 optlist
, args
= getopt
.getopt(sys
.argv
[1:],'ca:sp:')
105 for opt
, arg
in optlist
:
119 print 'Too many arguments'
123 filename
= 'film.video'
126 print 'Cannot use -s without -a'
128 print 'Starting audio recorder...'
129 posix
.system('rsh '+aumachine
+' syncrecord '+socket
.gethostname()+' &')
131 print 'Syncing to audio recorder...'
132 globtime
= vtime
.VTime().init(1,aumachine
,SYNCPORT
)
133 ctl
= socket
.socket(socket
.AF_INET
,socket
.SOCK_DGRAM
)
134 ctl
.bind((socket
.gethostname(),CTLPORT
))
135 aua
= (socket
.gethostbyname(aumachine
), CTLPORT
)
137 vidx
, vidy
, w
, h
= getvideosize()
139 winx
, winy
= 1280-w
-10, 1024-h
-30
140 prefposition(winx
,winx
+w
-1,winy
,winy
+h
-1)
141 win
= winopen(filename
)
142 f
= open(filename
, 'w')
159 readsource(SRC_FRAMEGRABBER
)
161 epoch
.epoch
= time
.millitimer()
162 stoptime
= epoch
.epoch
164 x
, y
= realw
/4, realh
/4
178 x
= getvaluator(MOUSEX
)-ox
179 y
= getvaluator(MOUSEY
)-oy
181 w
= getvaluator(MOUSEX
)-x
-ox
182 h
= getvaluator(MOUSEY
)-y
-oy
185 not (mousing
or inrunning
or insingle
or outrunning
or outsingle
):
187 if ev
== LEFTMOUSE
and val
== 1:
191 x
= getvaluator(MOUSEX
)-ox
192 y
= getvaluator(MOUSEY
)-oy
193 elif ev
== LEFTMOUSE
and val
== 0:
200 wrheader(f
, w
, h
, pf
)
203 elif ev
== RKEY
and val
== 1:
208 wasstopped
= time
.millitimer() - stoptime
209 epoch
.epoch
= epoch
.epoch
+ wasstopped
211 starttime
= time
.millitimer()
213 ctl
.sendto(`
(1,starttime
)`
, aua
)
214 elif ev
== PKEY
and val
== 1 and outrunning
:
216 stoptime
= time
.millitimer()
218 ctl
.sendto(`
(0,stoptime
)`
, aua
)
219 fps
= nframe
* 1000.0 / (time
.millitimer()-starttime
)
220 print 'Recorded', nframe
,
221 print 'frames at', 0.1*int(fps
*10),'frames/sec'
223 saveframes(f
, w
, h
, pf
)
225 elif ev
== PKEY
and val
== 1 and not outrunning
:
227 elif ev
== CKEY
and val
== 1:
229 elif ev
== SKEY
and val
== 1:
236 elif ev
in (ESCKEY
, WINQUIT
, WINSHUT
):
238 ctl
.sendto(`
(2,time
.millitimer())`
, aua
)
244 if inrunning
or insingle
:
246 rectcopy(vidx
+x
,vidy
+y
,vidx
+x
+w
-1,vidy
+y
+h
-1,x
,y
)
248 rectcopy(vidx
,vidy
,vidx
+realw
-1,vidx
+realh
-1,0,0)
250 if outrunning
or outsingle
:
253 wrheader(f
, w
, h
, pf
)
256 grabframe(f
, x
, y
, w
, h
, pf
)
258 saveframe(f
, x
, y
, w
, h
, pf
, outsingle
)