1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# Copy a video file, interactively, frame-by-frame.
import sys
import getopt
from gl import *
from DEVICE import *
def loadframe(f, w, h, pf):
line = f.readline()
if not line or line = '\n':
raise EOFError
x = eval(line[:-1])
if type(x) = type(0):
if pf: size = w*h*4
else: size = w*h*pf
else:
time, size = x
data = f.read(size)
if len(data) <> size:
raise EOFError
if pf:
windata = unpackrect(w/pf, h/pf, 1, data)
rectzoom(pf, pf)
lrectwrite(0, 0, w/pf-1, h/pf-1, windata)
else:
lrectwrite(0, 0, w-1, h-1, data)
return time, data
def report(time, iframe):
print 'Frame', iframe, ': t =', time
def usage():
sys.write('usage: vcopy infile outfile\n')
sys.exit(2)
def help():
print 'Command summary:'
print 'n get next image from input'
print 'w write current image to output'
def main():
opts, args = getopt.getopt(sys.argv[1:], '')
if len(args) <> 2:
usage()
[ifile, ofile] = args
ifp = open(ifile, 'r')
ofp = open(ofile, 'w')
#
line = ifp.readline()
if line[:4] = 'CMIF':
line = ifp.readline()
x = eval(line[:-1])
if len(x) = 3:
w, h, pf = x
else:
w, h = x
pf = 2
if pf:
w = (w/pf)*pf
h = (h/pf)*pf
#
ofp.write('CMIF video 1.0\n')
ofp.write(`w, h, pf` + '\n')
#
foreground()
prefsize(w, h)
wid = winopen(ifile + ' -> ' + ofile)
RGBmode()
gconfig()
qdevice(KEYBD)
qdevice(ESCKEY)
qdevice(WINQUIT)
qdevice(WINSHUT)
#
help()
#
time, data = loadframe(ifp, w, h, pf)
iframe = 1
report(time, iframe)
#
while 1:
dev, val = qread()
if dev in (ESCKEY, WINQUIT, WINSHUT):
break
if dev = REDRAW:
reshapeviewport()
elif dev = KEYBD:
c = chr(val)
if c = 'n':
try:
time, data = loadframe(ifp, w, h, pf)
iframe = iframe+1
report(time, iframe)
except EOFError:
print 'EOF'
ringbell()
elif c = 'w':
ofp.write(`time, len(data)` + '\n')
ofp.write(data)
print 'Frame', iframe, 'written.'
else:
print 'Character', `c`, 'ignored'
elif dev = INPUTCHANGE:
pass
else:
print '(dev, val) =', (dev, val)
main()
|