Don't reference removed files in Makefile
[python/dscho.git] / Demo / sgi / video / Vfix.py
blob6b2602399c290bdbda53364809379588ce6e9b92
1 #!/ufs/guido/bin/sgi/python
3 # Copy a video file, fixing the line width to be a multiple of 4
6 # Usage:
8 # Vfix [infile [outfile]]
11 # Options:
13 # infile : input file (default film.video)
14 # outfile : output file (default out.video)
17 import sys
18 import imageop
19 sys.path.append('/ufs/guido/src/video')
20 import VFile
23 # Main program -- mostly command line parsing
25 def main():
26 args = sys.argv[1:]
27 if len(args) < 1:
28 args.append('film.video')
29 if len(args) < 2:
30 args.append('out.video')
31 if len(args) > 2:
32 sys.stderr.write('usage: Vfix [infile [outfile]]\n')
33 sys.exit(2)
34 sts = process(args[0], args[1])
35 sys.exit(sts)
38 # Copy one file to another
40 def process(infilename, outfilename):
41 try:
42 vin = VFile.BasicVinFile(infilename)
43 except IOError, msg:
44 sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
45 return 1
46 except VFile.Error, msg:
47 sys.stderr.write(msg + '\n')
48 return 1
49 except EOFError:
50 sys.stderr.write(infilename + ': EOF in video file\n')
51 return 1
53 try:
54 vout = VFile.BasicVoutFile(outfilename)
55 except IOError, msg:
56 sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
57 return 1
59 info = vin.getinfo()
60 if info[0] <> 'grey':
61 sys.stderr.write('Vfix: input not in grey format\n')
62 return 1
63 vout.setinfo(info)
64 inwidth, height = vin.getsize()
65 pf = vin.packfactor
66 if (inwidth/pf)%4 == 0:
67 sys.stderr.write('Vfix: fix not necessary\n')
68 return 1
69 outwidth = (inwidth/pf/4)*4*pf
70 print 'inwidth =', inwidth, 'outwidth =', outwidth
71 vout.setsize(outwidth, height)
72 vout.writeheader()
73 n = 0
74 try:
75 while 1:
76 t, data, cdata = vin.getnextframe()
77 n = n + 1
78 sys.stderr.write('Frame ' + `n` + '...')
79 data = imageop.crop(data, 1, inwidth/pf, height/pf, \
80 0, 0, outwidth/pf-1, height/pf-1)
81 vout.writeframe(t, data, None)
82 sys.stderr.write('\n')
83 except EOFError:
84 pass
85 return 0
88 # Don't forget to call the main program
90 main()