Standardize indentation to 8 chars; remove redundant "saveframe";

add -s (short listing) option; don't print space after tab;
print data size in bytes and whether it
is a color image.
This commit is contained in:
Guido van Rossum 1992-05-06 17:58:34 +00:00
parent 2c8bf9d400
commit edb3a5fcf2
1 changed files with 41 additions and 35 deletions

View File

@ -11,43 +11,43 @@ EndOfFile = 'End of file'
bye = 'bye' bye = 'bye'
def openvideo(filename): def openvideo(filename):
f = open(filename, 'r') f = open(filename, 'r')
line = f.readline() line = f.readline()
if not line: raise EndOfFile if not line: raise EndOfFile
if line[:4] == 'CMIF': line = f.readline() if line[:4] == 'CMIF': line = f.readline()
x = eval(line[:-1]) x = eval(line[:-1])
if len(x) == 3: w, h, pf = x if len(x) == 3: w, h, pf = x
else: w, h = x; pf = 2 else: w, h = x; pf = 2
return f, w, h, pf return f, w, h, pf
def loadframe(f, w, h, pf): def loadframe(f, w, h, pf):
line = f.readline() line = f.readline()
if line == '': if line == '':
raise EndOfFile raise EndOfFile
x = eval(line[:-1]) x = eval(line[:-1])
if type(x) == type(0) or type(x) == type(0.0): if type(x) == type(0) or type(x) == type(0.0):
tijd = x tijd = x
if pf == 0: if pf == 0:
size = w*h*4 size = w*h*4
else: else:
size = (w/pf) * (h/pf) size = (w/pf) * (h/pf)
else: else:
tijd, size = x tijd, size = x
f.seek(size, 1) f.seek(size, 1)
return tijd return tijd
def saveframe(name, w, h, tijd, data):
f = open(name, 'w')
f.write(`w,h` + '\n')
f.write(`tijd` + '\n')
f.write(data)
f.close()
def main(): def main():
delta = 0 delta = 0
opts, names = getopt.getopt(sys.argv[1:], 'd') short = 0
try:
opts, names = getopt.getopt(sys.argv[1:], 'ds')
except getopt.error, msg:
sys.stderr.write(msg + '\n')
sys.stderr.write('usage: vinfo [-d] [-s] [file] ...\n')
sys.exit(2)
for opt, arg in opts: for opt, arg in opts:
if opt == '-d': delta = 1 if opt == '-d': delta = 1 # print delta between frames
elif opt == '-s': short = 1 # short: don't print times
if names == []: if names == []:
names = ['film.video'] names = ['film.video']
for name in names: for name in names:
@ -56,15 +56,21 @@ def main():
except: except:
sys.stderr.write(name + ': cannot open\n') sys.stderr.write(name + ': cannot open\n')
continue continue
print name, ':', w, 'x', h, '; pf =', pf if pf == 0:
size = w*h*4
else:
size = (w/pf) * (h/pf)
print name, ':', w, 'x', h, '; pf =', pf, ', size =', size,
if pf == 0: print '(color)',
print
num = 0 num = 0
try: try:
otijd = 0 otijd = 0
while 1: while not short:
try: try:
tijd = loadframe(f, w, h, pf) tijd = loadframe(f, w, h, pf)
if delta: print '\t', tijd-otijd, if delta: print '\t' + `tijd-otijd`,
else: print '\t', tijd, else: print '\t' + `tijd`,
otijd = tijd otijd = tijd
num = num + 1 num = num + 1
if num % 8 == 0: if num % 8 == 0: