Added usage message, minor cosmetic changes

This commit is contained in:
Guido van Rossum 1992-12-24 11:39:00 +00:00
parent 42e9be4559
commit ec706ada62
1 changed files with 108 additions and 76 deletions

View File

@ -1,49 +1,50 @@
#! /ufs/guido/bin/sgi/python-405
#! /ufs/guido/bin/sgi/python #! /ufs/guido/bin/sgi/python
#! /ufs/guido/bin/sgi/python-405
# Capture a CMIF movie using the Indigo video library and board # Capture a CMIF movie using the Indigo video library and board
# The CMIF video file format is documented in cmif-film.ms.
# Usage: # Audio data is recorded in AIFF format, using the input sampling
# # rate, source and volume set by the audio panel, in mono, 8
# makemovie [-a] [-q queuesize] [-r rate] [-w width] [moviefile [audiofile]] # bits/sample.
# Options: # Usage and help functions (keep this up-to-date if you change the program!)
#
# -a : record audio as well def usage():
# -q queuesize : set the capture queue size (default 2) print 'Usage: Vrec [options] [moviefile [audiofile]]'
# -r rate : capture 1 out of every 'rate' frames (default and min 2) print
# -w width : initial window width (default interactive placement) print 'Options:'
# -n : Don't write to file, only timing info print '-a : record audio as well'
# -d : drop fields if needed print '-q queuesize : set the capture queue size (default 2)'
# -g bits : greyscale (2, 4 or 8 bits) print '-r rate : capture 1 out of every "rate" frames', \
# -G : 2-bit greyscale dithered '(default and min 2)'
# -m : monochrome dithered print '-w width : initial window width', \
# -M value : monochrome tresholded with value '(default interactive placement)'
# -f : Capture fields (in stead of frames) print '-n : Don\'t write to file, only timing info'
# -P frames : preallocate space for 'frames' frames print '-d : drop fields if needed'
# print '-g bits : greyscale (2, 4 or 8 bits)'
# moviefile : here goes the movie data (default film.video); print '-G : 2-bit greyscale dithered'
# the format is documented in cmif-film.ms print '-m : monochrome dithered'
# audiofile : with -a, here goes the audio data (default film.aiff); print '-M value : monochrome tresholded with value'
# audio data is recorded in AIFF format, using the print '-f : Capture fields (in stead of frames)'
# input sampling rate, source and volume set by the print '-P frames : preallocate space for "frames" frames'
# audio panel, in mono, 8 bits/sample print 'moviefile : here goes the movie data (default film.video)'
print 'audiofile : with -a, here goes the audio data', \
'(default film.aiff)'
def help():
print 'Press the left mouse button to start recording, release it to'
print 'end recording. You can record as many times as you wish, but'
print 'each recording overwrites the output file(s) -- only the last'
print 'recording is kept.'
print
print 'Press ESC or use the window manager Quit or Close window option'
print 'to quit. If you quit before recording anything, the output'
print 'file(s) are not touched.'
# User interface: # Imported modules
#
# Start the application. Resize the window to the desired movie size.
# Press the left mouse button to start recording, release it to end
# recording. You can record as many times as you wish, but each time
# you overwrite the output file(s), so only the last recording is
# kept.
#
# Press ESC or select the window manager Quit or Close window option
# to quit. If you quit before recording anything, the output file(s)
# are not touched.
import sys import sys
sys.path.append('/ufs/guido/src/video') sys.path.append('/ufs/guido/src/video')
@ -58,6 +59,7 @@ import string
import imageop import imageop
import sgi import sgi
# Main program # Main program
def main(): def main():
@ -75,45 +77,73 @@ def main():
fields = 0 fields = 0
preallocspace = 0 preallocspace = 0
opts, args = getopt.getopt(sys.argv[1:], 'aq:r:w:ndg:mM:GfP:') # Parse command line
for opt, arg in opts: try:
if opt == '-a': opts, args = getopt.getopt(sys.argv[1:], 'aq:r:w:ndg:mM:GfP:')
audio = 1 except getopt.error, msg:
elif opt == '-q': sys.stdout = sys.stderr
qsize = string.atoi(arg) print 'Error:', msg, '\n'
elif opt == '-r': usage()
rate = string.atoi(arg)
if rate < 2:
sys.stderr.write('-r rate must be >= 2\n')
sys.exit(2)
elif opt == '-w':
width = string.atoi(arg)
elif opt == '-n':
norecord = 1
elif opt == '-d':
drop = 1
elif opt == '-g':
grey = 1
greybits = string.atoi(arg)
if not greybits in (2,4,8):
print 'Only 2, 4 or 8 bit greyscale supported'
elif opt == '-G':
grey = 1
greybits = -2
elif opt == '-m':
mono = 1
elif opt == '-M':
mono = 1
monotreshold = string.atoi(arg)
elif opt == '-f':
fields = 1
elif opt == '-P':
preallocspace = string.atoi(arg)
if args[2:]:
sys.stderr.write('usage: Vrec [options] [file [audiofile]]\n')
sys.exit(2) sys.exit(2)
# Interpret options
try:
for opt, arg in opts:
if opt == '-a':
audio = 1
elif opt == '-q':
qsize = string.atoi(arg)
elif opt == '-r':
rate = string.atoi(arg)
if rate < 2:
sys.stderr.write( \
'-r rate must be >= 2\n')
sys.exit(2)
elif opt == '-w':
width = string.atoi(arg)
elif opt == '-n':
norecord = 1
elif opt == '-d':
drop = 1
elif opt == '-g':
grey = 1
greybits = string.atoi(arg)
if not greybits in (2, 4, 8):
sys.stderr.write( \
'Only 2, 4 or 8 bit greyscale supported\n')
sys.exit(2)
elif opt == '-G':
grey = 1
greybits = -2
elif opt == '-m':
mono = 1
elif opt == '-M':
mono = 1
monotreshold = string.atoi(arg)
elif opt == '-f':
fields = 1
elif opt == '-P':
preallocspace = string.atoi(arg)
except string.atoi_error:
sys.stdout = sys.stderr
print 'Option', opt, 'requires integer argument'
sys.exit(2)
# Check excess arguments
# If norecord is on, refuse filename arguments
if norecord:
if args:
sys.stdout = sys.stderr
print 'With -n, no filename arguments are used\n'
usage()
sys.exit(2)
elif args[2:]:
sys.stdout = sys.stderr
print 'Too many filename arguments\n'
usage()
sys.exit(2)
# Process file arguments
if args: if args:
filename = args[0] filename = args[0]
else: else:
@ -133,6 +163,8 @@ def main():
if norecord: if norecord:
filename = audiofilename = '' filename = audiofilename = ''
# Open video
v = sv.OpenVideo() v = sv.OpenVideo()
# Determine maximum window size based on signal standard # Determine maximum window size based on signal standard
param = [SV.BROADCAST, 0] param = [SV.BROADCAST, 0]
@ -181,7 +213,7 @@ def main():
gl.qdevice(DEVICE.WINSHUT) gl.qdevice(DEVICE.WINSHUT)
gl.qdevice(DEVICE.ESCKEY) gl.qdevice(DEVICE.ESCKEY)
print 'Press left mouse to start recording, release it to stop' help()
while 1: while 1:
dev, val = gl.qread() dev, val = gl.qread()