1 |
#!/usr/bin/env python |
#!/usr/bin/env python |
2 |
|
|
3 |
|
# $Id$ |
4 |
|
|
5 |
""" |
""" |
6 |
Make an mpeg movie from the pnm files in the current directory |
Make an mpeg movie from the pnm files in the current directory |
7 |
""" |
""" |
10 |
import getopt |
import getopt |
11 |
|
|
12 |
(opts, args) = getopt.getopt(sys.argv[1:], |
(opts, args) = getopt.getopt(sys.argv[1:], |
13 |
"s:o:f:h", |
"s:o:f:p:h", |
14 |
["framestem=", "output=", "format=", "help"], |
["framestem=", "output=", "format=", "pad=", "help"], |
15 |
) |
) |
16 |
|
|
17 |
def usage(): |
def usage(): |
18 |
print "Usage:" |
print "Usage:" |
19 |
print " make_movie -s <framestem> -o <output filename> -f <format>\n" |
print " make_movie -s <framestem> -o <output filename> -f <format> -p <pad>\n" |
20 |
print " Arguments:" |
print " Arguments:" |
21 |
print " -s/--framestem: The frame filename stem (the stuff before .pnm) (required)" |
print " -s/--framestem: The frame filename stem (the stuff before .pnm) (required)" |
22 |
print " -o/--output: Output mpeg filename (optional)" |
print " -o/--output: Output mpeg filename (optional)" |
23 |
print " -f/--format: Input frame image format (optional)" |
print " -f/--format: Input frame image format (optional)" |
24 |
|
print " -p/--pad: How many frames to pad the movie (optional)" |
25 |
|
|
26 |
mpegName = None |
mpegName = None |
27 |
fnameStem = None |
fnameStem = None |
28 |
format = "pnm" # if format not specified assume pnm |
format = "pnm" # if format not specified assume pnm |
29 |
|
pad = 1 |
30 |
|
|
31 |
for option, arg in opts: |
for option, arg in opts: |
32 |
if option in ('-s', '--stem'): |
if option in ('-s', '--stem'): |
35 |
mpegName = arg |
mpegName = arg |
36 |
elif option in ('-f', '--format'): |
elif option in ('-f', '--format'): |
37 |
format = arg |
format = arg |
38 |
|
elif option in ('-p', '--pad'): |
39 |
|
pad = int(arg) |
40 |
elif option in ('-h', '--help'): |
elif option in ('-h', '--help'): |
41 |
usage() |
usage() |
42 |
sys.exit(0) |
sys.exit(0) |
58 |
fnames.append(fname) |
fnames.append(fname) |
59 |
count += 1 |
count += 1 |
60 |
|
|
61 |
|
if count == 0: |
62 |
|
raise ValueError, "No matching files found" |
63 |
|
|
64 |
# do a conversion if necessary |
# do a conversion if necessary |
65 |
if format != "pnm": |
if format != "pnm": |
66 |
print "Converting frames to pnm" |
print "Converting frames to pnm" |
109 |
firstFile = fnames[0] |
firstFile = fnames[0] |
110 |
lastFile = fnames[-1] |
lastFile = fnames[-1] |
111 |
|
|
112 |
r = re.compile("([a-zA-Z])(\\d+)(\\.\\w+)") |
r = re.compile("([a-zA-Z-_\.\d])(\\d+)(\\.\\w+)$") |
113 |
firstNum = r.findall(firstFile) |
firstNum = r.findall(firstFile) |
114 |
firstNum = firstNum[0][1] |
firstNum = firstNum[0][1] |
115 |
lastNum = r.findall(lastFile) |
lastNum = r.findall(lastFile) |
116 |
lastNum = lastNum[0][1] |
lastNum = lastNum[0][1] |
117 |
|
|
118 |
|
|
119 |
# finish off the params file string |
# finish off the params file string |
120 |
paramsFileString += "%s*.pnm [%s-%s]\n" % (fnameStem, firstNum, lastNum) |
if pad == 1: |
121 |
|
paramsFileString += "%s*.pnm [%s-%s]\n" % (fnameStem, firstNum, lastNum) |
122 |
|
elif pad > 1: |
123 |
|
# positive padding: add duplicate frames (slow the movie down) |
124 |
|
for i in range(int(firstNum), int(lastNum)+1): |
125 |
|
for j in range(pad): |
126 |
|
paramsFileString += "%s%04d.pnm\n" % (fnameStem, i) |
127 |
|
elif pad < 1: |
128 |
|
# negative padding: i.e. remove frames (speed the movie up) |
129 |
|
for i in range(int(firstNum), int(lastNum)+1, abs(pad)): |
130 |
|
paramsFileString += "%s%04d.pnm\n" % (fnameStem, i) |
131 |
|
|
132 |
paramsFileString += """END_INPUT |
paramsFileString += """END_INPUT |
133 |
PIXEL HALF |
PIXEL HALF |