mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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.
This commit is contained in:
parent
c97d2eddee
commit
85f7bd5251
6 changed files with 201 additions and 12 deletions
148
Demo/sgi/video/OldVcopy.py
Executable file
148
Demo/sgi/video/OldVcopy.py
Executable file
|
@ -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()
|
|
@ -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
|
||||
-------
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
23
Demo/sgi/video/Vstat.py
Executable file
23
Demo/sgi/video/Vstat.py
Executable file
|
@ -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()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue