blob: d32bc1f8019f22eedd63b7752e821fcbdae834ec [file] [log] [blame]
Guido van Rossum5d731fc1991-11-04 15:54:22 +00001# Copy a video file, interactively, frame-by-frame.
2
3import sys
4import getopt
5from gl import *
6from DEVICE import *
Guido van Rossumcbc1d901992-03-18 13:04:25 +00007import VFile
Jack Jansen3b253711992-12-14 12:25:21 +00008import string
9import imageop
Guido van Rossum5d731fc1991-11-04 15:54:22 +000010
11def report(time, iframe):
12 print 'Frame', iframe, ': t =', time
13
14def usage():
Jack Jansen3b253711992-12-14 12:25:21 +000015 sys.stderr.write('usage: vcopy [-t type] [-m treshold] [-a] infile outfile\n')
16 sys.stderr.write('-t Convert to other type\n')
17 sys.stderr.write('-a Automatic\n')
18 sys.stderr.write('-m Convert grey to mono with treshold\n')
19 sys.stderr.write('-d Convert grey to mono with dithering\n')
Guido van Rossum5d731fc1991-11-04 15:54:22 +000020 sys.exit(2)
21
22def help():
23 print 'Command summary:'
24 print 'n get next image from input'
25 print 'w write current image to output'
26
27def main():
Guido van Rossumcbc1d901992-03-18 13:04:25 +000028 foreground()
Jack Jansen3b253711992-12-14 12:25:21 +000029 opts, args = getopt.getopt(sys.argv[1:], 't:am:d')
Guido van Rossum5d731fc1991-11-04 15:54:22 +000030 if len(args) <> 2:
31 usage()
32 [ifile, ofile] = args
Guido van Rossumcbc1d901992-03-18 13:04:25 +000033 print 'open film ', ifile
34 ifilm = VFile.VinFile().init(ifile)
35 print 'open output ', ofile
36 ofilm = VFile.VoutFile().init(ofile)
37
38 ofilm.setinfo(ifilm.getinfo())
39
40 use_grabber = 0
41 continuous = 0
Jack Jansen3b253711992-12-14 12:25:21 +000042 tomono = 0
43 tomonodither = 0
Guido van Rossumcbc1d901992-03-18 13:04:25 +000044 for o, a in opts:
45 if o == '-t':
46 ofilm.format = a
47 use_grabber = 1
48 if o == '-a':
49 continuous = 1
Jack Jansen3b253711992-12-14 12:25:21 +000050 if o == '-m':
51 if ifilm.format <> 'grey':
52 print '-m only supported for greyscale'
53 sys.exit(1)
54 tomono = 1
55 treshold = string.atoi(a)
56 ofilm.format = 'mono'
57 if o == '-d':
58 if ifilm.format <> 'grey':
59 print '-m only supported for greyscale'
60 sys.exit(1)
61 tomonodither = 1
62 ofilm.format = 'mono'
63
Guido van Rossumcbc1d901992-03-18 13:04:25 +000064 ofilm.writeheader()
Guido van Rossum5d731fc1991-11-04 15:54:22 +000065 #
Guido van Rossumcbc1d901992-03-18 13:04:25 +000066 prefsize(ifilm.width, ifilm.height)
67 w = winopen(ifile)
Guido van Rossum5d731fc1991-11-04 15:54:22 +000068 qdevice(KEYBD)
69 qdevice(ESCKEY)
70 qdevice(WINQUIT)
71 qdevice(WINSHUT)
Guido van Rossumcbc1d901992-03-18 13:04:25 +000072 print 'qdevice calls done'
Guido van Rossum5d731fc1991-11-04 15:54:22 +000073 #
74 help()
75 #
Guido van Rossumcbc1d901992-03-18 13:04:25 +000076 time, data, cdata = ifilm.getnextframe()
77 ifilm.showframe(data, cdata)
Guido van Rossum5d731fc1991-11-04 15:54:22 +000078 iframe = 1
79 report(time, iframe)
80 #
81 while 1:
Guido van Rossumcbc1d901992-03-18 13:04:25 +000082 if continuous:
83 dev = KEYBD
84 else:
85 dev, val = qread()
Guido van Rossum5d731fc1991-11-04 15:54:22 +000086 if dev in (ESCKEY, WINQUIT, WINSHUT):
87 break
Guido van Rossumf47d0481992-02-11 14:50:22 +000088 if dev == REDRAW:
Guido van Rossum5d731fc1991-11-04 15:54:22 +000089 reshapeviewport()
Guido van Rossumf47d0481992-02-11 14:50:22 +000090 elif dev == KEYBD:
Guido van Rossumcbc1d901992-03-18 13:04:25 +000091 if continuous:
92 c = '0'
93 else:
94 c = chr(val)
95 #XXX Debug
96 if c == 'R':
97 c3i(255,0,0)
98 clear()
99 if c == 'G':
100 c3i(0,255,0)
101 clear()
102 if c == 'B':
103 c3i(0,0,255)
104 clear()
105 if c == 'w' or continuous:
106 if use_grabber:
107 data, cdata = ofilm.grabframe()
Jack Jansen3b253711992-12-14 12:25:21 +0000108 if tomono:
109 data = imageop.grey2mono(data, \
110 ifilm.width, ifilm.height, \
111 treshold)
112 if tomonodither:
113 data = imageop.dither2mono(data, \
114 ifilm.width, ifilm.height)
Guido van Rossumcbc1d901992-03-18 13:04:25 +0000115 ofilm.writeframe(time, data, cdata)
116 print 'Frame', iframe, 'written.'
117 if c == 'n' or continuous:
Guido van Rossum5d731fc1991-11-04 15:54:22 +0000118 try:
Guido van Rossumcbc1d901992-03-18 13:04:25 +0000119 time,data,cdata = ifilm.getnextframe()
120 ifilm.showframe(data, cdata)
Guido van Rossum5d731fc1991-11-04 15:54:22 +0000121 iframe = iframe+1
122 report(time, iframe)
123 except EOFError:
124 print 'EOF'
Guido van Rossumcbc1d901992-03-18 13:04:25 +0000125 if continuous:
126 break
Guido van Rossum5d731fc1991-11-04 15:54:22 +0000127 ringbell()
Guido van Rossumf47d0481992-02-11 14:50:22 +0000128 elif dev == INPUTCHANGE:
Guido van Rossum5d731fc1991-11-04 15:54:22 +0000129 pass
130 else:
131 print '(dev, val) =', (dev, val)
Guido van Rossumcbc1d901992-03-18 13:04:25 +0000132 ofilm.close()
Guido van Rossum5d731fc1991-11-04 15:54:22 +0000133
134main()