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

Skip to content

Commit e4bddea

Browse files
committed
Initial revision
1 parent baf0ebf commit e4bddea

13 files changed

Lines changed: 1363 additions & 0 deletions

File tree

Demo/sgi/video/README

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
This directory contains Python and C code we wrote while we had a
2+
framegrabber board on loan from SGI.
3+
4+
--Guido and Jack
5+
6+
cam.py network real-time tv broadcast; see tv.py
7+
usage: cam [packfactor [host]]
8+
specifying 'all' for host broadcasts
9+
10+
camcorder.py record video movies or make snapshots (in movie format)
11+
usage: camcorder [-c] [-a audiohost [-s]] [moviefile]
12+
-c color (default b/w, packfactor = 2)
13+
-a audiohost syncaudio is running on audiohost
14+
-s start syncaudio (on audiohost)
15+
moviefile (default film.video)
16+
keyboard commands:
17+
s stop grabbing (single step if already stopped)
18+
c continuous grabbing
19+
r start recording
20+
p pause recording (record single frame if paused)
21+
ESC quit
22+
23+
statit.py various statistics operations on movie files
24+
25+
syncaudio.py record audio synchronized with camcorder -a
26+
usage: syncaudio videohost soundfile
27+
soundfile format: 16 bits, 16khz, mono
28+
29+
tv.py receiver for transmissions from cam.py
30+
31+
video.py player for movies recorded by camcorder.py
32+
usage: video [moviefile [soundfile]]
33+
default moviefile is film.video
34+
default sound is no sound
35+
36+
vinfo.py print a summary of a movie file
37+
38+
vtime.py virtual time module imported by syncaudio.py and camcorder.py
39+
40+
41+
These are C programs, either for efficiency or because they need to
42+
link with a C library.
43+
44+
squash.c make a movie smaller by averaging pixels
45+
usage: squash factor [bits] <moviefile >newmoviefile
46+
factor x and y compression factor
47+
bits #bits left per sample in result (default 8)
48+
49+
squash2.c make a movie smaller by dropping pixels
50+
usage: squash2 factor <moviefile >newmoviefile
51+
factor x and y compression factor
52+
53+
tomono.c like squash2 but outputs a monochrome movie
54+
55+
v2i.c convert the first image of a movie file to SGI .rgb format
56+
link with -limage

Demo/sgi/video/cam.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import sys
2+
from socket import *
3+
from gl import *
4+
from GL import *
5+
from DEVICE import *
6+
from time import millitimer
7+
8+
HS = 40 # Header size (must be same as in tv.py)
9+
10+
# Rely on UDP packet (de)fragmentation for smoother images
11+
# (Changed for broadcast)
12+
MAX = 16000
13+
14+
PF = 2 # Default packfactor
15+
16+
# Default receiver station is voorn.
17+
# Kwik has no yellow pages, so...
18+
HOST = '192.16.201.121'
19+
PORT = 5555
20+
21+
if sys.argv[1:]:
22+
PF = eval(sys.argv[1])
23+
24+
if sys.argv[2:]:
25+
HOST = sys.argv[2]
26+
if HOST = 'all':
27+
HOST = '<broadcast>'
28+
MAX = 1400
29+
30+
PF2 = PF*PF
31+
32+
def main():
33+
centerx, centery = 400, 300
34+
35+
foreground()
36+
wid = winopen('cam')
37+
RGBmode()
38+
doublebuffer()
39+
gconfig()
40+
qdevice(ESCKEY)
41+
42+
w, h = getsize()
43+
ortho2(0, w, 0, h)
44+
w = w/PF*PF
45+
h = h/PF*PF
46+
47+
readsource(SRC_FRAMEGRABBER)
48+
49+
s = socket(AF_INET, SOCK_DGRAM)
50+
if HOST = '<broadcast>':
51+
s.allowbroadcast(1)
52+
addr = HOST, PORT
53+
54+
bytesperline = w/PF2
55+
linesperchunk = MAX/bytesperline
56+
linesperchunk = linesperchunk/PF*PF
57+
nchunks = (h+linesperchunk-1)/linesperchunk
58+
59+
print 'MAX=', MAX,
60+
print 'linesperchunk=', linesperchunk,
61+
print 'nchunks=', nchunks,
62+
print 'w=', w, 'h=', h
63+
64+
x1, x2 = 0, w-1
65+
66+
t1 = millitimer()
67+
nframes = 0
68+
fps = 0
69+
70+
msg = ''
71+
72+
while 1:
73+
while qtest():
74+
dev, val = qread()
75+
if dev = REDRAW:
76+
reshapeviewport()
77+
w, h = getsize()
78+
ortho2(0, w, 0, h)
79+
w = w/PF*PF
80+
h = h/PF*PF
81+
82+
bytesperline = w/PF2
83+
linesperchunk = MAX/bytesperline
84+
linesperchunk = linesperchunk/PF*PF
85+
nchunks = (h+linesperchunk-1)/linesperchunk
86+
87+
print 'MAX=', MAX,
88+
print 'linesperchunk=', linesperchunk,
89+
print 'nchunks=', nchunks,
90+
print 'w=', w, 'h=', h
91+
92+
x1, x2 = 0, w-1
93+
94+
fps = 0
95+
96+
elif dev = ESCKEY:
97+
winclose(wid)
98+
return
99+
100+
readsource(SRC_FRAMEGRABBER)
101+
102+
nframes = nframes+1
103+
if nframes >= fps:
104+
t2 = millitimer()
105+
if t2 <> t1:
106+
fps = int(10000.0*nframes/(t2-t1)) * 0.1
107+
msg = `fps` + ' frames/sec'
108+
t1 = t2
109+
nframes = 0
110+
111+
RGBcolor(255,255,255)
112+
cmov2i(9,9)
113+
charstr(msg)
114+
115+
swapbuffers()
116+
rectcopy(centerx-w/2, centery-w/2, centerx+w/2, centery+w/2, 0, 0)
117+
118+
for i in range(nchunks):
119+
y1 = i*linesperchunk
120+
y2 = y1 + linesperchunk-1
121+
if y2 >= h: y2 = h-1
122+
data = lrectread(x1, y1, x2, y2)
123+
data2 = packrect(x2-x1+1, y2-y1+1, PF, data)
124+
prefix = `w, h, PF, x1, y1, x2, y2`
125+
prefix = prefix + ' ' * (HS-len(prefix))
126+
data3 = prefix + data2
127+
s.sendto(data3, addr)
128+
129+
main()

Demo/sgi/video/camcorder.py

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/ufs/guido/bin/sgi/python3.3
2+
from gl import *
3+
from GL import *
4+
from DEVICE import *
5+
import time
6+
import sys
7+
import getopt
8+
import socket
9+
import posix
10+
import vtime
11+
12+
SYNCPORT = 10000
13+
CTLPORT = 10001
14+
15+
VP_GBXORG = 0x1000001
16+
VP_GBYORG = 0x1000002
17+
VP_FBXORG = 0x1000003
18+
VP_FBYORG = 0x1000004
19+
VP_WIDTH = 0x1000005
20+
VP_HEIGHT = 0x1000006
21+
22+
class Struct(): pass
23+
epoch = Struct()
24+
25+
def getvideosize():
26+
w = getvideo(VP_WIDTH)
27+
h = getvideo(VP_HEIGHT)
28+
print getvideo(VP_GBXORG), getvideo(VP_GBYORG)
29+
print getvideo(VP_FBXORG), getvideo(VP_FBYORG)
30+
x = 0
31+
y = 0
32+
return x,y,w,h
33+
def saveframe(f,x,y,w,h,pf, notime):
34+
readsource(SRC_FRONT)
35+
if pf:
36+
w = w/pf*pf
37+
h = h/pf*pf
38+
data = None
39+
data = lrectread(x,y,x+w-1,y+h-1)
40+
if pf: data = packrect(w,h,pf,data)
41+
if notime: t = 0
42+
else: t = time.millitimer()-epoch.epoch
43+
f.write(`t` + ',' + `len(data)` + '\n')
44+
f.write(data)
45+
readsource(SRC_FRAMEGRABBER)
46+
def drawframe(x,y,w,h,col):
47+
drawmode(OVERDRAW)
48+
color(col)
49+
bgnline()
50+
v2i(x-1,y-1) ; v2i(x+w,y-1); v2i(x+w,y+h); v2i(x-1,y+h); v2i(x-1,y-1)
51+
endline()
52+
drawmode(NORMALDRAW)
53+
def main():
54+
foreground()
55+
pf = 2
56+
ausync = 0
57+
austart = 0
58+
optlist, args = getopt.getopt(sys.argv[1:],'ca:s')
59+
for opt, arg in optlist:
60+
if opt = '-c':
61+
pf = 0
62+
elif opt = '-a':
63+
ausync = 1
64+
aumachine = arg
65+
elif opt = '-s':
66+
austart = 1
67+
else:
68+
print 'Usage: camcorder [-c] [-a audiomachine [-s]]'
69+
sys.exit(1)
70+
if austart:
71+
if not ausync:
72+
print 'Cannot use -s without -a'
73+
sys.exit(1)
74+
print 'Starting audio recorder...'
75+
posix.system('rsh '+aumachine+' syncrecord '+socket.gethostname()+' &')
76+
if ausync:
77+
print 'Syncing to audio recorder...'
78+
globtime = vtime.VTime().init(1,aumachine,SYNCPORT)
79+
ctl = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
80+
ctl.bind((socket.gethostname(),CTLPORT))
81+
aua = (socket.gethostbyname(aumachine), CTLPORT)
82+
print 'Done.'
83+
vidx, vidy, w, h = getvideosize()
84+
prefsize(w,h)
85+
win = winopen('Camcorder')
86+
if len(args) > 1:
87+
f = open(args, 'w')
88+
else:
89+
f = open('film.video', 'w')
90+
w, h = getsize()
91+
realw, realh = w, h
92+
doublebuffer()
93+
RGBmode()
94+
gconfig()
95+
qdevice(LEFTMOUSE)
96+
qdevice(RKEY)
97+
qdevice(SKEY)
98+
qdevice(CKEY)
99+
qdevice(PKEY)
100+
qdevice(ESCKEY)
101+
inrunning = 1
102+
outrunning = 0
103+
stop = 'stop'
104+
readsource(SRC_FRAMEGRABBER)
105+
mousing = 0
106+
epoch.epoch = time.millitimer()
107+
stoptime = epoch.epoch
108+
sizewritten = 0
109+
x, y = realw/4, realh/4
110+
w, h = w/2, h/2
111+
drawframe(x,y,w,h,1)
112+
nframe = 0
113+
try:
114+
num = 0
115+
while 1:
116+
insingle = 0
117+
outsingle = 0
118+
if mousing:
119+
drawframe(x,y,w,h,0)
120+
ox, oy = getorigin()
121+
if sizewritten:
122+
x = getvaluator(MOUSEX)-ox
123+
y = getvaluator(MOUSEY)-oy
124+
else:
125+
w = getvaluator(MOUSEX)-x-ox
126+
h = getvaluator(MOUSEY)-y-oy
127+
drawframe(x,y,w,h,1)
128+
if qtest():
129+
ev, val = qread()
130+
if ev = LEFTMOUSE and val = 1:
131+
drawframe(x,y,w,h,0)
132+
mousing = 1
133+
ox, oy = getorigin()
134+
x = getvaluator(MOUSEX)-ox
135+
y = getvaluator(MOUSEY)-oy
136+
elif ev = LEFTMOUSE and val = 0:
137+
mousing = 0
138+
if not sizewritten:
139+
f.write('CMIF video 1.0\n')
140+
f.write(`w,h,pf` + '\n')
141+
sizewritten = 1
142+
if ev = RKEY and val = 1:
143+
if not inrunning:
144+
ringbell()
145+
else:
146+
outrunning = 1
147+
wasstopped = time.millitimer() - stoptime
148+
epoch.epoch = epoch.epoch + wasstopped
149+
nframe = 0
150+
starttime = time.millitimer()
151+
if ausync:
152+
ctl.sendto(`(1,starttime)`, aua)
153+
elif ev = PKEY and val = 1 and outrunning:
154+
outrunning = 0
155+
stoptime = time.millitimer()
156+
if ausync:
157+
ctl.sendto(`(0,stoptime)`, aua)
158+
nf = nframe * 1000.0 / (time.millitimer()-starttime)
159+
drawmode(OVERDRAW)
160+
color(0)
161+
clear()
162+
color(1)
163+
cmov2i(5,5)
164+
charstr('Recorded ' + `nf` + ' frames/sec')
165+
drawmode(NORMALDRAW)
166+
elif ev = PKEY and val = 1 and not outrunning:
167+
outsingle = 1
168+
elif ev = CKEY and val = 1:
169+
inrunning = 1
170+
elif ev = SKEY and val = 1:
171+
if outrunning:
172+
ringbell()
173+
elif inrunning:
174+
inrunning = 0
175+
else:
176+
insingle = 1
177+
elif ev = ESCKEY:
178+
if ausync:
179+
ctl.sendto(`(2,time.millitimer())`, aua)
180+
raise stop
181+
if inrunning or insingle:
182+
rectcopy(vidx,vidy,realw,realh,0,0)
183+
swapbuffers()
184+
if outrunning or outsingle:
185+
nframe = nframe + 1
186+
if not sizewritten:
187+
f.write('CMIF video 1.0\n')
188+
f.write(`w,h,pf` + '\n')
189+
sizewritten = 1
190+
saveframe(f, x, y, w, h, pf, outsingle)
191+
except stop:
192+
pass
193+
drawmode(OVERDRAW)
194+
color(0)
195+
clear()
196+
#
197+
main()

0 commit comments

Comments
 (0)