def show(file): import gl, GL, DEVICE jpegdata = open(file, 'r').read() imgdata, width, height, bytesperpixel = decompress(jpegdata) gl.foreground() gl.prefsize(width, height) win = gl.winopen(file) if bytesperpixel == 1: gl.cmode() gl.pixmode(GL.PM_SIZE, 8) gl.gconfig() for i in range(256): gl.mapcolor(i, i, i, i) else: gl.RGBmode() gl.pixmode(GL.PM_SIZE, 32) gl.gconfig() gl.qdevice(DEVICE.REDRAW) gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.lrectwrite(0, 0, width - 1, height - 1, imgdata) while 1: dev, val = gl.qread() if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT): break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, width - 1, height - 1, imgdata) gl.winclose(win) newjpegdata = compress(imgdata, width, height, bytesperpixel) open('/tmp/j.jpg', 'w').write(newjpegdata)
def main(): format = SV.RGB8_FRAMES requestedwidth = SV.PAL_XMAX queuesize = 30 if sys.argv[1:]: queuesize = eval(sys.argv[1]) v = sv.OpenVideo() svci = (format, requestedwidth, 0, queuesize, 0) go = raw_input('Press return to capture ' + ` queuesize ` + ' frames: ') result = v.CaptureBurst(svci) svci, buffer, bitvec = result ## svci, buffer = result # XXX If bit vector not yet implemented print 'Captured', svci[3], 'frames, i.e.', len(buffer) / 1024, 'K bytes' w, h = svci[1:3] framesize = w * h gl.prefposition(300, 300 + w - 1, 100, 100 + h - 1) gl.foreground() win = gl.winopen('Burst Capture') gl.RGBmode() gl.gconfig() gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.ESCKEY) print 'Click left mouse for next frame' for i in range(svci[3]): inverted_frame = sv.RGB8toRGB32(1, \ buffer[i*framesize:(i+1)*framesize], w, h) gl.lrectwrite(0, 0, w - 1, h - 1, inverted_frame) while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE and val == 1: break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, w - 1, h - 1, inverted_frame) if dev == DEVICE.ESCKEY: v.CloseVideo() gl.winclose(win) return v.CloseVideo() gl.winclose(win)
def main(): format = SV.RGB8_FRAMES requestedwidth = SV.PAL_XMAX queuesize = 30 if sys.argv[1:]: queuesize = eval(sys.argv[1]) v = sv.OpenVideo() svci = (format, requestedwidth, 0, queuesize, 0) go = raw_input('Press return to capture ' + `queuesize` + ' frames: ') result = v.CaptureBurst(svci) svci, buffer, bitvec = result ## svci, buffer = result # XXX If bit vector not yet implemented print 'Captured', svci[3], 'frames, i.e.', len(buffer)/1024, 'K bytes' w, h = svci[1:3] framesize = w * h gl.prefposition(300, 300+w-1, 100, 100+h-1) gl.foreground() win = gl.winopen('Burst Capture') gl.RGBmode() gl.gconfig() gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.ESCKEY) print 'Click left mouse for next frame' for i in range(svci[3]): inverted_frame = sv.RGB8toRGB32(1, \ buffer[i*framesize:(i+1)*framesize], w, h) gl.lrectwrite(0, 0, w-1, h-1, inverted_frame) while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE and val == 1: break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, w-1, h-1, inverted_frame) if dev == DEVICE.ESCKEY: v.CloseVideo() gl.winclose(win) return v.CloseVideo() gl.winclose(win)
def makewindow(self): x, y = self.maxx, self.maxy gl.foreground() gl.maxsize(x, y) gl.keepaspect(x, y) gl.stepunit(8, 6) width = self.curx height = self.cury if width and height: # Place the window at (150, 150) from top left # (the video board likes this location...) x1 = 150 x2 = x1+width-1 SCRHEIGHT = 768 y2 = SCRHEIGHT-1-150 y1 = y2-height+1 gl.prefposition(x1, x2, y1, y2) self.window = gl.winopen('Vb video') self.settitle() if width: gl.maxsize(x, y) gl.keepaspect(x, y) gl.stepunit(8, 6) gl.winconstraints() gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT)
def imageview(file): import cl, CL, gl, GL, DEVICE filep = open(file, 'r') header = filep.read(16) filep.seek(0) scheme = cl.QueryScheme(header) decomp = cl.OpenDecompressor(scheme) headersize = cl.QueryMaxHeaderSize(scheme) header = filep.read(headersize) filep.seek(0) headersize = decomp.ReadHeader(header) width = decomp.GetParam(CL.IMAGE_WIDTH) height = decomp.GetParam(CL.IMAGE_HEIGHT) params = [CL.ORIGINAL_FORMAT, CL.RGBX, \ CL.ORIENTATION, CL.BOTTOM_UP, \ CL.FRAME_BUFFER_SIZE, width*height*CL.BytesPerPixel(CL.RGBX)] decomp.SetParams(params) image = decomp.Decompress(1, filep.read()) filep.close() decomp.CloseDecompressor() gl.foreground() gl.prefsize(width, height) win = gl.winopen(file) gl.RGBmode() gl.pixmode(GL.PM_SIZE, 32) gl.gconfig() gl.qdevice(DEVICE.REDRAW) gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.lrectwrite(0, 0, width-1, height-1, image) while 1: dev, val = gl.qread() if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT): break if dev == DEVICE.REDRAW: gl.lrectwrite(0, 0, width-1, height-1, image) gl.winclose(win)
def main(): gl.foreground() gl.prefsize(SV.PAL_XMAX, SV.PAL_YMAX) win = gl.winopen('video test') v = sv.OpenVideo() params = [SV.VIDEO_MODE, SV.COMP, SV.BROADCAST, SV.PAL] v.SetParam(params) v.BindGLWindow(win, SV.IN_REPLACE) gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) while 1: dev, val = gl.qread() if dev in (DEVICE.ESCKEY, DEVICE.WINSHUT, DEVICE.WINQUIT): v.CloseVideo() gl.winclose(win) return
#! /usr/bin/env python # Capture a CMIF movie using the Indigo video library and board in burst mode # User interface: # # Start the application. Resize the window to the desired movie size. # Press the left mouse button to start recording, release it to end # recording. You can record as many times as you wish, but each time # you overwrite the output file(s), so only the last recording is # kept. # # Press ESC or select the window manager Quit or Close window option # to quit. If you quit before recording anything, the output file(s) # are not touched. import sys sys.path.append('/ufs/guido/src/video') import sv, SV import VFile import gl, GL, DEVICE import al, AL import time import posix import getopt import string import imageop import sgi # Usage and help functions (keep this up-to-date if you change the program!) def usage(): print 'Usage: Vrecb [options] [moviefile [audiofile]]' print
#! /usr/bin/env python # Send live video UDP packets. # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] # [host] .. import sys import time import struct import string import math from socket import * from SOCKET import * import gl, GL, DEVICE sys.path.append('/ufs/guido/src/video') import DisplayVideoIn import LiveVideoOut import SV import getopt from IN import * from senddefs import * def usage(msg): print msg print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]', print '[-w width] [host] ...' print '-b : broadcast on local net' print '-h height : window height (default ' + `DEFHEIGHT` + ')' print '-p port : port to use (default ' + `DEFPORT` + ')' print '-t ttl : time-to-live (multicast only; default 1)' print '-s size : max packet size (default ' + `DEFPKTMAX` + ')' print '-S size : use this packet size/window size' print '-w width : window width (default ' + `DEFWIDTH` + ')'
if opt == '-p': port = string.atoi(optarg) if opt == '-m': group = gethostbyname(optarg) if opt == '-c': vtype = optarg except string.atoi_error, msg: usage('bad integer: ' + msg) s = opensocket(group, port) gl.foreground() gl.prefsize(width, height) wid = gl.winopen('Vreceive') gl.winconstraints() gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.WINQUIT) lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype) ifdlist = [gl.qgetfd(), s.fileno()] ofdlist = [] xfdlist = [] timeout = 1.0 selectargs = (ifdlist, ofdlist, xfdlist, timeout) while 1: if gl.qtest(): dev, val = gl.qread()
gl.prefposition(xoff, xoff+width-1, \ scrheight-yoff-height, scrheight-yoff-1) else: gl.prefsize(width, height) win = gl.winopen(filename) gl.clear() if quiet: vin.quiet = 1 vin.initcolormap() if bgcolor: r, g, b = bgcolor vin.clearto(r,g,b) gl.qdevice(ESCKEY) gl.qdevice(WINSHUT) gl.qdevice(WINQUIT) gl.qdevice(LEFTMOUSE) stop = 0 while not stop: gl.wintitle(filename) stop = (playonce(vin) or nowait) gl.wintitle('(done) ' + filename) if not looping: while not stop: dev, val = gl.qread() if dev == REDRAW: if bgcolor:
def getevent(): while 1: # # Get next event from the processed queue, if any # if G.queue: event = G.queue[0] del G.queue[0] #print 'getevent from queue -->', event return event # # Get next event from the draw queue, if any, # but only if there is nothing in the system queue. # if G.drawqueue and not gl.qtest(): win = G.drawqueue[0] del G.drawqueue[0] gl.winset(win._gid) gl.color(win._bg) gl.clear() event = WE_DRAW, win, win._area #print 'getevent from drawqueue -->', event return event # # Get next event from system queue, blocking if necessary # until one is available. # Some cases immediately return the event, others do nothing # or append one or more events to the processed queue. # dev, val = gl.qread() # if dev == REDRAW: win = G.windowmap[ ` val `] old_area = win._area win._fixviewport() win._needredraw() if old_area <> win._area: #print 'getevent --> WE_SIZE' return WE_SIZE, win, None elif dev == KEYBD: if val == 3: raise KeyboardInterrupt # Control-C in window character = chr(val) if commands.has_key(character): return WE_COMMAND, G.focus, commands[character] return WE_CHAR, G.focus, character elif dev == LEFTARROWKEY: if val: return WE_COMMAND, G.focus, WC_LEFT elif dev == RIGHTARROWKEY: if val: return WE_COMMAND, G.focus, WC_RIGHT elif dev == UPARROWKEY: if val: return WE_COMMAND, G.focus, WC_UP elif dev == DOWNARROWKEY: if val: return WE_COMMAND, G.focus, WC_DOWN elif dev in (LEFTALTKEY, RIGHTALTKEY): if val: for code in codelist: gl.qdevice(code) else: for code in codelist: gl.unqdevice(code) elif dev in codelist: if val: event = G.focus._doshortcut(code2key[ ` dev `]) if event: return event elif dev == LEFTMOUSE: G.mousex = gl.getvaluator(MOUSEX) G.mousey = gl.getvaluator(MOUSEY) if val: type = WE_MOUSE_DOWN gl.qdevice(MOUSEX) gl.qdevice(MOUSEY) else: type = WE_MOUSE_UP gl.unqdevice(MOUSEX) gl.unqdevice(MOUSEY) return _mouseevent(type) elif dev == MOUSEX: G.mousex = val return _mouseevent(WE_MOUSE_MOVE) elif dev == MOUSEY: G.mousey = val return _mouseevent(WE_MOUSE_MOVE) elif dev == RIGHTMOUSE: # Menu button press/release if val: # Press event = G.focus._domenu() if event: return event elif dev == INPUTCHANGE: if G.focus: G.queue.append(WE_DEACTIVATE, G.focus, None) G.focus = G.windowmap[ ` val `] if G.focus: G.queue.append(WE_ACTIVATE, G.focus, None) elif dev in (WINSHUT, WINQUIT): return WE_CLOSE, G.windowmap[ ` val `], None else: print '*** qread() --> dev:', dev, 'val:', val
import sys
#! /usr/bin/env python #! /ufs/guido/bin/sgi/python-405 # Capture a CMIF movie using the Indigo video library and board # The CMIF video file format is documented in cmif-film.ms. # Audio data is recorded in AIFF format, using the input sampling # rate, source and volume set by the audio panel, in mono, 8 # bits/sample. # Usage and help functions (keep this up-to-date if you change the program!) def usage(): print 'Usage: Vrec [options] [moviefile [audiofile]]' print print 'Options:' print '-a : record audio as well' print '-q queuesize : set the capture queue size (default 2)' print '-r rate : capture 1 out of every "rate" frames', \ '(default and min 2)' print '-w width : initial window width', \ '(default 256, use 0 for interactive placement)' print '-n : Don\'t write to file, only timing info' print '-d : drop fields if needed' print '-g bits : greyscale (2, 4 or 8 bits)' print '-G : 2-bit greyscale dithered' print '-m : monochrome dithered' print '-M value : monochrome thresholded with value' print '-f : Capture fields (in stead of frames)' print '-P frames : preallocate space for "frames" frames' print 'moviefile : here goes the movie data (default film.video)' print 'audiofile : with -a, here goes the audio data', \ '(default film.aiff)'
#! /usr/bin/env python # Play synchronous video and audio. # Highly experimental! import sys import getopt import string import os import VFile import aifc import gl, GL, DEVICE import al, AL def usage(): sys.stderr.write( \ 'usage: aplay [-o offset] [-q qsize] videofile audiofile\n') sys.exit(2) def main(): offset = 0 qsize = 0 # This defaults to 1/10 second of sound videofile = 'film.video' audiofile = 'film.aiff' try: opts, args = getopt.getopt(sys.argv[1:], 'o:q:') except getopt.error, msg: sys.stderr.write(msg + '\n') usage() try: for o, a in opts: if o == '-o': offset = string.atoi(a)
#! /usr/bin/env python # Capture a CMIF movie using the Indigo video library and board in burst mode # User interface: # # Start the application. Resize the window to the desired movie size. # Press the left mouse button to start recording, release it to end # recording. You can record as many times as you wish, but each time # you overwrite the output file(s), so only the last recording is # kept. # # Press ESC or select the window manager Quit or Close window option # to quit. If you quit before recording anything, the output file(s) # are not touched. import sys sys.path.append('/ufs/guido/src/video') import sv, SV import VFile import gl, GL, DEVICE import al, AL import time import posix import getopt import string import imageop import sgi # Usage and help functions (keep this up-to-date if you change the program!) def usage():
def getevent(): while 1: # # Get next event from the processed queue, if any # if G.queue: event = G.queue[0] del G.queue[0] # print 'getevent from queue -->', event return event # # Get next event from the draw queue, if any, # but only if there is nothing in the system queue. # if G.drawqueue and not gl.qtest(): win = G.drawqueue[0] del G.drawqueue[0] gl.winset(win._gid) gl.color(win._bg) gl.clear() event = WE_DRAW, win, win._area # print 'getevent from drawqueue -->', event return event # # Get next event from system queue, blocking if necessary # until one is available. # Some cases immediately return the event, others do nothing # or append one or more events to the processed queue. # dev, val = gl.qread() # if dev == REDRAW: win = G.windowmap[` val `] old_area = win._area win._fixviewport() win._needredraw() if old_area <> win._area: # print 'getevent --> WE_SIZE' return WE_SIZE, win, None elif dev == KEYBD: if val == 3: raise KeyboardInterrupt # Control-C in window character = chr(val) if commands.has_key(character): return WE_COMMAND, G.focus, commands[character] return WE_CHAR, G.focus, character elif dev == LEFTARROWKEY: if val: return WE_COMMAND, G.focus, WC_LEFT elif dev == RIGHTARROWKEY: if val: return WE_COMMAND, G.focus, WC_RIGHT elif dev == UPARROWKEY: if val: return WE_COMMAND, G.focus, WC_UP elif dev == DOWNARROWKEY: if val: return WE_COMMAND, G.focus, WC_DOWN elif dev in (LEFTALTKEY, RIGHTALTKEY): if val: for code in codelist: gl.qdevice(code) else: for code in codelist: gl.unqdevice(code) elif dev in codelist: if val: event = G.focus._doshortcut(code2key[` dev `]) if event: return event elif dev == LEFTMOUSE: G.mousex = gl.getvaluator(MOUSEX) G.mousey = gl.getvaluator(MOUSEY) if val: type = WE_MOUSE_DOWN gl.qdevice(MOUSEX) gl.qdevice(MOUSEY) else: type = WE_MOUSE_UP gl.unqdevice(MOUSEX) gl.unqdevice(MOUSEY) return _mouseevent(type) elif dev == MOUSEX: G.mousex = val return _mouseevent(WE_MOUSE_MOVE) elif dev == MOUSEY: G.mousey = val return _mouseevent(WE_MOUSE_MOVE) elif dev == RIGHTMOUSE: # Menu button press/release if val: # Press event = G.focus._domenu() if event: return event elif dev == INPUTCHANGE: if G.focus: G.queue.append(WE_DEACTIVATE, G.focus, None) G.focus = G.windowmap[` val `] if G.focus: G.queue.append(WE_ACTIVATE, G.focus, None) elif dev in (WINSHUT, WINQUIT): return WE_CLOSE, G.windowmap[` val `], None else: print "*** qread() --> dev:", dev, "val:", val
# Initialize GL # gl.foreground() gl.noport() dummygid = gl.winopen("") # Ask for all sorts of events # # Both REDRAW (= resize and/or redraw!) and INPUTCHANGE are implicitly queued # qdevice(REDRAW) # qdevice(INPUTCHANGE) # # Keyboard gl.qdevice(KEYBD) gl.qdevice(LEFTARROWKEY) gl.qdevice(RIGHTARROWKEY) gl.qdevice(UPARROWKEY) gl.qdevice(DOWNARROWKEY) gl.qdevice(LEFTALTKEY) gl.qdevice(RIGHTALTKEY) # # Mouse gl.qdevice(LEFTMOUSE) # gl.qdevice(MIDDLEMOUSE) gl.qdevice(RIGHTMOUSE) # Menu button # NB MOUSEX, MOUSEY events are queued on button down # # Window close requests gl.qdevice(WINQUIT)
# Implement 'jpeg' interface using SGI's compression library
c.setqueuesize(qsize) saveparams = [AL.OUTPUT_RATE, 0] al.getparams(AL.DEFAULT_DEVICE, saveparams) newparams = [AL.OUTPUT_RATE, ain.getframerate()] al.setparams(AL.DEFAULT_DEVICE, newparams) aport = al.openport(audiofile, 'w', c) print 'Opening video output window..' gl.foreground() gl.prefsize(vin.width, vin.height) wid = gl.winopen(videofile + ' + ' + audiofile) gl.clear() vin.initcolormap() print 'Playing..' gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.LEFTARROWKEY) gl.qdevice(DEVICE.RIGHTARROWKEY) ## gl.qdevice(DEVICE.UPARROWKEY) ## gl.qdevice(DEVICE.DOWNARROWKEY) gl.qdevice(DEVICE.SPACEKEY) while 1: samples_written = 0 samples_read = 0 lastt = 0 pause = 0 while 1: if gl.qtest(): dev, val = gl.qread() if val == 1:
if not hosts: hosts.append(gethostbyname(DEFMCAST)) if not LiveVideoIn.have_video: print 'Sorry, no video available (use python-405)' sys.exit(1) gl.foreground() gl.prefsize(width, height) gl.stepunit(8, 6) wid = gl.winopen('Vsend') gl.keepaspect(width, height) gl.stepunit(8, 6) gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX) gl.winconstraints() gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINFREEZE) gl.qdevice(DEVICE.WINTHAW) width, height = gl.getsize() lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype) lvi = LiveVideoIn.LiveVideoIn(pktmax, width, height, vtype) s = socket(AF_INET, SOCK_DGRAM) s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) if ttl >= 0: s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, chr(ttl))
def main(): QSIZE = 16 TIME = 5 audio = 0 opts, args = getopt.getopt(sys.argv[1:], 'aq:t:') for opt, arg in opts: if opt == '-a': audio = 1 elif opt == '-q': QSIZE = string.atoi(arg) elif opt == '-t': TIME = string.atoi(arg) if args: filename = args[0] else: filename = 'film.video' if audio: if args[1:]: audiofilename = args[1] else: audiofilename = 'film.aiff' gl.foreground() x, y = SV.PAL_XMAX / 4, SV.PAL_YMAX / 4 print x, 'x', y gl.minsize(40, 30) gl.stepunit(8, 6) gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX) gl.keepaspect(SV.PAL_XMAX, SV.PAL_YMAX) win = gl.winopen(filename) x, y = gl.getsize() print x, 'x', y v = sv.OpenVideo() v.BindGLWindow(win, SV.IN_REPLACE) v.SetSize(x, y) v.BindGLWindow(win, SV.IN_REPLACE) v.SetCaptureFormat(SV.RGB_FRAMES) v.SetCaptureMode(SV.BLOCKING_CAPTURE) v.SetQueueSize(QSIZE) v.InitCapture() if v.GetQueueSize() != QSIZE: QSIZE = v.GetQueueSize() print 'Warning: QSIZE reduced to', QSIZE gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.ESCKEY) print 'Click left mouse to start recording', TIME, 'seconds' ofile = None afile = None # Mouse down opens the file & freezes window # Mouse up starts recording frames while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE: # Start recording if val == 1: # Mouse down -- preparations if ofile == None: ofile = VFile.VoutFile().init(filename) ofile.format = 'rgb8' ofile.width = x ofile.height = y ofile.writeheader() # XXX other format bits? # The window can't be resized from now gl.prefsize(x, y) gl.winconstraints() gl.wintitle('* ' + filename) if audio: afile = initaudio(audiofilename) continue # Mouse up -- start actual recording global recording, stop_recording if audio: stop_recording = 0 recording.release() t0 = time.millitimer() v.StartCapture() while 1: t = time.millitimer() - t0 if t >= TIME*1000: break if v.GetCaptured() > 2: doframe(v, ofile, x, y, t) v.StopCapture() stop_recording = 1 while v.GetCaptured() > 0: doframe(v, ofile, x, y, t) t = time.millitimer() - t0 gl.wintitle(filename) elif dev == DEVICE.REDRAW: # Window resize (or move) x, y = gl.getsize() print x, 'x', y v.SetSize(x, y) v.BindGLWindow(win, SV.IN_REPLACE) elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT): # Quit if ofile: ofile.close() if afile: afile.destroy() posix._exit(0) # EndCapture dumps core... v.EndCapture() v.CloseVideo() gl.winclose(win)
G.font = fm.findfont(DEF_FONT).scalefont(G.size) # Initialize GL # gl.foreground() gl.noport() dummygid = gl.winopen('') # Ask for all sorts of events # # Both REDRAW (= resize and/or redraw!) and INPUTCHANGE are implicitly queued #qdevice(REDRAW) #qdevice(INPUTCHANGE) # # Keyboard gl.qdevice(KEYBD) gl.qdevice(LEFTARROWKEY) gl.qdevice(RIGHTARROWKEY) gl.qdevice(UPARROWKEY) gl.qdevice(DOWNARROWKEY) gl.qdevice(LEFTALTKEY) gl.qdevice(RIGHTALTKEY) # # Mouse gl.qdevice(LEFTMOUSE) #gl.qdevice(MIDDLEMOUSE) gl.qdevice(RIGHTMOUSE) # Menu button # NB MOUSEX, MOUSEY events are queued on button down # # Window close requests gl.qdevice(WINQUIT)
for host in args: hosts.append(gethostbyname(host)) if not hosts: hosts.append(gethostbyname(DEFMCAST)) gl.foreground() gl.prefsize(width, height) gl.stepunit(8, 6) wid = gl.winopen('Vsend') gl.keepaspect(width, height) gl.stepunit(8, 6) gl.maxsize(SV.PAL_XMAX, SV.PAL_YMAX) gl.winconstraints() gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINFREEZE) gl.qdevice(DEVICE.WINTHAW) width, height = gl.getsize() lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype) lvi = DisplayVideoIn.DisplayVideoIn(pktmax, width, height, vtype) if xpos or ypos: lvi.positionvideo(xpos, ypos) s = socket(AF_INET, SOCK_DGRAM) s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
#! /usr/bin/env python # Send live video UDP packets. # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] # [host] .. import sys import time import struct import string from socket import * from SOCKET import * import gl, GL, DEVICE sys.path.append('/ufs/guido/src/video') import LiveVideoIn import LiveVideoOut import SV import getopt from IN import * from senddefs import * def usage(msg): print msg print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]', print '[-w width] [host] ...' print '-b : broadcast on local net' print '-h height : window height (default ' + ` DEFHEIGHT ` + ')' print '-p port : port to use (default ' + ` DEFPORT ` + ')' print '-t ttl : time-to-live (multicast only; default 1)' print '-s size : max packet size (default ' + ` DEFPKTMAX ` + ')' print '-w width : window width (default ' + ` DEFWIDTH ` + ')' print '-c type : Type: rgb8, mono or grey (default rgb8)'
#! /usr/bin/env python # Send live video UDP packets. # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] # [host] .. import sys import time import struct import string from socket import * from SOCKET import * import gl, GL, DEVICE sys.path.append('/ufs/guido/src/video') import LiveVideoIn import LiveVideoOut import SV import getopt from IN import * from senddefs import * def usage(msg): print msg print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]', print '[-w width] [host] ...' print '-b : broadcast on local net' print '-h height : window height (default ' + `DEFHEIGHT` + ')' print '-p port : port to use (default ' + `DEFPORT` + ')' print '-t ttl : time-to-live (multicast only; default 1)' print '-s size : max packet size (default ' + `DEFPKTMAX` + ')' print '-w width : window width (default ' + `DEFWIDTH` + ')' print '-c type : Type: rgb8, mono or grey (default rgb8)' print '[host] ...: host(s) to send to (default multicast to ' + \
#! /usr/bin/env python # Play CMIF movie files # Help function def help(): print 'Usage: Vplay [options] [file] ...' print print 'Options:' print '-M magnify : magnify the image by the given factor' print '-d : write some debug stuff on stderr' print '-l : loop, playing the movie over and over again' print '-m delta : drop frames closer than delta seconds (default 0.)' print '-n : don\'t wait after each file' print '-q : quiet, no informative messages' print '-r delta : regenerate input time base delta seconds apart' print '-s speed : speed change factor (default 1.0)' print '-t : use a 2nd thread for read-ahead' print '-x left : window offset from left of screen' print '-y top : window offset from top of screen' print '-w width : window width' print '-h height : window height' print '-b color : background color (white,black or (r,g,b))' print 'file ... : file(s) to play; default film.video' print print 'User interface:' print 'Press the left mouse button to stop or restart the movie.' print 'Press ESC or use the window manager Close or Quit command' print 'to close the window and play the next file (if any).' # Imported modules
#! /usr/bin/env python
v.SetSize(x, y) if drop: param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF] else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if mono or grey: param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \ SV.INPUT_BYPASS, 1] else: param = param + [SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] v.BindGLWindow(win, SV.IN_REPLACE) v.SetParam(param) gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.ESCKEY) help() while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE: if val == 1: info = format, x, y, number, rate record(v, info, filename, audiofilename, \ mono, grey, \ greybits, monotreshold, fields) elif dev == DEVICE.REDRAW:
v.SetSize(x, y) if drop: param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF] else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if mono or grey: param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \ SV.INPUT_BYPASS, 1] else: param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] v.BindGLWindow(win, SV.IN_REPLACE) v.SetParam(param) gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.ESCKEY) help() while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE: if val == 1: info = format, x, y, qsize, rate record(v, info, filename, audiofilename,\ mono, grey, greybits, monotreshold, \ fields, preallocspace) elif dev == DEVICE.REDRAW:
def main(): format = SV.RGB8_FRAMES rate = 1 width = 0 drop = 0 mono = 0 grey = 0 greybits = 0 monotreshold = -1 fields = 0 number = 60 opts, args = getopt.getopt(sys.argv[1:], 'r:w:dg:mM:Gfn:') for opt, arg in opts: if opt == '-r': rate = string.atoi(arg) if rate < 2: sys.stderr.write('-r rate must be >= 2\n') sys.exit(2) elif opt == '-w': width = string.atoi(arg) elif opt == '-d': drop = 1 elif opt == '-g': grey = 1 greybits = string.atoi(arg) if not greybits in (2, 4, 8): print 'Only 2, 4 or 8 bit greyscale supported' elif opt == '-G': grey = 1 greybits = -2 elif opt == '-m': mono = 1 elif opt == '-M': mono = 1 monotreshold = string.atoi(arg) elif opt == '-f': fields = 1 elif opt == '-n': number = string.atoi(arg) if args[2:]: sys.stderr.write('usage: Vrec [options] [file]\n') sys.exit(2) if args: filename = args[0] else: filename = 'film.video' v = sv.OpenVideo() # Determine maximum window size based on signal standard param = [SV.BROADCAST, 0] v.GetParam(param) if param[1] == SV.PAL: x = SV.PAL_XMAX y = SV.PAL_YMAX elif param[1] == SV.NTSC: x = SV.NTSC_XMAX y = SV.NTSC_YMAX else: print 'Unknown video standard', param[1] sys.exit(1) gl.foreground() gl.maxsize(x, y) gl.keepaspect(x, y) gl.stepunit(8, 6) if width: gl.prefsize(width, width * 3 / 4) win = gl.winopen(filename) if width: gl.maxsize(x, y) gl.keepaspect(x, y) gl.stepunit(8, 6) gl.winconstraints() x, y = gl.getsize() print x, 'x', y v.SetSize(x, y) if drop: param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF] else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if mono or grey: param = param + [SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1] else: param = param + [SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] v.SetParam(param) v.BindGLWindow(win, SV.IN_REPLACE) gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.ESCKEY) print 'Press left mouse to start recording' while 1: dev, val = gl.qread() if dev == DEVICE.LEFTMOUSE: if val == 1: info = format, x, y, number, rate record(v, info, filename, mono, grey, \ greybits, monotreshold, fields) elif dev == DEVICE.REDRAW: # Window resize (or move) x, y = gl.getsize() print x, 'x', y v.SetSize(x, y) v.BindGLWindow(win, SV.IN_REPLACE) elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT): # Quit v.CloseVideo() gl.winclose(win) break
#! /usr/bin/env python # Send live video UDP packets. # Usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-w width] # [host] .. import sys import time import struct import string import math from socket import * from SOCKET import * import gl, GL, DEVICE sys.path.append('/ufs/guido/src/video') import DisplayVideoIn import LiveVideoOut import SV import getopt from IN import * from senddefs import * def usage(msg): print msg print 'usage: Vsend [-b] [-h height] [-p port] [-s size] [-t ttl] [-c type] [-m]', print '[-w width] [host] ...' print '-b : broadcast on local net' print '-h height : window height (default ' + ` DEFHEIGHT ` + ')' print '-p port : port to use (default ' + ` DEFPORT ` + ')' print '-t ttl : time-to-live (multicast only; default 1)' print '-s size : max packet size (default ' + ` DEFPKTMAX ` + ')' print '-S size : use this packet size/window size'