Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85f7bd5

Browse files
committed
Vrec.py, Vrecb.py:
- call v.SetParam() after v.BindGLWindow() - turn of dithering in mono/grey mode - use prefposition to place the top left corner at (150, 150) (so that the video remains visible during recording) - default width is 256 Vcopy.py: correct typos; more verbose output. OldVcopy.py: new name for Jack's old grabbing Vcopy.py. Vstat.py: print values of all video parameters.
1 parent c97d2ed commit 85f7bd5

6 files changed

Lines changed: 201 additions & 12 deletions

File tree

Demo/sgi/video/OldVcopy.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#! /ufs/guido/bin/sgi/python
2+
3+
# Copy a video file, interactively, frame-by-frame.
4+
5+
import sys
6+
import getopt
7+
from gl import *
8+
from DEVICE import *
9+
import VFile
10+
import VGrabber
11+
import string
12+
import imageop
13+
14+
def report(time, iframe):
15+
print 'Frame', iframe, ': t =', time
16+
17+
def usage():
18+
sys.stderr.write('usage: Vcopy [-t type] [-m treshold] [-a] infile outfile\n')
19+
sys.stderr.write('-t Convert to other type\n')
20+
sys.stderr.write('-a Automatic\n')
21+
sys.stderr.write('-m Convert grey to mono with treshold\n')
22+
sys.stderr.write('-d Convert grey to mono with dithering\n')
23+
sys.exit(2)
24+
25+
def help():
26+
print 'Command summary:'
27+
print 'n get next image from input'
28+
print 'w write current image to output'
29+
30+
class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber):
31+
pass
32+
33+
def main():
34+
foreground()
35+
try:
36+
opts, args = getopt.getopt(sys.argv[1:], 't:am:d')
37+
except getopt.error, msg:
38+
print msg
39+
usage()
40+
if len(args) <> 2:
41+
usage()
42+
[ifile, ofile] = args
43+
print 'open film ', ifile
44+
ifilm = VFile.VinFile().init(ifile)
45+
print 'open output ', ofile
46+
ofilm = GrabbingVoutFile().init(ofile)
47+
48+
ofilm.setinfo(ifilm.getinfo())
49+
50+
use_grabber = 0
51+
continuous = 0
52+
tomono = 0
53+
tomonodither = 0
54+
for o, a in opts:
55+
if o == '-t':
56+
ofilm.format = a
57+
use_grabber = 1
58+
if o == '-a':
59+
continuous = 1
60+
if o == '-m':
61+
if ifilm.format <> 'grey':
62+
print '-m only supported for greyscale'
63+
sys.exit(1)
64+
tomono = 1
65+
treshold = string.atoi(a)
66+
ofilm.format = 'mono'
67+
if o == '-d':
68+
if ifilm.format <> 'grey':
69+
print '-m only supported for greyscale'
70+
sys.exit(1)
71+
tomonodither = 1
72+
ofilm.format = 'mono'
73+
74+
ofilm.writeheader()
75+
#
76+
prefsize(ifilm.width, ifilm.height)
77+
w = winopen(ifile)
78+
qdevice(KEYBD)
79+
qdevice(ESCKEY)
80+
qdevice(WINQUIT)
81+
qdevice(WINSHUT)
82+
print 'qdevice calls done'
83+
#
84+
help()
85+
#
86+
time, data, cdata = ifilm.getnextframe()
87+
ifilm.showframe(data, cdata)
88+
iframe = 1
89+
report(time, iframe)
90+
#
91+
while 1:
92+
if continuous:
93+
dev = KEYBD
94+
else:
95+
dev, val = qread()
96+
if dev in (ESCKEY, WINQUIT, WINSHUT):
97+
break
98+
if dev == REDRAW:
99+
reshapeviewport()
100+
elif dev == KEYBD:
101+
if continuous:
102+
c = '0'
103+
else:
104+
c = chr(val)
105+
#XXX Debug
106+
if c == 'R':
107+
c3i(255,0,0)
108+
clear()
109+
if c == 'G':
110+
c3i(0,255,0)
111+
clear()
112+
if c == 'B':
113+
c3i(0,0,255)
114+
clear()
115+
if c == 'w' or continuous:
116+
if use_grabber:
117+
try:
118+
data, cdata = ofilm.grabframe()
119+
except VFile.Error, msg:
120+
print msg
121+
break
122+
if tomono:
123+
data = imageop.grey2mono(data, \
124+
ifilm.width, ifilm.height, \
125+
treshold)
126+
if tomonodither:
127+
data = imageop.dither2mono(data, \
128+
ifilm.width, ifilm.height)
129+
ofilm.writeframe(time, data, cdata)
130+
print 'Frame', iframe, 'written.'
131+
if c == 'n' or continuous:
132+
try:
133+
time,data,cdata = ifilm.getnextframe()
134+
ifilm.showframe(data, cdata)
135+
iframe = iframe+1
136+
report(time, iframe)
137+
except EOFError:
138+
print 'EOF'
139+
if continuous:
140+
break
141+
ringbell()
142+
elif dev == INPUTCHANGE:
143+
pass
144+
else:
145+
print '(dev, val) =', (dev, val)
146+
ofilm.close()
147+
148+
main()

Demo/sgi/video/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ CMIF video tools
44
This directory contains Python and C programs to manipulate files
55
containing digitized video in the "CMIF video format".
66

7+
An introduction to using the basic tools is in the file "video.doc".
8+
9+
A description of the video file format is in the file "cmif-film.ms"
10+
(troff/nroff -ms input).
11+
712

813
History
914
-------

Demo/sgi/video/Vcopy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def process(infilename, outfilename):
166166
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
167167
return 1
168168

169+
print '=== input file ==='
169170
vin.printinfo()
170171

171172
vout.setinfo(vin.getinfo())
@@ -187,7 +188,6 @@ def process(infilename, outfilename):
187188
if not ypf: ypf = vout.ypf
188189
newpf = (xpf, ypf)
189190
vout.setpf(newpf)
190-
scale = 1
191191

192192
if newwidth and newheight:
193193
scale = 1
@@ -221,6 +221,7 @@ def process(infilename, outfilename):
221221
newwidth = newwidth / vout.xpf
222222
newheight = newheight / vout.ypf
223223

224+
print '=== output file ==='
224225
vout.printinfo()
225226
vout.writeheader()
226227

@@ -251,13 +252,14 @@ def process(infilename, outfilename):
251252
inwidth, inheight, newwidth, newheight)
252253
if flip:
253254
x0, y0 = 0, 0
254-
x1, y1 = newwidth-1, neheight-1
255+
x1, y1 = newwidth-1, newheight-1
255256
if vin.upside_down <> vout.upside_down:
256257
y1, y0 = y0, y1
257258
if vin.mirror_image <> vout.mirror_image:
258259
x1, x0 = x0, x1
259260
data = imageop.crop(data, vout.bpp/8, \
260261
newwidth, newheight, x0, y0, x1, y1)
262+
print 'Writing frame', nout
261263
vout.writeframe(tout, data, cdata)
262264
nout = nout + 1
263265

Demo/sgi/video/Vrec.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def usage():
2020
print '-r rate : capture 1 out of every "rate" frames', \
2121
'(default and min 2)'
2222
print '-w width : initial window width', \
23-
'(default interactive placement)'
23+
'(default 256, use 0 for interactive placement)'
2424
print '-n : Don\'t write to file, only timing info'
2525
print '-d : drop fields if needed'
2626
print '-g bits : greyscale (2, 4 or 8 bits)'
@@ -184,7 +184,12 @@ def main():
184184
gl.keepaspect(x, y)
185185
gl.stepunit(8, 6)
186186
if width:
187-
gl.prefsize(width, width*3/4)
187+
height = width*3/4
188+
x1 = 150
189+
x2 = x1 + width-1
190+
y2 = 768-150
191+
y1 = y2-height+1
192+
gl.prefposition(x1, x2, y1, y2)
188193
win = gl.winopen(filename)
189194
if width:
190195
gl.maxsize(x, y)
@@ -201,12 +206,13 @@ def main():
201206
else:
202207
param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
203208
if mono or grey:
204-
param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
209+
param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \
210+
SV.INPUT_BYPASS, 1]
205211
else:
206212
param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
207-
v.SetParam(param)
208213

209214
v.BindGLWindow(win, SV.IN_REPLACE)
215+
v.SetParam(param)
210216

211217
gl.qdevice(DEVICE.LEFTMOUSE)
212218
gl.qdevice(DEVICE.WINQUIT)

Demo/sgi/video/Vrecb.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#! /ufs/guido/bin/sgi/python-405
21
#! /ufs/guido/bin/sgi/python
32

43
# Capture a CMIF movie using the Indigo video library and board in burst mode
@@ -41,7 +40,7 @@ def usage():
4140
print '-r rate : capture 1 out of every "rate" frames', \
4241
'(default and min 1)'
4342
print '-w width : initial window width', \
44-
'(default interactive placement)'
43+
'(default 256, use 0 for interactive placement)'
4544
print '-d : drop fields if needed'
4645
print '-g bits : greyscale (2, 4 or 8 bits)'
4746
print '-G : 2-bit greyscale dithered'
@@ -69,7 +68,7 @@ def main():
6968
format = SV.RGB8_FRAMES
7069
audio = 0
7170
rate = 1
72-
width = 0
71+
width = 256
7372
drop = 0
7473
mono = 0
7574
grey = 0
@@ -167,7 +166,12 @@ def main():
167166
gl.keepaspect(x, y)
168167
gl.stepunit(8, 6)
169168
if width:
170-
gl.prefsize(width, width*3/4)
169+
height = width*3/4
170+
x1 = 150
171+
x2 = x1 + width-1
172+
y2 = 768-150
173+
y1 = y2-height+1
174+
gl.prefposition(x1, x2, y1, y2)
171175
win = gl.winopen(filename)
172176
if width:
173177
gl.maxsize(x, y)
@@ -184,12 +188,13 @@ def main():
184188
else:
185189
param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
186190
if mono or grey:
187-
param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
191+
param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \
192+
SV.INPUT_BYPASS, 1]
188193
else:
189194
param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
190-
v.SetParam(param)
191195

192196
v.BindGLWindow(win, SV.IN_REPLACE)
197+
v.SetParam(param)
193198

194199
gl.qdevice(DEVICE.LEFTMOUSE)
195200
gl.qdevice(DEVICE.WINQUIT)

Demo/sgi/video/Vstat.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /ufs/guido/bin/sgi/python
2+
3+
# Print the value of all video parameters
4+
5+
import sys
6+
import sv, SV
7+
8+
def main():
9+
v = sv.OpenVideo()
10+
for name in dir(SV):
11+
const = getattr(SV, name)
12+
if type(const) is type(0):
13+
sys.stdout.flush()
14+
params = [const, 0]
15+
try:
16+
v.GetParam(params)
17+
except sv.error, msg:
18+
## print name, msg
19+
continue
20+
print name, params
21+
22+
main()
23+

0 commit comments

Comments
 (0)