def __init__(self, filename, title, qsize): try: self.vout = VFile.VoutFile(filename) except (EOFError, VFile.Error): raise IOError, 'bad video output file' if not title: title = os.path.split(filename)[1] self.filename = filename self.title = title self.qsize = qsize gl.foreground() self.wid = -1 self.reset()
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`
#! /usr/bin/env python
import gl, GL
print 'Funny data length: wanted',x,'*',y,'*', number,'=',\ x*y*number,'got',len(data) gl.wintitle(filename) return # # Save # if filename and audiofilename: audiostop.append(None) audiodone.acquire_lock() if filename: # # Construct header and write it # try: vout = VFile.VoutFile(filename) except IOError, msg: print filename, ':', msg sys.exit(1) if mono: vout.format = 'mono' elif grey and greybits == 8: vout.format = 'grey' elif grey: vout.format = 'grey' + ` abs(greybits) ` else: vout.format = 'rgb8' vout.width = x vout.height = y if fields: vout.packfactor = (1, -2)
def record(v, info, filename, audiofilename, mono, grey, greybits, \ monotreshold, fields, preallocspace): import thread format, x, y, qsize, rate = info fps = 59.64 # Fields per second # XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!) tpf = 1000.0 / fps # Time per field in msec if filename: vout = VFile.VoutFile(filename) if mono: format = 'mono' elif grey and greybits == 8: format = 'grey' elif grey: format = 'grey' + ` abs(greybits) ` else: format = 'rgb8' vout.setformat(format) vout.setsize(x, y) if fields: vout.setpf((1, -2)) vout.writeheader() if preallocspace: print 'Preallocating space...' vout.prealloc(preallocspace) print 'done.' MAXSIZE = 20 # XXX should be a user option import Queue queue = Queue.Queue(MAXSIZE) done = thread.allocate_lock() done.acquire_lock() convertor = None if grey: if greybits == 2: convertor = imageop.grey2grey2 elif greybits == 4: convertor = imageop.grey2grey4 elif greybits == -2: convertor = imageop.dither2grey2 thread.start_new_thread(saveframes, \ (vout, queue, done, mono, monotreshold, convertor)) if audiofilename: audiodone = thread.allocate_lock() audiodone.acquire_lock() audiostop = [] initaudio(audiofilename, audiostop, audiodone) gl.wintitle('(rec) ' + filename) lastid = 0 t0 = time.time() count = 0 ids = [] v.InitContinuousCapture(info) while not gl.qtest(): try: cd, id = v.GetCaptureData() except sv.error: #time.sleep(0.010) # XXX is this necessary? sgi.nap(1) # XXX Try by Jack continue ids.append(id) id = id + 2 * rate ## if id <> lastid + 2*rate: ## print lastid, id lastid = id count = count + 1 if fields: data1, data2 = cd.GetFields() cd.UnlockCaptureData() if filename: queue.put((data1, int(id * tpf))) queue.put((data2, int((id + 1) * tpf))) else: data = cd.InterleaveFields(1) cd.UnlockCaptureData() if filename: queue.put((data, int(id * tpf))) t1 = time.time() gl.wintitle('(busy) ' + filename) print lastid, 'fields in', round(t1 - t0, 3), 'sec', print '--', round(lastid / (t1 - t0), 1), 'fields/sec' print 'Captured', count * 2, 'fields,', print round(count * 2 / (t1 - t0), 1), 'f/s', if lastid: print '(', print round(count * 200.0 / lastid), '%, or', print round(count * rate * 200.0 / lastid), '% of wanted rate )', print if ids: print 'Ids:', t0 = ids[0] del ids[0] for t1 in ids: print t1 - t0, t0 = t1 print if filename and audiofilename: audiostop.append(None) audiodone.acquire_lock() v.EndContinuousCapture() if filename: queue.put(None) # Sentinel done.acquire_lock() gl.wintitle('(done) ' + filename)
gl.wintitle(filename) return # print bitvec if x * y * number <> len(data): print 'Funny data length: wanted',x,'*',y,'*', number,'=',\ x*y*number,'got',len(data) gl.wintitle(filename) return # # Save # if filename: # # Construct header and write it # vout = VFile.VoutFile().init(filename) if mono: vout.format = 'mono' elif grey and greybits == 8: vout.format = 'grey' elif grey: vout.format = 'grey' + ` abs(greybits) ` else: vout.format = 'rgb8' vout.width = x vout.height = y if fields: vout.packfactor = (1, -2) else: print 'Sorry, can only save fields at the moment' gl.wintitle(filename)
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)
import sys
def main(): foreground() opts, args = getopt.getopt(sys.argv[1:], 't:am:d') if len(args) <> 2: usage() [ifile, ofile] = args print 'open film ', ifile ifilm = VFile.VinFile().init(ifile) print 'open output ', ofile ofilm = VFile.VoutFile().init(ofile) ofilm.setinfo(ifilm.getinfo()) use_grabber = 0 continuous = 0 tomono = 0 tomonodither = 0 for o, a in opts: if o == '-t': ofilm.format = a use_grabber = 1 if o == '-a': continuous = 1 if o == '-m': if ifilm.format <> 'grey': print '-m only supported for greyscale' sys.exit(1) tomono = 1 treshold = string.atoi(a) ofilm.format = 'mono' if o == '-d': if ifilm.format <> 'grey': print '-m only supported for greyscale' sys.exit(1) tomonodither = 1 ofilm.format = 'mono' ofilm.writeheader() # prefsize(ifilm.width, ifilm.height) w = winopen(ifile) qdevice(KEYBD) qdevice(ESCKEY) qdevice(WINQUIT) qdevice(WINSHUT) print 'qdevice calls done' # help() # time, data, cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = 1 report(time, iframe) # while 1: if continuous: dev = KEYBD else: dev, val = qread() if dev in (ESCKEY, WINQUIT, WINSHUT): break if dev == REDRAW: reshapeviewport() elif dev == KEYBD: if continuous: c = '0' else: c = chr(val) #XXX Debug if c == 'R': c3i(255, 0, 0) clear() if c == 'G': c3i(0, 255, 0) clear() if c == 'B': c3i(0, 0, 255) clear() if c == 'w' or continuous: if use_grabber: data, cdata = ofilm.grabframe() if tomono: data = imageop.grey2mono(data, \ ifilm.width, ifilm.height, \ treshold) if tomonodither: data = imageop.dither2mono(data, \ ifilm.width, ifilm.height) ofilm.writeframe(time, data, cdata) print 'Frame', iframe, 'written.' if c == 'n' or continuous: try: time, data, cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = iframe + 1 report(time, iframe) except EOFError: print 'EOF' if continuous: break ringbell() elif dev == INPUTCHANGE: pass else: print '(dev, val) =', (dev, val) ofilm.close()
def rewind(self): info = self.vout.getinfo() self.vout.close() self.vout = VFile.VoutFile(self.filename) self.vout.setinfo(info) self.reset()
#! /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