blob: 4870c1b9791d54bd11badf78d25337fa75a7f64c [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossum4df20fa1992-09-29 17:07:10 +00002
3# Copy a video file, fixing the line width to be a multiple of 4
4
5
6# Usage:
7#
8# Vfix [infile [outfile]]
9
10
11# Options:
12#
13# infile : input file (default film.video)
14# outfile : output file (default out.video)
15
16
17import sys
18import imageop
19sys.path.append('/ufs/guido/src/video')
20import VFile
21
22
23# Main program -- mostly command line parsing
24
25def 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)
36
37
38# Copy one file to another
39
40def process(infilename, outfilename):
41 try:
Guido van Rossum21a3ff91993-12-17 15:11:41 +000042 vin = VFile.BasicVinFile(infilename)
Guido van Rossum4df20fa1992-09-29 17:07:10 +000043 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
52
53 try:
Guido van Rossum21a3ff91993-12-17 15:11:41 +000054 vout = VFile.BasicVoutFile(outfilename)
Guido van Rossum4df20fa1992-09-29 17:07:10 +000055 except IOError, msg:
56 sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
57 return 1
58
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
86
87
88# Don't forget to call the main program
89
90main()