10 sys
.path
.append('/ufs/guido/src/video') # Increase chance to find colorsys
17 epoch
.correcttiming
= 1
18 EndOfFile
= 'End of file'
23 conf
.setqueuesize(BUFFERSIZE
)
24 conf
.setwidth(AL
.SAMPLE_16
)
25 conf
.setchannels(AL
.MONO
)
26 return al
.openport('spkr','w',conf
)
32 sys
.stderr
.write(name
+ ': cannot open\n')
35 if not line
: raise EndOfFile
36 colorinfo
= (8, 0, 0, 0)
37 if line
[:4] == 'CMIF':
38 if line
[:14] == 'CMIF video 2.0':
40 colorinfo
= eval(line
[:-1])
43 if len(x
) == 3: w
, h
, pf
= x
44 else: w
, h
= x
; pf
= 2
45 if pf
and w
/pf
% 4 <> 0:
47 'warning: stride not a multiple of 4 -- may not work on Indigo XS\n')
48 return f
, w
, h
, pf
, colorinfo
50 def loadframe(f
,w
,h
,pf
,af
,spkr
, (ybits
,ibits
,qbits
,chrompack
),mf
):
55 if type(x
) == type(0) or type(x
) == type(0.0):
60 size
= (w
/pf
) * (h
/pf
)
70 cw
= (w
+chrompack
-1)/chrompack
71 ch
= (h
+chrompack
-1)/chrompack
72 chromdata
= f
.read(2*cw
*ch
)
73 rectzoom(pf
*chrompack
*mf
,pf
*chrompack
*mf
)
75 writemask(0x7ff - ((1<<ybits
)-1))
76 lrectwrite(0,0,cw
-1,ch
-1,chromdata
)
77 writemask((1<<ybits
)-1)
80 rectzoom(pf
*mf
, pf
*mf
)
83 lrectwrite(0,0,w
-1,h
-1,data
)
84 # This is ugly here, but the only way to get the two
85 # channels started in sync
88 ct
= time
.millitimer() - epoch
.epoch
89 if epoch
.correcttiming
and tijd
> 0 and ct
< tijd
:
90 time
.millisleep(tijd
-ct
)
94 def initcmap(ybits
,ibits
,qbits
,chrompack
):
95 if ybits
+ibits
+qbits
> 11:
96 raise 'Sorry, 11 bits max'
100 for i
in range(2048,4096-256):
101 mapcolor(i
, 0, 255, 0)
102 for y
in range(maxy
):
103 yv
= float(y
)/float(maxy
-1)
104 for i
in range(maxi
):
106 else: iv
= (float(i
)/float(maxi
-1))-0.5
107 for q
in range(maxq
):
109 else: qv
= (float(q
)/float(maxq
-1))-0.5
110 index
= 2048 + y
+ (i
<< ybits
) + (q
<< (ybits
+ibits
))
111 rv
,gv
,bv
= colorsys
.yiq_to_rgb(yv
,iv
,qv
)
112 r
,g
,b
= int(rv
*255.0), int(gv
*255.0), int(bv
*255.0)
113 if index
< 4096 - 256:
114 mapcolor(index
, r
,g
,b
)
116 def playsound(af
, spkr
):
117 nsamp
= spkr
.getfillable()
118 data
= af
.read(nsamp
*2)
119 spkr
.writesamps(data
)
126 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'm:p:lF')
128 sys
.stderr
.write('usage: video ' + \
129 '[-l] [-p pf] [-m mag] [-F] [moviefile [soundfile [skipbytes]]]\n')
131 for opt
, arg
in opts
:
133 magfactor
= int(eval(arg
))
135 packfactor
= int(eval(arg
))
139 epoch
.correcttiming
= 0
143 filename
= 'film.video'
144 f
, w
, h
, pf
, cinfo
= openvideo(filename
)
145 if 0 < packfactor
<> pf
:
150 audiofilename
= args
[1]
151 af
= open(audiofilename
, 'r')
155 afskip
= eval(args
[2])
158 af
, spkr
= None, None
160 prefsize(w
*magfactor
,h
*magfactor
)
161 win
= winopen(filename
)
174 pixmode(PM_SIZE
,8) # 8 bit pixels
179 epoch
.epoch
= time
.millitimer()
188 tijd
= loadframe(f
, w
, h
, pf
, af
, spkr
, cinfo
,magfactor
)
192 t
= time
.millitimer()
195 print 0.1 * int(nframe
* 10000.0 / tijd
),
197 print 'Played', nframe
, 'frames at',
198 print 0.1 * int(nframe
* 10000.0 / (t
-epoch
.epoch
)),
202 epoch
.epoch
= time
.millitimer()
209 if not running
or qtest():
211 if dev
in (ESCKEY
, WINSHUT
, WINQUIT
):