3 # Convert CMIF movie file(s) to a sequence of rgb images
9 print 'Usage: video2rgb [options] [file] ...'
12 print '-q : quiet, no informative messages'
13 print '-m : create monochrome (greyscale) image files'
14 print '-f prefix : create image files with names "prefix0000.rgb"'
15 print 'file ... : file(s) to convert; default film.video'
21 sys
.path
.append('/ufs/jack/src/av/video') # Increase chance of finding VFile
38 # Main program -- mostly command line parsing
41 global quiet
, prefix
, mono
45 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'qmf:')
46 except getopt
.error
, msg
:
47 sys
.stdout
= sys
.stderr
48 print 'Error:', msg
, '\n'
55 if opt
== '-q': quiet
= 1
56 if opt
== '-f': prefix
= arg
57 if opt
== '-m': mono
= 1
58 except string
.atoi_error
:
59 sys
.stdout
= sys
.stderr
60 print 'Option', opt
, 'requires integer argument'
64 if not args
: args
= ['film.video']
67 sts
= (process(filename
) or sts
)
69 # Exit with proper exit status
73 # Process one movie file
75 def process(filename
):
77 vin
= VFile
.VinFile(filename
)
79 sys
.stderr
.write(filename
+ ': I/O error: ' + `msg`
+ '\n')
81 except VFile
.Error
, msg
:
82 sys
.stderr
.write(msg
+ '\n')
85 sys
.stderr
.write(filename
+ ': EOF in video header\n')
91 width
, height
= int(vin
.width
), int(vin
.height
)
95 cf
= imgconv
.getconverter(vin
.format
, 'grey')
97 cf
= imgconv
.getconverter(vin
.format
, 'rgb')
99 print 'Sorry, no converter available for type',vin
.format
109 convert(vin
, cf
, width
, height
, depth
, bpp
, vin
.packfactor
)
111 def convert(vin
, cf
, width
, height
, depth
, bpp
, pf
):
114 if type(pf
) == type(()):
122 time
, data
, cdata
= vin
.getnextframe()
126 print 'Film contains chromdata!'
128 data
= cf(data
, width
/xpf
, height
/abs(ypf
))
130 data
= applypackfactor(data
, width
, height
, pf
, bpp
)
132 s
= '0'*(4-len(s
)) + s
133 fname
= prefix
+ s
+ '.rgb'
136 print 'Writing',fname
,'...'
137 imgfile
.write(fname
, data
, width
, height
, depth
)
139 def applypackfactor(image
, w
, h
, pf
, bpp
):
141 if type(pf
) == type(()):
151 image
= imageop
.crop(image
, bpp
, w1
, h1
, 0, h1
-1, w1
-1, 0)
152 return imageop
.scale(image
, bpp
, w1
, h1
, w
, h
)
154 # Don't forget to call the main program
158 except KeyboardInterrupt: