@@ -19,15 +19,21 @@ def openspkr():
1919 conf .setwidth (AL .SAMPLE_16 )
2020 conf .setchannels (AL .MONO )
2121 return al .openport ('spkr' ,'w' ,conf )
22+
2223def openvideo (name ):
23- f = open (name , 'r' )
24+ try :
25+ f = open (name , 'r' )
26+ except :
27+ sys .stderr .write (name + ': cannot open\n ' )
28+ sys .exit (1 )
2429 line = f .readline ()
2530 if not line : raise EndOfFile
2631 if line [:4 ] = 'CMIF' : line = f .readline ()
2732 x = eval (line [:- 1 ])
2833 if len (x ) = 3 : w , h , pf = x
2934 else : w , h = x ; pf = 2
3035 return f , w , h , pf
36+
3137def loadframe (f ,w ,h ,pf ,af ,spkr ):
3238 line = f .readline ()
3339 if line = '' :
@@ -57,56 +63,66 @@ def loadframe(f,w,h,pf,af,spkr):
5763 ct = time .millitimer () - epoch .epoch
5864 if tijd > 0 and ct < tijd :
5965 time .millisleep (tijd - ct )
60- swapbuffers ()
66+ # swapbuffers()
6167 return tijd
68+
6269def playsound (af , spkr ):
6370 nsamp = spkr .getfillable ()
6471 data = af .read (nsamp * 2 )
6572 spkr .writesamps (data )
73+
6674def main ():
67- if len (sys .argv ) > 1 :
68- f , w , h , pf = openvideo (sys .argv [1 ])
69- else :
70- f , w , h , pf = openvideo ('film.video' )
71- af = None
72- spkr = None
73- if len (sys .argv ) > 2 :
74- af = open (sys .argv [2 ], 'r' )
75- spkr = openspkr ()
76- if len (sys .argv ) > 3 :
77- data = af .read (eval (sys .argv [3 ]))
78- del data
79- foreground ()
80- prefsize (w ,h )
81- win = winopen ('Video player' )
82- RGBmode ()
83- doublebuffer ()
84- gconfig ()
85- qdevice (ESCKEY )
86- running = 1
87- epoch .epoch = time .millitimer ()
88- nframe = 0
89- tijd = 1
90- try :
91- while 1 :
92- if running :
93- try :
94- tijd = loadframe (f , w , h , pf , af , spkr )
95- nframe = nframe + 1
96- except EndOfFile :
97- running = 0
98- t = time .millitimer ()
99- if tijd > 0 :
100- print 'Recorded at ' , nframe * 1000.0 / tijd ,
101- print 'frames/second (' , tijd , 'ms total)'
102- print 'Played at' , nframe * 1000.0 / (t - epoch .epoch ),
103- print 'frames/second'
104- if af <> None :
105- playsound (af ,spkr )
106- if qtest ():
107- if qread () = (ESCKEY ,1 ):
108- raise bye
109- except bye :
110- pass
75+ foreground ()
76+ if len (sys .argv ) > 1 :
77+ filename = sys .argv [1 ]
78+ else :
79+ filename = 'film.video'
80+ f , w , h , pf = openvideo (filename )
81+ if len (sys .argv ) > 2 :
82+ audiofilename = sys .argv [2 ]
83+ af = open (audiofilename , 'r' )
84+ spkr = openspkr ()
85+ if len (sys .argv ) > 3 :
86+ af .seek (eval (sys .argv [3 ]))
87+ else :
88+ af , spkr = None , None
89+ prefsize (w ,h )
90+ win = winopen (filename )
91+ RGBmode ()
92+ #doublebuffer()
93+ gconfig ()
94+ qdevice (ESCKEY )
95+ qdevice (WINSHUT )
96+ qdevice (WINQUIT )
97+ running = 1
98+ epoch .epoch = time .millitimer ()
99+ nframe = 0
100+ tijd = 1
101+ try :
102+ while 1 :
103+ if running :
104+ try :
105+ tijd = loadframe (f , w , h , pf , af , spkr )
106+ nframe = nframe + 1
107+ except EndOfFile :
108+ running = 0
109+ t = time .millitimer ()
110+ if tijd > 0 :
111+ print 'Recorded at' ,
112+ print 0.1 * int (nframe * 10000.0 / tijd ),
113+ print 'frames/sec'
114+ print 'Played' , nframe , 'frames at' ,
115+ print 0.1 * int (nframe * 10000.0 / (t - epoch .epoch )),
116+ print 'frames/sec'
117+ if af <> None :
118+ playsound (af ,spkr )
119+ if not running or qtest ():
120+ dev , val = qread ()
121+ if dev in (ESCKEY , WINSHUT , WINQUIT ):
122+ raise bye
123+ elif dev = REDRAW :
124+ reshapeviewport ()
125+ except bye :
126+ pass
111127
112128main ()
0 commit comments