/[escript]/trunk/pyvisi/py_src/movie.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/movie.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1194 - (show annotations)
Thu Jun 14 05:53:49 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 5300 byte(s)
- Fixed a minor bug in the Camera module.
- Added some extra capability to the Movie module.
- The Camera module now has the capability to perform parallel projection by calling the 'parallelProjectionOn' method.
- The Camera at this stage is only capable of zooming towards the rendered object using 'dolly'. However, it appears that 'dolly' cannot be used to perform zooming out.
1 """
2 @author: John NGUI
3 """
4
5 from esys.pyvisi.constant import ImageFormat
6 from os import system
7
8 class Movie:
9 """
10 Class that creates a file called 'make_movie' by default (if a parameter
11 file name is not speficied) which contains a list of parameters required
12 by the 'ppmtompeg' command to generate a movie from a series of images.
13 """
14
15 def __init__(self, parameter_file = "make_movie"):
16 """
17 Initialise the generation of the movie.
18
19 @type parameter_file: String
20 @param parameter_file: Name of the file containing the list of
21 parameters required by the 'ppmtompeg' command.
22 """
23
24 self.__parameter_file = parameter_file
25
26 def makeMovie(self, input_directory, first_image, last_image, movie):
27 """
28 Coordinate the generation of the movie.
29
30 @type input_directory: String
31 @param input_directory: Directory in which the series of images can
32 be found
33 @type first_image: String
34 @param first_image: First image name (including the extension)
35 @type last_image: String
36 @param last_image: Last image name (including the extension)
37 @type movie : String
38 @param movie: Movie name (including the extension)
39 """
40
41 self.__input_directory = input_directory
42 self.__first_image = first_image
43 self.__last_image = last_image
44 self.__movie = movie
45
46 self.__splitInput()
47 self.__retrieveFirstImageDetails()
48 self.__retrieveLastImageDetails()
49 self.__retrieveConversionCommand()
50 self.__generateParameterFile()
51
52 # If a parameter file name was not specified, then the default file
53 # will be deleted automatically once the movie has been generated.
54 # However, if a paramter file name was specified, the file will be
55 # maintained.
56 system('ppmtompeg ' + self.__parameter_file)
57 if(self.__parameter_file == "make_movie"):
58 system('rm ' + self.__parameter_file)
59
60 def __splitInput(self):
61 """
62 Split the image label (i.e. temp-0001.jpg) to separate the
63 image name (i.e. temp-0001) and image format (i.e. jpg).
64 """
65
66 first_image_split = self.__first_image.split('.')
67 # Image format (i.e. jpg)
68 self.__image_format = first_image_split[len(first_image_split) - 1]
69 # First image name.
70 self.__first_image = \
71 self.__first_image.rstrip('.' + self.__image_format)
72
73 # Last image name.
74 self.__last_image = \
75 self.__last_image.rstrip('.' + self.__image_format)
76
77
78
79 #self.__image_format = self.__first_image.split('.')[1]
80 # First image name.
81 #self.__first_image = self.__first_image.split('.')[0]
82 # Last image name.
83 #self.__last_image = self.__last_image.split('.')[0]
84
85 def __retrieveFirstImageDetails(self):
86 """
87 Retrieve the first image name details.
88 """
89
90 # For a image called 'temp-0001.jpg', self.__first_image_number
91 # will be '0001', while self.__image_prefix will be 'temp-'.
92 self.__first_image_number = ""
93 self.__image_prefix = ""
94
95 for i in range(len(self.__first_image)):
96 if(self.__first_image[i].isdigit()): # Retrieve first image number.
97 self.__first_image_number = \
98 self.__first_image_number + self.__first_image[i]
99 else: # Retrieve image prefix.
100 self.__image_prefix = \
101 self.__image_prefix + self.__first_image[i]
102
103 def __retrieveLastImageDetails(self):
104 """
105 Retrieve the last image name details.
106 """
107
108 self.__last_image_number = ""
109
110 for i in range(len(self.__last_image)):
111 if(self.__last_image[i].isdigit()): # Retrieve last image number.
112 self.__last_image_number = \
113 self.__last_image_number + self.__last_image[i]
114
115 # The last image number is deducted by one. This allows the user
116 # to use the same image range when generating a movie as the
117 # ones used for the for-loop.
118 #self.__last_image_number = unicode(int(self.__last_image_number) - 1)
119
120 def __retrieveConversionCommand(self):
121 """
122 Retrieve the conversion command (depending on the image format)
123 required by the 'ppmtompeg' command.
124 """
125 print "-----", self.__image_format
126 if(self.__image_format.endswith(ImageFormat.JPG)):
127 self.__command = 'jpeg'
128 elif(self.__image_format.endswith(ImageFormat.BMP)):
129 self.__command = ImageFormat.BMP
130 elif(self.__image_format.endswith(ImageFormat.PNM)):
131 self.__command = ImageFormat.PNM
132 elif(self.__image_format.endswith(ImageFormat.PNG)):
133 self.__command = ImageFormat.PNG
134 elif(self.__image_format.endswith(ImageFormat.TIF)):
135 self.__command = 'tiff'
136 else:
137 raise IOError("ERROR: Invalid image format.")
138
139
140 def __generateParameterFile(self):
141 """
142 Write the list of parameters into the file.
143 """
144
145 parameter_file = open(self.__parameter_file, 'w')
146
147 parameter_file.write('PATTERN IBBPBBPBBPBBPBBP\n' +
148 'OUTPUT ' + self.__movie + '\n'
149 'BASE_FILE_FORMAT PNM\n' +
150 'INPUT_CONVERT ' + self.__command + 'topnm *\n' +
151 'GOP_SIZE 16\n' +
152 'SLICES_PER_FRAME 10\n' +
153 'INPUT_DIR ' + self.__input_directory + '\n' +
154 'INPUT\n' +
155 self.__image_prefix + '*.' + self.__image_format + ' [' + \
156 self.__first_image_number + '-' + \
157 self.__last_image_number + ']\n'
158 'END_INPUT\n' +
159 'PIXEL HALF\n' +
160 'RANGE 10\n' +
161 'PSEARCH_ALG LOGARITHMIC\n' +
162 'BSEARCH_ALG CROSS2\n' +
163 'IQSCALE 8\n' +
164 'PQSCALE 10\n' +
165 'BQSCALE 25\n' +
166 'REFERENCE_FRAME DECODED\n' +
167 'FORCE_ENCODE_LAST_FRAME\n' +
168 'ASPECT_RATIO 1\n' +
169 'FRAME_RATE 24')
170
171 parameter_file.close()
172

  ViewVC Help
Powered by ViewVC 1.1.26