From 85f7bd5251398f4a114740a39222772025a895b7 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 25 Feb 1993 16:10:16 +0000 Subject: Vrec.py, Vrecb.py: - call v.SetParam() after v.BindGLWindow() - turn of dithering in mono/grey mode - use prefposition to place the top left corner at (150, 150) (so that the video remains visible during recording) - default width is 256 Vcopy.py: correct typos; more verbose output. OldVcopy.py: new name for Jack's old grabbing Vcopy.py. Vstat.py: print values of all video parameters. --- Demo/sgi/video/OldVcopy.py | 148 +++++++++++++++++++++++++++++++++++++++++++++ Demo/sgi/video/README | 5 ++ Demo/sgi/video/Vcopy.py | 6 +- Demo/sgi/video/Vrec.py | 14 +++-- Demo/sgi/video/Vrecb.py | 17 ++++-- Demo/sgi/video/Vstat.py | 23 +++++++ 6 files changed, 201 insertions(+), 12 deletions(-) create mode 100755 Demo/sgi/video/OldVcopy.py create mode 100755 Demo/sgi/video/Vstat.py diff --git a/Demo/sgi/video/OldVcopy.py b/Demo/sgi/video/OldVcopy.py new file mode 100755 index 0000000..63bbf71 --- /dev/null +++ b/Demo/sgi/video/OldVcopy.py @@ -0,0 +1,148 @@ +#! /ufs/guido/bin/sgi/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 treshold] [-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 treshold\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 + +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().init(ifile) + print 'open output ', ofile + ofilm = GrabbingVoutFile().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: + try: + data, cdata = ofilm.grabframe() + except VFile.Error, msg: + print msg + break + 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() + +main() diff --git a/Demo/sgi/video/README b/Demo/sgi/video/README index 01a01d2..6abe698 100644 --- a/Demo/sgi/video/README +++ b/Demo/sgi/video/README @@ -4,6 +4,11 @@ CMIF video tools This directory contains Python and C programs to manipulate files containing digitized video in the "CMIF video format". +An introduction to using the basic tools is in the file "video.doc". + +A description of the video file format is in the file "cmif-film.ms" +(troff/nroff -ms input). + History ------- diff --git a/Demo/sgi/video/Vcopy.py b/Demo/sgi/video/Vcopy.py index f9c954a..e8d4f55 100755 --- a/Demo/sgi/video/Vcopy.py +++ b/Demo/sgi/video/Vcopy.py @@ -166,6 +166,7 @@ def process(infilename, outfilename): sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n') return 1 + print '=== input file ===' vin.printinfo() vout.setinfo(vin.getinfo()) @@ -187,7 +188,6 @@ def process(infilename, outfilename): if not ypf: ypf = vout.ypf newpf = (xpf, ypf) vout.setpf(newpf) - scale = 1 if newwidth and newheight: scale = 1 @@ -221,6 +221,7 @@ def process(infilename, outfilename): newwidth = newwidth / vout.xpf newheight = newheight / vout.ypf + print '=== output file ===' vout.printinfo() vout.writeheader() @@ -251,13 +252,14 @@ def process(infilename, outfilename): inwidth, inheight, newwidth, newheight) if flip: x0, y0 = 0, 0 - x1, y1 = newwidth-1, neheight-1 + x1, y1 = newwidth-1, newheight-1 if vin.upside_down <> vout.upside_down: y1, y0 = y0, y1 if vin.mirror_image <> vout.mirror_image: x1, x0 = x0, x1 data = imageop.crop(data, vout.bpp/8, \ newwidth, newheight, x0, y0, x1, y1) + print 'Writing frame', nout vout.writeframe(tout, data, cdata) nout = nout + 1 diff --git a/Demo/sgi/video/Vrec.py b/Demo/sgi/video/Vrec.py index e90a4bd..7b95aee 100755 --- a/Demo/sgi/video/Vrec.py +++ b/Demo/sgi/video/Vrec.py @@ -20,7 +20,7 @@ def usage(): print '-r rate : capture 1 out of every "rate" frames', \ '(default and min 2)' print '-w width : initial window width', \ - '(default interactive placement)' + '(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)' @@ -184,7 +184,12 @@ def main(): gl.keepaspect(x, y) gl.stepunit(8, 6) if width: - gl.prefsize(width, width*3/4) + 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) @@ -201,12 +206,13 @@ def main(): else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if mono or grey: - param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1] + 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.SetParam(param) v.BindGLWindow(win, SV.IN_REPLACE) + v.SetParam(param) gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) diff --git a/Demo/sgi/video/Vrecb.py b/Demo/sgi/video/Vrecb.py index 43a5ddf..ef7bc37 100755 --- a/Demo/sgi/video/Vrecb.py +++ b/Demo/sgi/video/Vrecb.py @@ -1,4 +1,3 @@ -#! /ufs/guido/bin/sgi/python-405 #! /ufs/guido/bin/sgi/python # Capture a CMIF movie using the Indigo video library and board in burst mode @@ -41,7 +40,7 @@ def usage(): print '-r rate : capture 1 out of every "rate" frames', \ '(default and min 1)' print '-w width : initial window width', \ - '(default interactive placement)' + '(default 256, use 0 for interactive placement)' print '-d : drop fields if needed' print '-g bits : greyscale (2, 4 or 8 bits)' print '-G : 2-bit greyscale dithered' @@ -69,7 +68,7 @@ def main(): format = SV.RGB8_FRAMES audio = 0 rate = 1 - width = 0 + width = 256 drop = 0 mono = 0 grey = 0 @@ -167,7 +166,12 @@ def main(): gl.keepaspect(x, y) gl.stepunit(8, 6) if width: - gl.prefsize(width, width*3/4) + 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) @@ -184,12 +188,13 @@ def main(): else: param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] if mono or grey: - param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1] + 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.SetParam(param) v.BindGLWindow(win, SV.IN_REPLACE) + v.SetParam(param) gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.WINQUIT) diff --git a/Demo/sgi/video/Vstat.py b/Demo/sgi/video/Vstat.py new file mode 100755 index 0000000..cc0ecfb --- /dev/null +++ b/Demo/sgi/video/Vstat.py @@ -0,0 +1,23 @@ +#! /ufs/guido/bin/sgi/python + +# Print the value of all video parameters + +import sys +import sv, SV + +def main(): + v = sv.OpenVideo() + for name in dir(SV): + const = getattr(SV, name) + if type(const) is type(0): + sys.stdout.flush() + params = [const, 0] + try: + v.GetParam(params) + except sv.error, msg: +## print name, msg + continue + print name, params + +main() + -- cgit v0.12