def _mouseevent(type): gl.winset(G.focus._gid) orgx, orgy = gl.getorigin() sizex, sizey = gl.getsize() x = G.mousex - orgx y = G.mousey - orgy return type, G.focus, ((x, sizey - y), 1, 0, 0)
def __init__(self, wid): import gl gl.winset(wid) self.wid = wid self.width = gl.getsize()[1] self.height = 0 self.d = GLMeasurerWriter() SavingBackEnd.__init__(self)
def reshapewindow(self): oldwid = gl.winget() gl.winset(self.wid) gl.reshapeviewport() w, h = gl.getsize() self.disp.xorigin = (w-self.vw)/2 self.disp.yorigin = (h-self.vh)/2 self.disp.clear() gl.winset(oldwid)
def calcnframes(self, memsize): gl.winset(self.window) x, y = gl.getsize() pixels = x*y pixels = pixels/2 # XXX always assume fields if self.mono or self.grey: n = memsize/pixels else: n = memsize/(4*pixels) return max(1, n)
def showform(self): # Get position of video window gl.winset(self.window) x, y = gl.getorigin() width, height = gl.getsize() # Calculate position of form window x1 = x + width + 10 x2 = x1 + int(self.form.w) - 1 y2 = y + height - 1 y1 = y2 - int(self.form.h) + 1 # Position and show form window gl.prefposition(x1, x2, y1, y2) self.form.show_form(FL.PLACE_FREE, FL.TRUE, 'Vb Control')
def redraw(self): import gl gl.winset(self.wid) width = gl.getsize()[1] if width <> self.width: setdocsize = 1 self.width = width for p in self.paralist: p.top = p.bottom = None d = self.d v = 0 for p in self.paralist: v = p.render(d, 0, v, width)
def optfullsizewindow(self): if not self.window: return gl.winset(self.window) if self.use_24: x, y = self.maxx, self.maxy else: x, y = self.curx, self.cury left, bottom = gl.getorigin() width, height = gl.getsize() bottom = bottom+height-y gl.prefposition(left, left+x-1, bottom, bottom+y-1) gl.winconstraints() if not self.use_24: gl.keepaspect(x, y) gl.stepunit(8, 6) gl.maxsize(self.maxx, self.maxy) gl.winconstraints() self.bindvideo()
def bindvideo(self): if not self.video: return x, y = gl.getsize() if not self.use_24: self.curx, self.cury = x, y self.video.SetSize(x, y) drop = self.b_drop.get_button() if drop: param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF] else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if self.rgb: param = param+[SV.COLOR, SV.DEFAULT_COLOR, \ SV.DITHER, 1, \ SV.INPUT_BYPASS, 0] else: param = param+[SV.COLOR, SV.MONO, SV.DITHER, 0, \ SV.INPUT_BYPASS, 1] self.video.BindGLWindow(self.window, SV.IN_REPLACE) self.video.SetParam(param)
def burst_capture(self): self.setwatch() gl.winset(self.window) x, y = gl.getsize() if self.use_24: fl.show_message('Sorry, no 24 bit continuous capture yet', '', '') return vformat = SV.RGB8_FRAMES nframes = self.getint(self.in_nframes, 0) if nframes == 0: maxmem = self.getint(self.in_maxmem, 1.0) memsize = int(maxmem * 1024 * 1024) nframes = self.calcnframes(memsize) info = (vformat, x, y, nframes, 1) try: info2, data, bitvec = self.video.CaptureBurst(info) except sv.error, msg: self.b_capture.set_button(0) self.setarrow() fl.show_message('Capture error:', str(msg), '') return
def open_video(self): self.close_video() gl.winset(self.window) x, y = gl.getsize() if self.use_24: if self.rgb24_size == 2: x, y = x/2, y/2 elif self.rgb24_size == 3: x, y = x/4, y/4 vout = VFile.VoutFile(self.vfile) vout.setformat(self.vformat) if self.vformat == 'compress': cheader = self.init_compressor(x, y) vout.setcompressheader(cheader) vout.setsize(x, y) if self.vmode == VM_BURST: vout.setpf((1, -2)) vout.writeheader() self.vout = vout self.nframes = 0 self.speed_factor = 1 self.t_nframes.label = `self.nframes`
import sys
#! /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
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
gl.keepaspect(x, y) gl.stepunit(8, 6) if width: height = width * 3 / 4 x1 = 150 x2 = x1 + width - 1 y2 = 768 - 150 y1 = y2 - height + 1 gl.prefposition(x1, x2, y1, y2) 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 if memsize: number = calcnumber(x, y, grey or mono, memsize) print number, 'frames' 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]
if dev == REDRAW: if bgcolor: r,g,b = bgcolor vin.clearto(r,g,b) else: vin.clear() if dev == LEFTMOUSE and val == 1: break # Continue outer loop if dev == ESCKEY and val == 1 or \ dev in (WINSHUT, WINQUIT): stop = 1 # Set xoff, yoff for the next window from the current window global xoff, yoff xoff, yoff = gl.getorigin() width, height = gl.getsize() scrheight = gl.getgdesc(GL.GD_YPMAX) yoff = scrheight - yoff - height gl.winclose(win) return 0 # Play a movie once; return 1 if user wants to stop, 0 if not def playonce(vin): vin.rewind() vin.colormapinited = 1 vin.magnify = magnify if threading:
gl.keepaspect(x, y) gl.stepunit(8, 6) if width: height = width*3/4 x1 = 150 x2 = x1 + width-1 y2 = 768-150 y1 = y2-height+1 gl.prefposition(x1, x2, y1, y2) 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.DITHER, 0, \ SV.INPUT_BYPASS, 1] else: param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] v.BindGLWindow(win, SV.IN_REPLACE)
# Live video output (display video on the screen, presumably from the net)
def settitle(self): gl.winset(self.window) x, y = gl.getsize() title = 'Vb ' + self.vfile + ' (%dx%d)' % (x, y) gl.wintitle(title)
#! /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
# Text formatting abstractions
#! /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 # 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
#! /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 # 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` + ')'
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)
#! /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():
#! /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'