def process(filename): try: fp = open(filename, 'r+') vin = VFile.RandomVinFile(fp) vin.filename = filename except IOError, msg: sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n') return 1
def process(infilename, outfilename): global newwidth, newheight, newpf try: vin = VFile.BasicVinFile(infilename) except IOError, msg: sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n') return 1
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 __init__(self, filename, title, *args): try: self.vin = VFile.VinFile(filename) except (EOFError, VFile.Error): raise IOError, 'bad video input file' self.vin.warmcache() if not title: title = os.path.split(filename)[1] self.filename = filename self.title = title self.qsize = len(self.vin.index) gl.foreground() gl.prefsize(self.vin.width, self.vin.height) self.wid = -1 self.reset()
def grab_rgb8(w, h, pf): if gl.getdisplaymode() <> GET.DMRGB: raise Error, 'Sorry, can only grab rgb8 in single-buf rgbmode' if pf <> (1, 1): raise Error, 'Sorry, can only grab rgb8 with packfactor (1,1)' if not VFile.is_entry_indigo(): raise Error, 'Sorry, can only grab rgb8 on entry level Indigo' # XXX Dirty Dirty here. # XXX Set buffer to cmap mode, grab image and set it back. gl.cmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 8) data = gl.lrectread(0, 0, w - 1, h - 1) data = data[:w * h] # BUG FIX for python lrectread gl.RGBmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 32) return data, None
def grab_rgb8(w, h, pf): if gl.getdisplaymode() <> GET.DMRGB: raise Error, 'Sorry, can only grab rgb8 in single-buf rgbmode' if pf <> (1, 1): raise Error, 'Sorry, can only grab rgb8 with packfactor (1,1)' if not VFile.is_entry_indigo(): raise Error, 'Sorry, can only grab rgb8 on entry level Indigo' # XXX Dirty Dirty here. # XXX Set buffer to cmap mode, grab image and set it back. gl.cmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 8) data = gl.lrectread(0, 0, w-1, h-1) data = data[:w*h] # BUG FIX for python lrectread gl.RGBmode() gl.gconfig() gl.pixmode(GL.PM_SIZE, 32) return data, None
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`
usage() if len(args) > 2: usage() if args: videofile = args[0] if args[1:]: audiofile = args[1] if not os.path.exists(videofile) and \ os.path.exists(videofile + '.video'): if not args[1:] and os.path.exists(videofile + '.aiff'): audiofile = videofile + '.aiff' videofile = videofile + '.video' print 'Opening video input file..' vin = VFile.VinFile(videofile) print 'Opening audio input file..' ain = aifc.open(audiofile, 'r') print 'rate :', ain.getframerate() print 'channels:', ain.getnchannels() print 'frames :', ain.getnframes() print 'width :', ain.getsampwidth() print 'kbytes :', \ ain.getnframes() * ain.getnchannels() * ain.getsampwidth() print 'Opening audio output port..' c = al.newconfig() c.setchannels(ain.getnchannels()) c.setwidth(ain.getsampwidth()) nullsample = '\0' * ain.getsampwidth()
import gl, GL
def process(filename): try: vin = VFile.RandomVinFile(filename) except IOError, msg: sys.stderr.write(filename + ': I/O error: ' + ` msg ` + '\n') return 1 except VFile.Error, msg: sys.stderr.write(msg + '\n') return 1 except EOFError: sys.stderr.write(filename + ': EOF in video file\n') return 1 if terse: print string.ljust(filename, maxwidth), kbytes = (VFile.getfilesize(filename) + 1023) / 1024 print string.rjust( ` kbytes `, 5) + 'K', print ' ', string.ljust( ` vin.version `, 5), print string.ljust(vin.format, 8), print string.rjust( ` vin.width `, 4), print string.rjust( ` vin.height `, 4), if type(vin.packfactor) == type(()): xpf, ypf = vin.packfactor s = string.rjust(`xpf`, 2) + ',' + \ string.rjust(`ypf`, 2) else: s = string.rjust( ` vin.packfactor `, 2) if type(vin.packfactor) == type(0) and \ vin.format not in ('rgb', 'jpeg') and \ (vin.width/vin.packfactor) % 4 <> 0: s = s + '! '
#! /usr/bin/env python # Print some info about a CMIF movie file # Usage: # # Vinfo [-d] [-q] [-s] [-t] [file] ... # Options: # # -d : print deltas between frames instead of frame times # -q : quick: don't read the frames # -s : don't print times (but do count frames and print the total) # -t : terse (one line/file, implies -s) # file ... : file(s) to inspect; default film.video import sys sys.path.append('/ufs/guido/src/video') import VFile import getopt import string # Global options short = 0 quick = 0 delta = 0 terse = 0 maxwidth = 10 # Main program -- mostly command line parsing def main():
def process(infilename, outfilename): try: vin = VFile.BasicVinFile(infilename) except IOError, msg: sys.stderr.write(infilename + ': I/O error: ' + ` msg ` + '\n') return 1 except VFile.Error, msg: sys.stderr.write(msg + '\n') return 1 except EOFError: sys.stderr.write(infilename + ': EOF in video file\n') return 1 try: vout = VFile.BasicVoutFile(outfilename) except IOError, msg: sys.stderr.write(outfilename + ': I/O error: ' + ` msg ` + '\n') return 1 vout.setinfo(vin.getinfo()) vout.writeheader() told = 0 nin = 0 nout = 0 tin = 0 tout = 0 while 1: try:
#! /usr/bin/env python
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)
class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber): pass def main(): foreground() try: opts, args = getopt.getopt(sys.argv[1:], 't:am:d') except getopt.error, msg: print msg usage() if len(args) <> 2: usage() [ifile, ofile] = args print 'open film ', ifile ifilm = VFile.VinFile(ifile) print 'open output ', ofile ofilm = GrabbingVoutFile(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
def rewind(self): info = self.vout.getinfo() self.vout.close() self.vout = VFile.VoutFile(self.filename) self.vout.setinfo(info) self.reset()
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 process(infilename, outfilename): try: vin = VFile.BasicVinFile(infilename) except IOError, msg: sys.stderr.write(infilename + ': I/O error: ' + ` msg ` + '\n') return 1
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)
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()
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 process(filename): try: vin = VFile.RandomVinFile(filename) except IOError, msg: sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n') return 1 except VFile.Error, msg: sys.stderr.write(msg + '\n') return 1 except EOFError: sys.stderr.write(filename + ': EOF in video file\n') return 1 if terse: print string.ljust(filename, maxwidth), kbytes = (VFile.getfilesize(filename) + 1023) / 1024 print string.rjust(`kbytes`, 5) + 'K', print ' ', string.ljust(`vin.version`, 5), print string.ljust(vin.format, 8), print string.rjust(`vin.width`, 4), print string.rjust(`vin.height`, 4), if type(vin.packfactor) == type(()): xpf, ypf = vin.packfactor s = string.rjust(`xpf`, 2) + ',' + \ string.rjust(`ypf`, 2) else: s = string.rjust(`vin.packfactor`, 2) if type(vin.packfactor) == type(0) and \ vin.format not in ('rgb', 'jpeg') and \ (vin.width/vin.packfactor) % 4 <> 0: s = s + '! '
def process(filename): try: vin = VFile.RandomVinFile(filename) except IOError, msg: sys.stderr.write(filename + ': I/O error: ' + ` msg ` + '\n') return 1
import sys
#! /usr/bin/env python # Copy a video file, interactively, frame-by-frame. import sys import getopt from gl import * from DEVICE import * import VFile import VGrabber import string import imageop def report(time, iframe): print 'Frame', iframe, ': t =', time def usage(): sys.stderr.write( 'usage: Vcopy [-t type] [-m threshold] [-a] infile outfile\n') sys.stderr.write('-t Convert to other type\n') sys.stderr.write('-a Automatic\n') sys.stderr.write('-m Convert grey to mono with threshold\n') sys.stderr.write('-d Convert grey to mono with dithering\n') sys.exit(2) def help(): print 'Command summary:' print 'n get next image from input' print 'w write current image to output' class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber): pass