1 #! /ufs/guido/bin/sgi/python-405
2 #! /ufs/guido/bin/sgi/python
4 # Capture a continuous CMIF movie using the Indigo video library and board
9 # makemovie [-r rate] [-w width] [moviefile]
14 # -r rate : capture 1 out of every 'rate' frames (default 1)
15 # -w width : initial window width (default interactive placement)
16 # -d : drop fields if needed
17 # -g bits : greyscale (2, 4 or 8 bits)
18 # -G : 2-bit greyscale dithered
19 # -m : monochrome dithered
20 # -M value : monochrome tresholded with value
21 # -f : Capture fields (in stead of frames)
22 # -n number : Capture 'number' fields (default 60)
24 # moviefile : here goes the movie data (default film.video);
25 # the format is documented in cmif-film.ms
30 # Start the application. Resize the window to the desired movie size.
31 # Press the left mouse button to start recording, release it to end
32 # recording. You can record as many times as you wish, but each time
33 # you overwrite the output file(s), so only the last recording is
36 # Press ESC or select the window manager Quit or Close window option
37 # to quit. If you quit before recording anything, the output file(s)
42 sys
.path
.append('/ufs/guido/src/video')
57 format
= SV
.RGB8_FRAMES
68 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'r:w:dg:mM:Gfn:')
71 rate
= string
.atoi(arg
)
73 sys
.stderr
.write('-r rate must be >= 2\n')
76 width
= string
.atoi(arg
)
81 greybits
= string
.atoi(arg
)
82 if not greybits
in (2,4,8):
83 print 'Only 2, 4 or 8 bit greyscale supported'
91 monotreshold
= string
.atoi(arg
)
95 number
= string
.atoi(arg
)
98 sys
.stderr
.write('usage: Vrec [options] [file]\n')
104 filename
= 'film.video'
107 # Determine maximum window size based on signal standard
108 param
= [SV
.BROADCAST
, 0]
110 if param
[1] == SV
.PAL
:
113 elif param
[1] == SV
.NTSC
:
117 print 'Unknown video standard', param
[1]
125 gl
.prefsize(width
, width
*3/4)
126 win
= gl
.winopen(filename
)
138 param
= [SV
.FIELDDROP
, 1, SV
.GENLOCK
, SV
.GENLOCK_OFF
]
140 param
= [SV
.FIELDDROP
, 0, SV
.GENLOCK
, SV
.GENLOCK_ON
]
142 param
= param
+[SV
.COLOR
, SV
.MONO
, SV
.INPUT_BYPASS
, 1]
144 param
= param
+[SV
.COLOR
, SV
.DEFAULT_COLOR
, SV
.INPUT_BYPASS
, 0]
147 v
.BindGLWindow(win
, SV
.IN_REPLACE
)
149 gl
.qdevice(DEVICE
.LEFTMOUSE
)
150 gl
.qdevice(DEVICE
.WINQUIT
)
151 gl
.qdevice(DEVICE
.WINSHUT
)
152 gl
.qdevice(DEVICE
.ESCKEY
)
154 print 'Press left mouse to start recording'
157 dev
, val
= gl
.qread()
158 if dev
== DEVICE
.LEFTMOUSE
:
160 info
= format
, x
, y
, number
, rate
161 record(v
, info
, filename
, mono
, grey
, \
162 greybits
, monotreshold
, fields
)
163 elif dev
== DEVICE
.REDRAW
:
164 # Window resize (or move)
168 v
.BindGLWindow(win
, SV
.IN_REPLACE
)
169 elif dev
in (DEVICE
.ESCKEY
, DEVICE
.WINQUIT
, DEVICE
.WINSHUT
):
176 # Record until the mouse is released (or any other GL event)
177 # XXX audio not yet supported
179 def record(v
, info
, filename
, mono
, grey
, greybits
, monotreshold
, fields
):
181 format
, x
, y
, number
, rate
= info
182 fps
= 59.64 # Fields per second
183 # XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
184 tpf
= 1000.0 / fps
# Time per field in msec
188 gl
.wintitle('(rec) ' + filename
)
190 ninfo
, data
, bitvec
= v
.CaptureBurst(info
)
191 except sv
.error
, arg
:
192 print 'CaptureBurst failed:', arg
194 gl
.wintitle(filename
)
196 gl
.wintitle('(save) '+ filename
)
201 print 'Sorry, format changed.'
204 gl
.wintitle(filename
)
207 if x
*y
*number
<> len(data
):
208 print 'Funny data length: wanted',x
,'*',y
,'*', number
,'=',\
209 x
*y
*number
,'got',len(data
)
210 gl
.wintitle(filename
)
217 # Construct header and write it
219 vout
= VFile
.VoutFile().init(filename
)
222 elif grey
and greybits
== 8:
225 vout
.format
= 'grey'+`
abs(greybits
)`
231 vout
.packfactor
= (1,-2)
233 print 'Sorry, can only save fields at the moment'
234 gl
.wintitle(filename
)
238 # Compute convertor, if needed
243 convertor
= imageop
.grey2grey2
245 convertor
= imageop
.grey2grey4
247 convertor
= imageop
.dither2grey2
251 tpf
= 1000 / 50.0 #XXXX
252 for frameno
in range(0, number
*2):
253 if frameno
<> 0 and \
254 bitvec
[frameno
] == bitvec
[frameno
-1]:
255 nskipped
= nskipped
+ 1
259 # XXXX Works only for fields and top-to-bottom
261 start
= frameno
*fieldsize
262 field
= data
[start
:start
+fieldsize
]
264 field
= convertor(field
, x
, y
)
265 elif mono
and monotreshold
>= 0:
266 field
= imageop
.grey2mono(field
, x
, y
, \
269 field
= imageop
.dither2mono(field
, x
, y
)
270 vout
.writeframe(int(realframeno
*tpf
), field
, None)
271 print 'Skipped',nskipped
,'duplicate frames'
274 gl
.wintitle('(done) ' + filename
)
276 # Don't forget to call the main program
280 except KeyboardInterrupt: