Kaydet (Commit) 85f7bd52 authored tarafından Guido van Rossum's avatar Guido van Rossum

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.
üst c97d2edd
#! /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()
...@@ -4,6 +4,11 @@ CMIF video tools ...@@ -4,6 +4,11 @@ CMIF video tools
This directory contains Python and C programs to manipulate files This directory contains Python and C programs to manipulate files
containing digitized video in the "CMIF video format". 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 History
------- -------
......
...@@ -166,6 +166,7 @@ def process(infilename, outfilename): ...@@ -166,6 +166,7 @@ def process(infilename, outfilename):
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n') sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1 return 1
print '=== input file ==='
vin.printinfo() vin.printinfo()
vout.setinfo(vin.getinfo()) vout.setinfo(vin.getinfo())
...@@ -187,7 +188,6 @@ def process(infilename, outfilename): ...@@ -187,7 +188,6 @@ def process(infilename, outfilename):
if not ypf: ypf = vout.ypf if not ypf: ypf = vout.ypf
newpf = (xpf, ypf) newpf = (xpf, ypf)
vout.setpf(newpf) vout.setpf(newpf)
scale = 1
if newwidth and newheight: if newwidth and newheight:
scale = 1 scale = 1
...@@ -221,6 +221,7 @@ def process(infilename, outfilename): ...@@ -221,6 +221,7 @@ def process(infilename, outfilename):
newwidth = newwidth / vout.xpf newwidth = newwidth / vout.xpf
newheight = newheight / vout.ypf newheight = newheight / vout.ypf
print '=== output file ==='
vout.printinfo() vout.printinfo()
vout.writeheader() vout.writeheader()
...@@ -251,13 +252,14 @@ def process(infilename, outfilename): ...@@ -251,13 +252,14 @@ def process(infilename, outfilename):
inwidth, inheight, newwidth, newheight) inwidth, inheight, newwidth, newheight)
if flip: if flip:
x0, y0 = 0, 0 x0, y0 = 0, 0
x1, y1 = newwidth-1, neheight-1 x1, y1 = newwidth-1, newheight-1
if vin.upside_down <> vout.upside_down: if vin.upside_down <> vout.upside_down:
y1, y0 = y0, y1 y1, y0 = y0, y1
if vin.mirror_image <> vout.mirror_image: if vin.mirror_image <> vout.mirror_image:
x1, x0 = x0, x1 x1, x0 = x0, x1
data = imageop.crop(data, vout.bpp/8, \ data = imageop.crop(data, vout.bpp/8, \
newwidth, newheight, x0, y0, x1, y1) newwidth, newheight, x0, y0, x1, y1)
print 'Writing frame', nout
vout.writeframe(tout, data, cdata) vout.writeframe(tout, data, cdata)
nout = nout + 1 nout = nout + 1
......
...@@ -20,7 +20,7 @@ def usage(): ...@@ -20,7 +20,7 @@ def usage():
print '-r rate : capture 1 out of every "rate" frames', \ print '-r rate : capture 1 out of every "rate" frames', \
'(default and min 2)' '(default and min 2)'
print '-w width : initial window width', \ 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 '-n : Don\'t write to file, only timing info'
print '-d : drop fields if needed' print '-d : drop fields if needed'
print '-g bits : greyscale (2, 4 or 8 bits)' print '-g bits : greyscale (2, 4 or 8 bits)'
...@@ -184,7 +184,12 @@ def main(): ...@@ -184,7 +184,12 @@ def main():
gl.keepaspect(x, y) gl.keepaspect(x, y)
gl.stepunit(8, 6) gl.stepunit(8, 6)
if width: 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) win = gl.winopen(filename)
if width: if width:
gl.maxsize(x, y) gl.maxsize(x, y)
...@@ -201,12 +206,13 @@ def main(): ...@@ -201,12 +206,13 @@ def main():
else: else:
param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
if mono or grey: 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: else:
param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
v.SetParam(param)
v.BindGLWindow(win, SV.IN_REPLACE) v.BindGLWindow(win, SV.IN_REPLACE)
v.SetParam(param)
gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.LEFTMOUSE)
gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINQUIT)
......
#! /ufs/guido/bin/sgi/python-405
#! /ufs/guido/bin/sgi/python #! /ufs/guido/bin/sgi/python
# Capture a CMIF movie using the Indigo video library and board in burst mode # Capture a CMIF movie using the Indigo video library and board in burst mode
...@@ -41,7 +40,7 @@ def usage(): ...@@ -41,7 +40,7 @@ def usage():
print '-r rate : capture 1 out of every "rate" frames', \ print '-r rate : capture 1 out of every "rate" frames', \
'(default and min 1)' '(default and min 1)'
print '-w width : initial window width', \ print '-w width : initial window width', \
'(default interactive placement)' '(default 256, use 0 for interactive placement)'
print '-d : drop fields if needed' print '-d : drop fields if needed'
print '-g bits : greyscale (2, 4 or 8 bits)' print '-g bits : greyscale (2, 4 or 8 bits)'
print '-G : 2-bit greyscale dithered' print '-G : 2-bit greyscale dithered'
...@@ -69,7 +68,7 @@ def main(): ...@@ -69,7 +68,7 @@ def main():
format = SV.RGB8_FRAMES format = SV.RGB8_FRAMES
audio = 0 audio = 0
rate = 1 rate = 1
width = 0 width = 256
drop = 0 drop = 0
mono = 0 mono = 0
grey = 0 grey = 0
...@@ -167,7 +166,12 @@ def main(): ...@@ -167,7 +166,12 @@ def main():
gl.keepaspect(x, y) gl.keepaspect(x, y)
gl.stepunit(8, 6) gl.stepunit(8, 6)
if width: 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) win = gl.winopen(filename)
if width: if width:
gl.maxsize(x, y) gl.maxsize(x, y)
...@@ -184,12 +188,13 @@ def main(): ...@@ -184,12 +188,13 @@ def main():
else: else:
param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON] param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
if mono or grey: 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: else:
param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0] param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
v.SetParam(param)
v.BindGLWindow(win, SV.IN_REPLACE) v.BindGLWindow(win, SV.IN_REPLACE)
v.SetParam(param)
gl.qdevice(DEVICE.LEFTMOUSE) gl.qdevice(DEVICE.LEFTMOUSE)
gl.qdevice(DEVICE.WINQUIT) gl.qdevice(DEVICE.WINQUIT)
......
#! /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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment