diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1993-07-23 11:59:25 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1993-07-23 11:59:25 (GMT) |
commit | 78991fd042aade1e71f8912fa395702640455c86 (patch) | |
tree | e1bcb939d611521f344816fd402b7286a5a0da7f /Demo/sgi | |
parent | f1cda9100d15023ecaf5d7ec0ea66d301a9e275a (diff) | |
download | cpython-78991fd042aade1e71f8912fa395702640455c86.zip cpython-78991fd042aade1e71f8912fa395702640455c86.tar.gz cpython-78991fd042aade1e71f8912fa395702640455c86.tar.bz2 |
VFile - Added support for creating compression lib movies
Vb, VbForm - Compression lib movie support
Save settings in ~/.Vb_init
Diffstat (limited to 'Demo/sgi')
-rwxr-xr-x | Demo/sgi/video/VFile.py | 30 | ||||
-rwxr-xr-x | Demo/sgi/video/Vb.py | 177 | ||||
-rw-r--r-- | Demo/sgi/video/VbForm.fd | 89 |
3 files changed, 242 insertions, 54 deletions
diff --git a/Demo/sgi/video/VFile.py b/Demo/sgi/video/VFile.py index 8e093b8..b375299 100755 --- a/Demo/sgi/video/VFile.py +++ b/Demo/sgi/video/VFile.py @@ -304,6 +304,12 @@ class VideoParams: self.c0bits, self.c1bits, self.c2bits, self.offset, \ self.chrompack) + def getcompressheader(self): + return self.compressheader + + def setcompressheader(self, ch): + self.compressheader = ch + # Write the relevant bits to stdout def printinfo(self): @@ -765,6 +771,24 @@ def writefileheader(fp, values): # data = (width, height, packfactor) fp.write(`data`+'\n') + +def writecompressfileheader(fp, cheader, values): + (format, width, height, packfactor, \ + c0bits, c1bits, c2bits, offset, chrompack) = values + # + # Write identifying header + # + fp.write('CMIF video 3.1\n') + # + # Write color encoding info + # + data = (format, cheader) + fp.write(`data`+'\n') + # + # Write frame geometry info + # + data = (width, height, packfactor) + fp.write(`data`+'\n') # Basic class for reading CMIF video files @@ -1058,7 +1082,11 @@ class BasicVoutFile(VideoParams): def writeheader(self): if self.frozen: raise CallError - writefileheader(self.fp, self.getinfo()) + if self.format == 'compress': + writecompressfileheader(self.fp, self.compressheader, \ + self.getinfo()) + else: + writefileheader(self.fp, self.getinfo()) self.freeze() self.atheader = 1 self.framecount = 0 diff --git a/Demo/sgi/video/Vb.py b/Demo/sgi/video/Vb.py index 57e76ae..c7e7fcc 100755 --- a/Demo/sgi/video/Vb.py +++ b/Demo/sgi/video/Vb.py @@ -31,6 +31,11 @@ import VGrabber import imageop sys.path.append('/ufs/jack/src/av/vcr') import VCR +try: + import cl + import CL +except ImportError: + cl = None ARROW = 0 WATCH = 1 @@ -46,9 +51,10 @@ def main(): StopCapture = 'StopCapture' VideoFormatLabels = ['Video off', 'rgb8', 'grey8', 'grey4', 'grey2', \ - 'grey2 dith', 'mono dith', 'mono thresh', 'rgb24', 'rgb24-jpeg'] + 'grey2 dith', 'mono dith', 'mono thresh', 'rgb24', 'rgb24-jpeg', \ + 'compress'] VideoFormats = ['', 'rgb8', 'grey', 'grey4', 'grey2', \ - 'grey2', 'mono', 'mono', 'rgb', 'jpeg'] + 'grey2', 'mono', 'mono', 'rgb', 'jpeg', 'compress'] VideoModeLabels = ['Continuous', 'Burst', 'Single frame', 'VCR sync'] [VM_CONT, VM_BURST, VM_SINGLE, VM_VCR] = range(1, 5) @@ -62,6 +68,16 @@ VcrSpeeds = [None, 5, 4, 3, 2, 1, 0] RgbSizeLabels = ['full', 'quarter', 'sixteenth'] +# init file stuff: +if os.environ.has_key('HOME'): + HOME=os.environ['HOME'] +else: + HOME='.' +VB_INIT_FILE=HOME + '/.Vb_init' + +VB_INIT_KEYS=['vfile', 'vmode', 'mono_thresh', 'vformat', 'comp_scheme', \ + 'rgb24_size', 'afile', 'aformat'] + class VideoBagOfTricks: # Init/close stuff @@ -70,14 +86,23 @@ class VideoBagOfTricks: self.window = None formdef = flp.parse_form('VbForm', 'form') flp.create_full_form(self, formdef) - self.g_cont.hide_object() - self.g_burst.hide_object() - self.g_single.hide_object() - self.g_vcr.hide_object() self.setdefaults() + if self.vmode <> VM_CONT: + self.g_cont.hide_object() + if self.vmode <> VM_BURST: + self.g_burst.hide_object() + if self.vmode <> VM_SINGLE: + self.g_single.hide_object() + if self.vmode <> VM_VCR: + self.g_vcr.hide_object() + if self.vformat <> 'compress': + self.g_compress.hide_object() + self.openvideo() self.makewindow() self.bindvideo() + if self.use_24: + self.optfullsizewindow() self.showform() fl.set_event_call_back(self.do_event) return self @@ -85,6 +110,7 @@ class VideoBagOfTricks: def close(self): self.close_video() self.close_audio() + self.savedefaults() raise SystemExit, 0 def showform(self): @@ -101,15 +127,56 @@ class VideoBagOfTricks: gl.prefposition(x1, x2, y1, y2) self.form.show_form(FL.PLACE_FREE, FL.TRUE, 'Vb Control') - def setdefaults(self): - self.vcr = None - self.vout = None - self.capturing = 0 + def getdefaultdefaults(self): # Video defaults self.vfile = 'film.video' self.vmode = VM_CONT self.mono_thresh = 128 self.vformat = 'rgb8' + self.comp_scheme = 'Uncompressed' + self.rgb24_size = 1 + # Missing: drop, rate, maxmem, nframes, rate, vcrspeed + # Audio defaults: + self.afile = 'film.aiff' + self.aformat = A_OFF + + def getdefaults(self): + self.getdefaultdefaults() + # XXXX Read defaults file and override. + try: + fp = open(VB_INIT_FILE, 'r') + except IOError: + print 'Vb: no init file' + self.initcont = {} + return + data = fp.read(1000000) + try: + self.initcont = eval(data) + except: + print 'Vb: Ill-formatted init file' + self.initcont = {} + for k in self.initcont.keys(): + if hasattr(self, k): + setattr(self, k, self.initcont[k]) + + def savedefaults(self): + newdb = {} + for k in VB_INIT_KEYS: + newdb[k] = getattr(self, k) + if newdb <> self.initcont: + try: + fp = open(VB_INIT_FILE, 'w') + except IOError: + print 'Vb: Cannot create', VB_INIT_FILE + return + fp.write(`newdb`) + fp.close() + + def setdefaults(self): + self.getdefaults() + self.vcr = None + self.vout = None + self.capturing = 0 self.c_vformat.clear_choice() for label in VideoFormatLabels: self.c_vformat.addto_choice(label) @@ -132,13 +199,21 @@ class VideoBagOfTricks: self.c_rgb24_size.clear_choice() for label in RgbSizeLabels: self.c_rgb24_size.addto_choice(label) - self.c_rgb24_size.set_choice(1) - self.rgb24_size = 1 + self.c_rgb24_size.set_choice(self.rgb24_size) + if cl: + algs = cl.QueryAlgorithms(CL.VIDEO) + self.all_comp_schemes = [] + for i in range(0, len(algs), 2): + if algs[i+1] in (CL.COMPRESSOR, CL.CODEC): + self.all_comp_schemes.append(algs[i]) + self.c_cformat.clear_choice() + for label in self.all_comp_schemes: + self.c_cformat.addto_choice(label) + i = self.all_comp_schemes.index(self.comp_scheme) + self.c_cformat.set_choice(i+1) # Audio defaults self.aout = None self.aport = None - self.afile = 'film.aiff' - self.aformat = A_OFF self.c_aformat.clear_choice() for label in AudioFormatLabels: self.c_aformat.addto_choice(label) @@ -276,6 +351,11 @@ class VideoBagOfTricks: `self.mono_thresh`, '') self.rebindvideo() + def cb_cformat(self, *args): + i = self.c_cformat.get_choice() + self.comp_scheme = self.all_comp_schemes[i-1] + + def cb_vmode(self, *args): if self.vcr: self.vcr = None @@ -493,21 +573,33 @@ class VideoBagOfTricks: data = cd.InterleaveFields(1) else: x, y = self.vout.getsize() - if self.rgb24_size == 1: - data = cd.YUVtoRGB(1) - elif self.rgb24_size == 2: - data = cd.YUVtoRGB_quarter(1) - x = x/2 - y = y/2 - elif self.rgb24_size == 3: - data = cd.YUVtoRGB_sixteenth(1) - x = x/4 - y = y/4 + if self.use_compress: + if self.rgb24_size == 1: + data = cd.YUVtoYUV422DC(0) + elif self.rgb24_size == 2: + data = cd.YUVtoYUV422DC_quarter(1) + x = x/2 + y = y/2 + elif self.rgb24_size == 3: + data = cd.YUVtoYUV422DC_sixteenth(1) + x = x/4 + y = y/4 else: - raise 'Kaboo! Kaboo!' + data = cd.YUVtoRGB(1) + if self.maxx*self.maxy*4 <> len(data): + print 'maxx,maxy,exp,got=', self.maxx, + print self.maxy,self.maxx*self.maxy*4, + print len(data) + fl.showmessage('Wrong sized data') + return 0 + if self.rgb24_size <> 1: + data = imageop.scale(data, 4, \ + self.maxx, self.maxy, x, y) if self.use_jpeg: import jpeg data = jpeg.compress(data, x, y, 4) + if self.use_compress: + data = self.compressor.Compress(1, data) cd.UnlockCaptureData() self.end_cont() if timecode == None: @@ -520,7 +612,7 @@ class VideoBagOfTricks: print 'Connecting to VCR ...' self.vcr = VCR.VCR().init() print 'Waiting for VCR to come online ...' - self.vcr.wait() + self.vcr.initvcr() print 'Preparing VCR ...' if not (self.vcr.fmmode('dnr') and \ self.vcr.dmcontrol('digital slow')): @@ -622,6 +714,10 @@ class VideoBagOfTricks: i = self.c_vformat.get_choice() label = VideoFormatLabels[i-1] format = VideoFormats[i-1] + if format == 'compress' and cl == None: + fl.show_message('Sorry, no compression library support') + format = '' + label = 'Video off' self.vformat = format if self.vformat == '': self.form.freeze_form() @@ -639,18 +735,23 @@ class VideoBagOfTricks: elif self.vmode == VM_SINGLE: self.g_single.show_object() # - self.rgb = (format[:3] == 'rgb') + self.rgb = (format[:3] == 'rgb' or format == 'compress') self.mono = (format == 'mono') self.grey = (format[:4] == 'grey') - self.use_24 = (format in ('rgb', 'jpeg')) - if self.use_24 and 0: ### quarter/sixteenth decoding not impl. + self.use_24 = (format in ('rgb', 'jpeg', 'compress')) + if self.use_24: self.g_rgb24.show_object() else: self.g_rgb24.hide_object() self.use_jpeg = (format == 'jpeg') self.mono_use_thresh = (label == 'mono thresh') + self.use_compress = (format == 'compress') + if self.use_compress: + self.g_compress.show_object() + else: + self.g_compress.hide_object() s = format[4:] - if s: + if self.grey and s: self.greybits = string.atoi(s) else: self.greybits = 8 @@ -676,6 +777,16 @@ class VideoBagOfTricks: else: self.g_audio.show_object() + def init_compressor(self, w, h): + self.compressor = None + scheme = cl.QuerySchemeFromName(CL.VIDEO, self.comp_scheme) + self.compressor = cl.OpenCompressor(scheme) + parambuf = [CL.IMAGE_WIDTH, w, \ + CL.IMAGE_HEIGHT, h, \ + CL.ORIGINAL_FORMAT, CL.YUV422DC] + self.compressor.SetParams(parambuf) + return self.compressor.Compress(0, '') + def open_if_closed(self): if not self.vout: self.open_video() @@ -691,10 +802,13 @@ class VideoBagOfTricks: if self.use_24: if self.rgb24_size == 2: x, y = x/2, y/2 - elif self.rgb24_size == 4: + elif self.rgb24_size == 3: x, y = x/4, y/4 vout = VFile.VoutFile().init(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)) @@ -743,6 +857,7 @@ class VideoBagOfTricks: msg = 'disk full??' fl.show_message('IOError', str(msg), '') self.vout = None + self.compressor = None # Watch cursor handling diff --git a/Demo/sgi/video/VbForm.fd b/Demo/sgi/video/VbForm.fd index 8c2c166..fd9759f 100644 --- a/Demo/sgi/video/VbForm.fd +++ b/Demo/sgi/video/VbForm.fd @@ -8,13 +8,13 @@ Number of forms: 1 =============== FORM =============== Name: form Width: 450.000000 -Height: 240.000000 -Number of Objects: 37 +Height: 260.000000 +Number of Objects: 40 -------------------- class: 1 type: 1 -box: 0.000000 0.000000 450.000000 240.000000 +box: 0.000000 0.000000 450.000000 260.000000 boxtype: 1 colors: 47 47 alignment: 4 @@ -29,7 +29,7 @@ argument: -------------------- class: 11 type: 5 -box: 330.000000 130.000000 110.000015 60.000004 +box: 330.000000 150.000000 110.000015 60.000004 boxtype: 1 colors: 47 47 alignment: 4 @@ -74,7 +74,7 @@ argument: 0 -------------------- class: 42 type: 0 -box: 80.000000 200.000000 120.000000 30.000000 +box: 80.000000 220.000000 120.000000 30.000000 boxtype: 5 colors: 7 0 alignment: 2 @@ -89,7 +89,7 @@ argument: 0 -------------------- class: 11 type: 0 -box: 330.000000 200.000000 110.000000 30.000000 +box: 330.000000 220.000000 110.000000 30.000000 boxtype: 1 colors: 47 47 alignment: 4 @@ -179,7 +179,7 @@ argument: -------------------- class: 42 type: 0 -box: 80.000000 160.000000 120.000000 30.000000 +box: 80.000000 180.000000 120.000000 30.000000 boxtype: 5 colors: 7 0 alignment: 2 @@ -194,7 +194,7 @@ argument: 0 -------------------- class: 11 type: 0 -box: 10.000000 110.000000 190.000000 30.000000 +box: 10.000000 90.000000 190.000000 30.000000 boxtype: 1 colors: 47 47 alignment: 4 @@ -239,7 +239,7 @@ argument: -------------------- class: 31 type: 2 -box: 220.000000 130.000000 100.000000 30.000000 +box: 220.000000 150.000000 100.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 @@ -284,7 +284,7 @@ argument: -------------------- class: 31 type: 1 -box: 220.000000 130.000000 100.000000 30.000000 +box: 220.000000 150.000000 100.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 @@ -299,7 +299,7 @@ argument: 0 -------------------- class: 31 type: 2 -box: 220.000000 70.000000 100.000000 30.000000 +box: 220.000000 90.000000 100.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 @@ -344,7 +344,7 @@ argument: -------------------- class: 31 type: 2 -box: 250.000000 130.000000 40.000000 30.000000 +box: 250.000000 150.000000 40.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 @@ -359,7 +359,7 @@ argument: 0 -------------------- class: 2 type: 0 -box: 220.000000 130.000000 30.000000 30.000000 +box: 220.000000 150.000000 30.000000 30.000000 boxtype: 0 colors: 47 47 alignment: 2 @@ -374,7 +374,7 @@ argument: -------------------- class: 2 type: 0 -box: 290.000000 130.000000 30.000000 30.000000 +box: 290.000000 150.000000 30.000000 30.000000 boxtype: 0 colors: 47 47 alignment: 2 @@ -389,7 +389,7 @@ argument: -------------------- class: 13 type: 0 -box: 220.000000 70.000000 100.000000 30.000000 +box: 220.000000 90.000000 100.000000 30.000000 boxtype: 0 colors: 7 3 alignment: 4 @@ -419,7 +419,7 @@ argument: -------------------- class: 2 type: 0 -box: 390.000000 90.000000 50.000000 30.000002 +box: 330.000000 90.000000 110.000000 30.000002 boxtype: 2 colors: 47 47 alignment: 2 @@ -434,14 +434,14 @@ argument: -------------------- class: 2 type: 0 -box: 320.000000 90.000000 60.000000 30.000000 +box: 330.000000 120.000000 110.000000 30.000000 boxtype: 0 colors: 47 47 alignment: 2 style: 0 size: 11.000000 lcol: 0 -label: Frames: +label: Frames done: name: callback: argument: @@ -464,14 +464,14 @@ argument: -------------------- class: 31 type: 2 -box: 220.000000 70.000000 100.000000 30.000000 +box: 220.000000 90.000000 100.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 style: 0 size: 11.000000 lcol: 0 -label: Nr. of frames: +label: # frames wtd: name: in_nframes_vcr callback: cb_nframes_vcr argument: 0 @@ -479,7 +479,7 @@ argument: 0 -------------------- class: 31 type: 2 -box: 220.000000 130.000000 100.000000 30.000000 +box: 220.000000 150.000000 100.000000 30.000000 boxtype: 2 colors: 13 5 alignment: 0 @@ -539,7 +539,7 @@ argument: -------------------- class: 42 type: 0 -box: 260.000000 200.000000 60.000000 30.000000 +box: 260.000000 220.000000 60.000000 30.000000 boxtype: 5 colors: 7 0 alignment: 2 @@ -566,5 +566,50 @@ name: callback: argument: +-------------------- +class: 10000 +type: 0 +box: 0.000000 0.000000 0.000000 0.000000 +boxtype: 0 +colors: 0 0 +alignment: 4 +style: 0 +size: 10.000000 +lcol: 0 +label: +name: g_compress +callback: +argument: + +-------------------- +class: 42 +type: 0 +box: 80.000000 140.000000 120.000000 30.000000 +boxtype: 5 +colors: 7 0 +alignment: 2 +style: 0 +size: 11.000000 +lcol: 0 +label: Scheme: +name: c_cformat +callback: cb_cformat +argument: 0 + +-------------------- +class: 20000 +type: 0 +box: 0.000000 0.000000 0.000000 0.000000 +boxtype: 0 +colors: 0 0 +alignment: 4 +style: 0 +size: 10.000000 +lcol: 0 +label: +name: +callback: +argument: + ============================== create_the_forms |