ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mpeg_encode/src/param.c
Revision: 22
Committed: Mon Jul 7 22:16:37 2008 UTC (11 years, 5 months ago) by wdelano
File size: 41145 byte(s)
Log Message:
initial checkin of mpeg_encode source
Line File contents
1 /*===========================================================================*
2 * param.c *
3 * *
4 * Procedures to read in parameter file *
5 * *
6 * EXPORTED PROCEDURES: *
7 * ReadParamFile *
8 * GetNthInputFileName *
9 * *
10 *===========================================================================*/
11
12 /*
13 * Copyright (c) 1995 The Regents of the University of California.
14 * All rights reserved.
15 *
16 * Permission to use, copy, modify, and distribute this software and its
17 * documentation for any purpose, without fee, and without written agreement is
18 * hereby granted, provided that the above copyright notice and the following
19 * two paragraphs appear in all copies of this software.
20 *
21 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
22 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
23 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
24 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
29 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
30 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
31 */
32
33 /*
34 * $Header: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/param.c,v 1.38 1995/08/14 22:29:13 smoot Exp smoot $
35 * $Log: param.c,v $
36 * Revision 1.38 1995/08/14 22:29:13 smoot
37 * cleaned up subcommand for file name generation
38 * fixed bug where foo* didnt work as input string
39 *
40 * Revision 1.37 1995/08/07 21:47:01 smoot
41 * allows spaces after lines in param files
42 * added SIZE == YUV_SIZE for parallel encoding (otherwise you'd have
43 * to parse PPM files in the master server... Ick.
44 * So we have it specified)
45 *
46 * Revision 1.36 1995/06/26 21:52:52 smoot
47 * allow uppercase stdin
48 *
49 * Revision 1.35 1995/06/21 18:35:01 smoot
50 * moved TUNE stuff to opts.c
51 * Added ability to do:
52 * INPUT
53 * file.ppm [1-10]
54 * to do 10 copies
55 * added CDL = SPECIFICS
56 *
57 * Revision 1.34 1995/05/02 01:48:25 eyhung
58 * deleted some smootisms. fixed framerate settings, added check for
59 * invalid input range
60 *
61 * Revision 1.33 1995/05/02 01:20:10 smoot
62 * *** empty log message ***
63 *
64 * Revision 1.31 1995/03/09 06:22:36 eyhung
65 * more robust input checking (whitespace at end of input file spec)
66 *
67 * Revision 1.30 1995/02/02 01:06:18 eyhung
68 * Added error checking for JMOVIE and stdin ; deleted smoot's "understand"
69 * param file ideas.
70 *
71 * Revision 1.29 1995/02/01 21:09:59 eyhung
72 * Finished infinite coding-on-the-fly
73 *
74 * Revision 1.28 1995/01/31 22:34:28 eyhung
75 * Added stdin as a parameter to INPUT_DIR for interactive encoding
76 *
77 * Revision 1.27 1995/01/27 21:58:07 eyhung
78 * Fixed a bug with reading JMOVIES in GetNthInputFileName
79 *
80 * Revision 1.26 1995/01/25 23:00:05 smoot
81 * Checks out Qtable entries
82 *
83 * Revision 1.25 1995/01/23 02:09:51 darryl
84 * removed "PICT_RATE" code
85 *
86 * Revision 1.24 1995/01/20 00:07:46 smoot
87 * requires unistd.c now
88 *
89 * Revision 1.23 1995/01/20 00:05:33 smoot
90 * Added gamma correction option
91 *
92 * Revision 1.22 1995/01/19 23:55:55 eyhung
93 * Fixed up smoot's "style" and made YUV_FORMAT default to EYUV
94 *
95 * Revision 1.21 1995/01/19 23:09:03 eyhung
96 * Changed copyrights
97 *
98 * Revision 1.20 1995/01/17 22:04:14 smoot
99 * Added `commands` to file name listing
100 *
101 * Revision 1.19 1995/01/17 06:28:01 eyhung
102 * StdinUsed added.
103 *
104 * Revision 1.18 1995/01/16 09:33:35 eyhung
105 * Fixed stupid commenting error.
106 *
107 * Revision 1.17 1995/01/16 06:07:53 eyhung
108 * Made it look a little nicer
109 *
110 * Revision 1.16 1995/01/13 23:57:25 smoot
111 * added Y format
112 *
113 * Revision 1.15 1995/01/08 06:20:39 eyhung
114 * *** empty log message ***
115 *
116 * Revision 1.14 1995/01/08 06:15:57 eyhung
117 * *** empty log message ***
118 *
119 * Revision 1.13 1995/01/08 05:50:32 eyhung
120 * Added YUV Format parameter
121 *
122 * Revision 1.12 1994/12/16 00:55:30 smoot
123 * Fixed INPU_FILES bug
124 *
125 * Revision 1.11 1994/12/12 23:54:36 smoot
126 * Fixed GOP-missing error message (GOP to GOP_SIZE)
127 *
128 * Revision 1.10 1994/12/07 00:40:36 smoot
129 * Added seperate P and B search ranges
130 *
131 * Revision 1.9 1994/11/18 23:19:22 smoot
132 * Added USER_DATA parameter
133 *
134 * Revision 1.8 1994/11/16 22:33:40 smoot
135 * Put in ifdef for rsh in param.c
136 *
137 * Revision 1.7 1994/11/16 22:25:05 smoot
138 * Corrected ASPECT_RATIO bug
139 *
140 * Revision 1.6 1994/11/14 22:39:26 smoot
141 * merged specifics and rate control
142 *
143 * Revision 1.5 1994/11/01 05:01:41 darryl
144 * with rate control changes added
145 *
146 * Revision 1.1 1994/09/27 00:16:28 darryl
147 * Initial revision
148 *
149 * Revision 1.4 1994/03/15 00:27:11 keving
150 * nothing
151 *
152 * Revision 1.3 1993/12/22 19:19:01 keving
153 * nothing
154 *
155 * Revision 1.2 1993/07/22 22:23:43 keving
156 * nothing
157 *
158 * Revision 1.1 1993/06/30 20:06:09 keving
159 * nothing
160 *
161 */
162
163
164 /*==============*
165 * HEADER FILES *
166 *==============*/
167
168 #include "all.h"
169 #include "mtypes.h"
170 #include "mpeg.h"
171 #include "search.h"
172 #include "prototypes.h"
173 #include "parallel.h"
174 #include "param.h"
175 #include "readframe.h"
176 #include "fsize.h"
177 #include "frames.h"
178 #include "jpeg.h"
179 #include <string.h>
180 #include <ctype.h>
181 #include "rate.h"
182 #include "opts.h"
183
184 /*===========*
185 * CONSTANTS *
186 *===========*/
187
188 #define INPUT_ENTRY_BLOCK_SIZE 128
189
190 #define FIRST_OPTION 0
191 #define OPTION_GOP 0
192 #define OPTION_PATTERN 1
193 #define OPTION_PIXEL 2
194 #define OPTION_PQSCALE 3
195 #define OPTION_OUTPUT 4
196 #define OPTION_RANGE 5
197 #define OPTION_PSEARCH_ALG 6
198 #define OPTION_IQSCALE 7
199 #define OPTION_INPUT_DIR 8
200 #define OPTION_INPUT_CONVERT 9
201 #define OPTION_INPUT 10
202 #define OPTION_BQSCALE 11
203 #define OPTION_BASE_FORMAT 12
204 #define OPTION_SPF 13
205 #define OPTION_BSEARCH_ALG 14
206 #define OPTION_REF_FRAME 15
207 #define LAST_OPTION 15
208
209 /* put any non-required options after LAST_OPTION */
210 #define OPTION_RESIZE 16
211 #define OPTION_IO_CONVERT 17
212 #define OPTION_SLAVE_CONVERT 18
213 #define OPTION_IQTABLE 19
214 #define OPTION_NIQTABLE 20
215 #define OPTION_FRAME_RATE 21
216 #define OPTION_ASPECT_RATIO 22
217 #define OPTION_YUV_SIZE 23
218 #define OPTION_SPECIFICS 24
219 #define OPTION_DEFS_SPECIFICS 25
220 #define OPTION_BUFFER_SIZE 26
221 #define OPTION_BIT_RATE 27
222 #define OPTION_USER_DATA 28
223 #define OPTION_YUV_FORMAT 29
224 #define OPTION_GAMMA 30
225 #define OPTION_PARALLEL 31
226
227 #define NUM_OPTIONS 31
228
229 /*=======================*
230 * STRUCTURE DEFINITIONS *
231 *=======================*/
232
233 typedef struct InputFileEntryStruct {
234 char left[256];
235 char right[256];
236 boolean glob; /* if FALSE, left is complete name */
237 int startID;
238 int endID;
239 int skip;
240 int numPadding; /* -1 if there is none */
241 int numFiles;
242 boolean repeat;
243 } InputFileEntry;
244
245
246 /*==================*
247 * STATIC VARIABLES *
248 *==================*/
249
250 static InputFileEntry **inputFileEntries;
251 static int numInputFileEntries = 0;
252 static int maxInputFileEntries;
253
254
255 /*==================*
256 * GLOBAL VARIABLES *
257 *==================*/
258
259 extern char currentPath[MAXPATHLEN];
260 extern char currentGOPPath[MAXPATHLEN];
261 extern char currentFramePath[MAXPATHLEN];
262 char outputFileName[256];
263 int outputWidth, outputHeight;
264 int numInputFiles = 0;
265 char inputConversion[1024];
266 char ioConversion[1024];
267 char slaveConversion[1024];
268 char yuvConversion[256];
269 char specificsFile[256],specificsDefines[1024]="";
270 boolean GammaCorrection=FALSE;
271 float GammaValue;
272 unsigned char userDataFileName[256]={0};
273 boolean specificsOn = FALSE;
274 boolean optionSeen[NUM_OPTIONS+1];
275 int numMachines;
276 char machineName[MAX_MACHINES][256];
277 char userName[MAX_MACHINES][256];
278 char executable[MAX_MACHINES][1024];
279 char remoteParamFile[MAX_MACHINES][1024];
280 boolean remote[MAX_MACHINES];
281 boolean stdinUsed = FALSE;
282 int mult_seq_headers = 0; /* 0 for none, N for header/N GOPs */
283
284 /*===============================*
285 * INTERNAL PROCEDURE prototypes *
286 *===============================*/
287 static void ReadInputFileNames _ANSI_ARGS_((FILE *fpointer,
288 char *endInput));
289 static void ReadMachineNames _ANSI_ARGS_((FILE *fpointer));
290 static int GetAspectRatio _ANSI_ARGS_((char *p));
291 static int GetFrameRate _ANSI_ARGS_((char *p));
292
293 /*=====================*
294 * EXPORTED PROCEDURES *
295 *=====================*/
296
297
298 /*===========================================================================*
299 *
300 * ReadParamFile
301 *
302 * read the parameter file
303 * function is ENCODE_FRAMES, COMBINE_GOPS, or COMBINE_FRAMES, and
304 * will slightly modify the procedure's behavior as to what it
305 * is looking for in the parameter file
306 *
307 * RETURNS: TRUE if the parameter file was read correctly; FALSE if not
308 *
309 * SIDE EFFECTS: sets parameters accordingly, as well as machine info for
310 * parallel execution and input file names
311 *
312 *===========================================================================*/
313 boolean
314 ReadParamFile(fileName, function)
315 char *fileName;
316 int function;
317 {
318 FILE *fpointer;
319 char input[256];
320 char *charPtr;
321 boolean yuvUsed = FALSE;
322 static char *optionText[LAST_OPTION+1] = { "GOP_SIZE", "PATTERN", "PIXEL", "PQSCALE",
323 "OUTPUT", "RANGE", "PSEARCH_ALG", "IQSCALE", "INPUT_DIR",
324 "INPUT_CONVERT", "INPUT", "BQSCALE", "BASE_FILE_FORMAT",
325 "SLICES_PER_FRAME", "BSEARCH_ALG", "REFERENCE_FRAME"};
326 register int index;
327 register int row, col;
328
329 if ( (fpointer = fopen(fileName, "r")) == NULL ) {
330 fprintf(stderr, "Error: Cannot open parameter file: %s\n", fileName);
331 return FALSE;
332 }
333
334 /* should set defaults */
335 numInputFiles = 0;
336 numMachines = 0;
337 sprintf(currentPath, ".");
338 sprintf(currentGOPPath, ".");
339 sprintf(currentFramePath, ".");
340 #ifndef HPUX
341 SetRemoteShell("rsh");
342 #else
343 SetRemoteShell("remsh");
344 #endif
345
346 switch(function) {
347 case ENCODE_FRAMES:
348 for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
349 optionSeen[index] = FALSE;
350 }
351 optionSeen[OPTION_IO_CONVERT] = FALSE;
352 optionSeen[OPTION_SLAVE_CONVERT] = FALSE;
353 break;
354 case COMBINE_GOPS:
355 for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
356 optionSeen[index] = TRUE;
357 }
358
359 optionSeen[OPTION_OUTPUT] = FALSE;
360 break;
361 case COMBINE_FRAMES:
362 for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
363 optionSeen[index] = TRUE;
364 }
365
366 optionSeen[OPTION_GOP] = FALSE;
367 optionSeen[OPTION_OUTPUT] = FALSE;
368 break;
369 }
370
371 for( index=LAST_OPTION+1; index<= NUM_OPTIONS; index++ ) {
372 optionSeen[index]=FALSE;
373 }
374
375 while ( fgets(input, 256, fpointer) != NULL ) {
376 /* skip comments */
377 if ( input[0] == '#' ) {
378 continue;
379 }
380
381 {
382 int len = strlen(input);
383 if (input[len-1] == '\n') {
384 len--;
385 input[len] = '\0'; /* get rid of newline */
386 /* Junk whitespace */
387 while ((len >= 0) && ((input[len-1] == ' ') || (input[len-1] == '\t'))) {
388 input[--len] = '\0';
389 }
390 }
391 }
392
393 if (strlen(SkipSpacesTabs(input)) == 0) continue;
394
395 switch(input[0]) {
396 case 'A':
397 if ( strncmp(input, "ASPECT_RATIO", 12) == 0 ) {
398 charPtr = SkipSpacesTabs(&input[12]);
399 aspectRatio = GetAspectRatio(charPtr);
400 optionSeen[OPTION_ASPECT_RATIO] = TRUE;
401 }
402 break;
403
404 case 'B':
405 if ( strncmp(input, "BQSCALE", 7) == 0 ) {
406 charPtr = SkipSpacesTabs(&input[7]);
407 SetBQScale(atoi(charPtr));
408 optionSeen[OPTION_BQSCALE] = TRUE;
409 } else if ( strncmp(input, "BASE_FILE_FORMAT", 16) == 0 ) {
410 charPtr = SkipSpacesTabs(&input[16]);
411 SetFileFormat(charPtr);
412 if ( (strncmp(charPtr,"YUV",3) == 0) ||
413 (strcmp(charPtr,"Y") == 0) ) {
414 yuvUsed = TRUE;
415 }
416 optionSeen[OPTION_BASE_FORMAT] = TRUE;
417 } else if ( strncmp(input, "BSEARCH_ALG", 11) == 0 ) {
418 charPtr = SkipSpacesTabs(&input[11]);
419 SetBSearchAlg(charPtr);
420 optionSeen[OPTION_BSEARCH_ALG] = TRUE;
421 } else if ( strncmp(input, "BIT_RATE", 8) == 0 ) {
422 charPtr = SkipSpacesTabs(&input[8]);
423 setBitRate(charPtr);
424 optionSeen[OPTION_BIT_RATE] = TRUE;
425 } else if ( strncmp(input, "BUFFER_SIZE", 11) == 0 ) {
426 charPtr = SkipSpacesTabs(&input[11]);
427 setBufferSize(charPtr);
428 optionSeen[OPTION_BUFFER_SIZE] = TRUE;
429 }
430 break;
431
432 case 'C':
433 if ( strncmp(input, "CDL_FILE", 8) == 0 ) {
434 charPtr = SkipSpacesTabs(&input[8]);
435 strcpy(specificsFile, charPtr);
436 specificsOn=TRUE;
437 optionSeen[OPTION_SPECIFICS] = TRUE;
438 } else if ( strncmp(input, "CDL_DEFINES", 11) == 0 ) {
439 charPtr = SkipSpacesTabs(&input[11]);
440 strcpy(specificsDefines, charPtr);
441 optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
442 }
443 break;
444
445 case 'F':
446 if ( strncmp(input, "FRAME_INPUT_DIR", 15) == 0 ) {
447 charPtr = SkipSpacesTabs(&input[15]);
448 if ( strncmp(charPtr, "stdin", 5) == 0 ||
449 strncmp(charPtr, "STDIN", 5) == 0 ) {
450 stdinUsed = TRUE;
451 numInputFiles = MAXINT;
452 numInputFileEntries = 1;
453 }
454 strcpy(currentFramePath, charPtr);
455 } else if ( strncmp(input, "FRAME_INPUT", 11) == 0 ) {
456 if ( function == COMBINE_FRAMES ) {
457 ReadInputFileNames(fpointer, "FRAME_END_INPUT");
458 }
459 } else if ( strncmp(input, "FORCE_I_ALIGN", 13) == 0 ) {
460 forceIalign = TRUE;
461 } else if ( strncmp(input, "FORCE_ENCODE_LAST_FRAME", 23) == 0 ) {
462 forceEncodeLast = TRUE;
463 } else if ( strncmp(input, "FRAME_RATE", 10) == 0 ) {
464 charPtr = SkipSpacesTabs(&input[10]);
465 frameRate = GetFrameRate(charPtr);
466 frameRateRounded = (int) VidRateNum[frameRate];
467 if ( (frameRate % 3) == 1) {
468 frameRateInteger = FALSE;
469 }
470 optionSeen[OPTION_FRAME_RATE] = TRUE;
471 }
472 break;
473
474 case 'G':
475 if ( strncmp(input, "GOP_SIZE", 8) == 0 ) {
476 charPtr = SkipSpacesTabs(&input[8]);
477 SetGOPSize(atoi(charPtr));
478 optionSeen[OPTION_GOP] = TRUE;
479 } else if ( strncmp(input, "GOP_INPUT_DIR", 13) == 0 ) {
480 charPtr = SkipSpacesTabs(&input[13]);
481 if ( strncmp(charPtr, "stdin", 5) == 0 ||
482 strncmp(charPtr, "STDIN", 5) == 0 ) {
483 stdinUsed = TRUE;
484 numInputFiles = MAXINT;
485 numInputFileEntries = 1;
486 }
487 strcpy(currentGOPPath, charPtr);
488 } else if ( strncmp(input, "GOP_INPUT", 9) == 0 ) {
489 if ( function == COMBINE_GOPS ) {
490 ReadInputFileNames(fpointer, "GOP_END_INPUT");
491 }
492 } else if ( strncmp(input, "GAMMA", 5) == 0) {
493 charPtr = SkipSpacesTabs(&input[5]);
494 GammaCorrection = TRUE;
495 sscanf(charPtr,"%f",&GammaValue);
496 optionSeen[OPTION_GAMMA] = TRUE;
497 }
498 break;
499
500 case 'I':
501 if ( strncmp(input, "IQSCALE", 7) == 0 ) {
502 charPtr = SkipSpacesTabs(&input[7]);
503 SetIQScale(atoi(charPtr));
504 optionSeen[OPTION_IQSCALE] = TRUE;
505 } else if ( strncmp(input, "INPUT_DIR", 9) == 0 ) {
506 charPtr = SkipSpacesTabs(&input[9]);
507 if ( strncmp(charPtr, "stdin", 5) == 0 ||
508 strncmp(charPtr, "STDIN", 5) == 0 ) {
509 stdinUsed = TRUE;
510 numInputFiles = MAXINT;
511 numInputFileEntries = 1;
512 }
513 strcpy(currentPath, charPtr);
514 optionSeen[OPTION_INPUT_DIR] = TRUE;
515 } else if ( strncmp(input, "INPUT_CONVERT", 13) == 0 ) {
516 charPtr = SkipSpacesTabs(&input[13]);
517 strcpy(inputConversion, charPtr);
518 optionSeen[OPTION_INPUT_CONVERT] = TRUE;
519 } else if ( strcmp(input, "INPUT") == 0 ) { /* yes, strcmp */
520 if ( function == ENCODE_FRAMES ) {
521 ReadInputFileNames(fpointer, "END_INPUT");
522 optionSeen[OPTION_INPUT] = TRUE;
523 }
524 } else if ( strncmp(input, "IO_SERVER_CONVERT", 17) == 0 ) {
525 charPtr = SkipSpacesTabs(&input[17]);
526 strcpy(ioConversion, charPtr);
527 optionSeen[OPTION_IO_CONVERT] = TRUE;
528 } else if ( strncmp(input, "IQTABLE", 7) == 0 ) {
529 for ( row = 0; row < 8; row ++ ) {
530 fgets(input, 256, fpointer);
531 charPtr = input;
532 if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
533 &qtable[row*8+0], &qtable[row*8+1],
534 &qtable[row*8+2], &qtable[row*8+3],
535 &qtable[row*8+4], &qtable[row*8+5],
536 &qtable[row*8+6], &qtable[row*8+7])) {
537 fprintf(stderr, "Line %d of IQTABLE doesn't have 8 elements!\n", row);
538 exit(1);
539 }
540 for ( col = 0; col < 8; col ++ ) {
541 if ((qtable[row*8+col]<1) || (qtable[row*8+col]>255)) {
542 fprintf(stderr,
543 "Warning: IQTable Element %1d,%1d (%d) corrected to 1-255.\n",
544 row+1, col+1, qtable[row*8+col]);
545 qtable[row*8+col] = (qtable[row*8+col]<1)?1:255;
546 }}
547 }
548
549 if ( qtable[0] != 8 ) {
550 fprintf(stderr, "Warning: IQTable Element 1,1 reset to 8, since it must be 8.\n");
551 qtable[0] = 8;
552 }
553 customQtable = qtable;
554 optionSeen[OPTION_IQTABLE] = TRUE;
555 } else if ( strncmp(input, "INPUT", 5) == 0 ) { /* handle spaces after input */
556 log(10.0);
557 charPtr = SkipSpacesTabs(&input[5]);
558 if ( function == ENCODE_FRAMES && *charPtr==0) {
559 ReadInputFileNames(fpointer, "END_INPUT");
560 optionSeen[OPTION_INPUT] = TRUE;
561 }
562 }
563 break;
564
565 case 'N':
566 if ( strncmp(input, "NIQTABLE", 8) == 0 ) {
567 for ( row = 0; row < 8; row ++ ) {
568 fgets(input, 256, fpointer);
569 charPtr = input;
570 if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
571 &niqtable[row*8+0], &niqtable[row*8+1],
572 &niqtable[row*8+2], &niqtable[row*8+3],
573 &niqtable[row*8+4], &niqtable[row*8+5],
574 &niqtable[row*8+6], &niqtable[row*8+7])) {
575 fprintf(stderr, "Line %d of NIQTABLE doesn't have 8 elements!\n", row);
576 exit(1);
577 }
578 for ( col = 0; col < 8; col++ ) {
579 if ((niqtable[row*8+col]<1) || (niqtable[row*8+col]>255)) {
580 fprintf(stderr,
581 "Warning: NIQTable Element %1d,%1d (%d) corrected to 1-255.\n",
582 row+1, col+1, niqtable[row*8+col]);
583 niqtable[row*8+col]=(niqtable[row*8+col]<1)?1:255;
584 }}
585 }
586
587 customNIQtable = niqtable;
588 optionSeen[OPTION_NIQTABLE] = TRUE;
589 }
590 break;
591
592 case 'O':
593 if ( strncmp(input, "OUTPUT", 6) == 0 ) {
594 charPtr = SkipSpacesTabs(&input[6]);
595 if ( whichGOP == -1 ) {
596 strcpy(outputFileName, charPtr);
597 } else {
598 sprintf(outputFileName, "%s.gop.%d",
599 charPtr, whichGOP);
600 }
601
602 optionSeen[OPTION_OUTPUT] = TRUE;
603 }
604 break;
605
606 case 'P':
607 if ( strncmp(input, "PATTERN", 7) == 0 ) {
608 charPtr = SkipSpacesTabs(&input[7]);
609 SetFramePattern(charPtr);
610 optionSeen[OPTION_PATTERN] = TRUE;
611 } else if ( strncmp(input, "PIXEL", 5) == 0 ) {
612 charPtr = SkipSpacesTabs(&input[5]);
613 SetPixelSearch(charPtr);
614 optionSeen[OPTION_PIXEL] = TRUE;
615 } else if ( strncmp(input, "PQSCALE", 7) == 0 ) {
616 charPtr = SkipSpacesTabs(&input[7]);
617 SetPQScale(atoi(charPtr));
618 optionSeen[OPTION_PQSCALE] = TRUE;
619 } else if ( strncmp(input, "PSEARCH_ALG", 11) == 0 ) {
620 charPtr = SkipSpacesTabs(&input[11]);
621 SetPSearchAlg(charPtr);
622 optionSeen[OPTION_PSEARCH_ALG] = TRUE;
623 } else if ( strncmp(input, "PARALLEL_TEST_FRAMES", 20) == 0 ) {
624 SetParallelPerfect(FALSE);
625 charPtr = SkipSpacesTabs(&input[20]);
626 parallelTestFrames = atoi(charPtr);
627 } else if ( strncmp(input, "PARALLEL_TIME_CHUNKS", 20) == 0 ) {
628 SetParallelPerfect(FALSE);
629 charPtr = SkipSpacesTabs(&input[20]);
630 parallelTimeChunks = atoi(charPtr);
631 } else if ( strncmp(input, "PARALLEL_CHUNK_TAPER", 20) == 0 ) {
632 SetParallelPerfect(FALSE);
633 parallelTimeChunks = -1;
634 } else if ( strncmp(input, "PARALLEL_PERFECT", 16) == 0 ) {
635 SetParallelPerfect(TRUE);
636 } else if ( strncmp(input, "PARALLEL", 8) == 0 ) {
637 ReadMachineNames(fpointer);
638 optionSeen[OPTION_PARALLEL] = TRUE;
639 }
640 break;
641
642 case 'R':
643 if ( strncmp(input, "RANGE", 5) == 0 ) {
644 int num_ranges=0,a,b;
645 charPtr = SkipSpacesTabs(&input[5]);
646 optionSeen[OPTION_RANGE] = TRUE;
647 num_ranges=sscanf(charPtr,"%d %d",&a,&b);
648 if (num_ranges==2) {
649 SetSearchRange(a,b);
650 } else if (sscanf(charPtr,"%d [%d]",&a,&b)==2) {
651 SetSearchRange(a,b);
652 } else SetSearchRange(a,a);
653 } else if ( strncmp(input, "REFERENCE_FRAME", 15) == 0 ) {
654 charPtr = SkipSpacesTabs(&input[15]);
655 SetReferenceFrameType(charPtr);
656 optionSeen[OPTION_REF_FRAME] = TRUE;
657 } else if ( strncmp(input, "RSH", 3) == 0 ) {
658 charPtr = SkipSpacesTabs(&input[3]);
659 SetRemoteShell(charPtr);
660 } else if ( strncmp(input, "RESIZE", 6) == 0 ) {
661 charPtr = SkipSpacesTabs(&input[6]);
662 sscanf(charPtr, "%dx%d", &outputWidth, &outputHeight);
663 outputWidth &= ~(DCTSIZE * 2 - 1);
664 outputHeight &= ~(DCTSIZE * 2 - 1);
665 optionSeen[OPTION_RESIZE] = TRUE;
666 }
667 break;
668
669 case 'S':
670 if ( strncmp(input, "SLICES_PER_FRAME", 16) == 0 ) {
671 charPtr = SkipSpacesTabs(&input[16]);
672 SetSlicesPerFrame(atoi(charPtr));
673 optionSeen[OPTION_SPF] = TRUE;
674 } else if ( strncmp(input, "SLAVE_CONVERT", 13) == 0 ) {
675 charPtr = SkipSpacesTabs(&input[13]);
676 strcpy(slaveConversion, charPtr);
677 optionSeen[OPTION_SLAVE_CONVERT] = TRUE;
678 } else if ( strncmp(input, "SPECIFICS_FILE", 14) == 0 ) {
679 charPtr = SkipSpacesTabs(&input[14]);
680 strcpy(specificsFile, charPtr);
681 specificsOn=TRUE;
682 optionSeen[OPTION_SPECIFICS] = TRUE;
683 } else if ( strncmp(input, "SPECIFICS_DEFINES", 16) == 0 ) {
684 charPtr = SkipSpacesTabs(&input[17]);
685 strcpy(specificsDefines, charPtr);
686 optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
687 } else if (strncmp(input, "SEQUENCE_SIZE", 13) == 0) {
688 charPtr = SkipSpacesTabs(&input[13]);
689 mult_seq_headers = atoi(charPtr);
690 } else if (strncmp(input, "SIZE", 4) == 0 ) {
691 charPtr = SkipSpacesTabs(&input[4]);
692 sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
693 realWidth = yuvWidth;
694 realHeight = yuvHeight;
695 Fsize_Validate(&yuvWidth, &yuvHeight);
696 optionSeen[OPTION_YUV_SIZE] = TRUE;
697 }
698 break;
699
700 case 'T':
701 if ( strncmp(input, "TUNE", 4) == 0) {
702 tuneingOn = TRUE;
703 charPtr = SkipSpacesTabs(&input[4]);
704 ParseTuneParam(charPtr);
705 }
706 break;
707
708 case 'U':
709 if ( strncmp(input, "USER_DATA", 9) == 0 ) {
710 charPtr = SkipSpacesTabs(&input[9]);
711 strcpy(userDataFileName, charPtr);
712 optionSeen[OPTION_USER_DATA] = TRUE;
713 }
714 break;
715
716 case 'Y':
717 if (strncmp(input, "YUV_SIZE", 8) == 0 ) {
718 charPtr = SkipSpacesTabs(&input[8]);
719 sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
720 realWidth = yuvWidth;
721 realHeight = yuvHeight;
722 Fsize_Validate(&yuvWidth, &yuvHeight);
723 optionSeen[OPTION_YUV_SIZE] = TRUE;
724 }
725 else if (strncmp(input, "Y_SIZE", 6) == 0 ) {
726 charPtr = SkipSpacesTabs(&input[6]);
727 sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
728 realWidth = yuvWidth;
729 realHeight = yuvHeight;
730 Fsize_Validate(&yuvWidth, &yuvHeight);
731 optionSeen[OPTION_YUV_SIZE] = TRUE;
732 }
733 else if ( strncmp(input, "YUV_FORMAT", 10) == 0 ) {
734 charPtr = SkipSpacesTabs(&input[10]);
735 strcpy(yuvConversion, charPtr);
736 optionSeen[OPTION_YUV_FORMAT] = TRUE;
737 }
738 break;
739 }
740 }
741
742 fclose(fpointer);
743
744 for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
745 if ( ! optionSeen[index] ) {
746
747 /* INPUT unnecessary when stdin is used */
748 if ((index == OPTION_INPUT) && stdinUsed) {
749 continue;
750 }
751
752 fprintf(stderr, "ERROR: Missing option '%s'\n", optionText[index]);
753 exit(1);
754 }
755 }
756
757 /* error checking */
758 if ( yuvUsed ) {
759
760 if (! optionSeen[OPTION_YUV_SIZE]) {
761 fprintf(stderr, "ERROR: YUV format used but YUV_SIZE not given\n");
762 exit(1);
763 }
764
765 if (! optionSeen[OPTION_YUV_FORMAT]) {
766 strcpy (yuvConversion, "EYUV");
767 fprintf(stderr, "WARNING: YUV format not specified; defaulting to Berkeley YUV (EYUV)\n\n");
768 }
769
770 }
771
772 if ( stdinUsed && optionSeen[OPTION_PARALLEL] ) {
773 fprintf(stderr, "ERROR: stdin reading for parallel execution not enabled yet.\n");
774 exit(1);
775 }
776
777
778 if ( optionSeen[OPTION_PARALLEL] && !optionSeen[OPTION_YUV_SIZE]) {
779 fprintf(stderr, "ERROR: Specify SIZE WxH for parallel encoding\n");
780 exit(1);
781 }
782
783 if ( optionSeen[OPTION_IO_CONVERT] != optionSeen[OPTION_SLAVE_CONVERT] ) {
784 fprintf(stderr, "ERROR: must have either both IO_SERVER_CONVERT and SLAVE_CONVERT\n");
785 fprintf(stderr, " or neither\n");
786 exit(1);
787 }
788
789 if ( optionSeen[OPTION_DEFS_SPECIFICS] && !optionSeen[OPTION_SPECIFICS]) {
790 fprintf(stderr, "ERROR: does not make sense to define Specifics file options, but no specifics file!\n");
791 exit(1);
792 }
793
794 SetIOConvert(optionSeen[OPTION_IO_CONVERT]);
795
796 SetResize(optionSeen[OPTION_RESIZE]);
797
798 if ( function == ENCODE_FRAMES ) {
799 SetFCode();
800
801 if ( psearchAlg == PSEARCH_TWOLEVEL )
802 SetPixelSearch("HALF");
803 }
804
805 return TRUE;
806 }
807
808
809 /*===========================================================================*
810 *
811 * GetNthInputFileName
812 *
813 * finds the nth input file name
814 *
815 * RETURNS: name is placed in already allocated fileName string
816 *
817 * SIDE EFFECTS: none
818 *
819 *===========================================================================*/
820 void
821 GetNthInputFileName(fileName, n)
822 char *fileName;
823 int n;
824 {
825 static int lastN = 0, lastMapN = 0, lastSoFar = 0;
826 int mapN;
827 register int index;
828 int soFar;
829 int loop;
830 int numPadding;
831 char numBuffer[33];
832
833 if ( stdinUsed ) {
834 return;
835 }
836
837 /* assumes n is within bounds 0...numInputFiles-1 */
838
839 if ( n >= lastN ) {
840 soFar = lastSoFar;
841 index = lastMapN;
842 } else {
843 soFar = 0;
844 index = 0;
845 }
846
847 while ( soFar + inputFileEntries[index]->numFiles <= n ) {
848 soFar += inputFileEntries[index]->numFiles;
849 index++;
850 }
851
852 mapN = index;
853
854 index = inputFileEntries[mapN]->startID +
855 inputFileEntries[mapN]->skip*(n-soFar);
856
857 numPadding = inputFileEntries[mapN]->numPadding;
858
859 if ( numPadding != -1 ) {
860 sprintf(numBuffer, "%32d", index);
861 for ( loop = 32-numPadding; loop < 32; loop++ ) {
862 if ( numBuffer[loop] != ' ' ) {
863 break;
864 } else {
865 numBuffer[loop] = '0';
866 }
867 }
868
869 if (inputFileEntries[mapN]->repeat != TRUE) {
870 sprintf(fileName, "%s%s%s",
871 inputFileEntries[mapN]->left,
872 &numBuffer[32-numPadding],
873 inputFileEntries[mapN]->right);
874 } else {
875 sprintf(fileName, "%s", inputFileEntries[mapN]->left);
876 }
877 } else {
878 if (inputFileEntries[mapN]->repeat != TRUE) {
879 sprintf(fileName, "%s%d%s",
880 inputFileEntries[mapN]->left,
881 index,
882 inputFileEntries[mapN]->right);
883 } else {
884 sprintf(fileName, "%s", inputFileEntries[mapN]->left);
885 }
886 }
887
888 lastN = n;
889 lastMapN = mapN;
890 lastSoFar = soFar;
891 }
892
893
894 /*=====================*
895 * INTERNAL PROCEDURES *
896 *=====================*/
897
898 /*===========================================================================*
899 *
900 * ReadMachineNames
901 *
902 * read a list of machine names for parallel execution
903 *
904 * RETURNS: nothing
905 *
906 * SIDE EFFECTS: machine info updated
907 *
908 *===========================================================================*/
909 static void
910 ReadMachineNames(fpointer)
911 FILE *fpointer;
912 {
913 char input[256];
914 char *charPtr;
915
916 while ( (fgets(input, 256, fpointer) != NULL) &&
917 (strncmp(input, "END_PARALLEL", 12) != 0) ) {
918 if ( input[0] == '#' || input[0] == '\n') {
919 continue;
920 }
921
922 if ( strncmp(input, "REMOTE", 6) == 0 ) {
923 charPtr = SkipSpacesTabs(&input[6]);
924 remote[numMachines] = TRUE;
925
926 sscanf(charPtr, "%s %s %s %s", machineName[numMachines],
927 userName[numMachines], executable[numMachines],
928 remoteParamFile[numMachines]);
929 } else {
930 remote[numMachines] = FALSE;
931
932 sscanf(input, "%s %s %s", machineName[numMachines],
933 userName[numMachines], executable[numMachines]);
934 }
935
936 numMachines++;
937 }
938 }
939
940
941 /*===========================================================================*
942 *
943 * ReadInputFileNames
944 *
945 * read a list of input file names
946 *
947 * RETURNS: nothing
948 *
949 * SIDE EFFECTS: info stored for retrieval using GetNthInputFileName
950 *
951 *===========================================================================*/
952 static void
953 ReadInputFileNames(fpointer, endInput)
954 FILE *fpointer;
955 char *endInput;
956 {
957 char input[256];
958 char left[256], right[256];
959 char *globPtr, *charPtr;
960 char leftNumText[256], rightNumText[256];
961 char skipNumText[256];
962 int leftNum, rightNum;
963 int skipNum;
964 boolean padding;
965 int numPadding = 0;
966 int length;
967 char full_path[MAXPATHLEN + 256];
968 FILE *jmovie;
969
970 inputFileEntries = (InputFileEntry **) malloc(INPUT_ENTRY_BLOCK_SIZE*
971 sizeof(InputFileEntry *));
972 maxInputFileEntries = INPUT_ENTRY_BLOCK_SIZE;
973
974 length = strlen(endInput);
975
976 /* read input files up until endInput */
977 while ( (fgets(input, 256, fpointer) != NULL) &&
978 (strncmp(input, endInput, length) != 0) ) {
979
980 /* if input is coming in via standard input, keep on looping till the
981 * endInput string is reached so that the program points to the right
982 * place on exit.
983 */
984 if ( stdinUsed ) {
985 continue;
986 }
987
988 /* ignore comments and newlines */
989 if ( (input[0] == '#') || (input[0] == '\n') ) {
990 continue;
991 }
992
993 if (input[0] == '`' ) { /* Recurse for commands */
994 FILE *fp;
995 char cmd[300], *start, *end, tmp[300], cdcmd[110];
996
997 start = &input[1];
998 end = &input[strlen(input)-1];
999
1000 while (*end != '`') {
1001 end--;
1002 }
1003
1004 end--;
1005
1006 if (optionSeen[OPTION_INPUT_DIR] == TRUE) {
1007 sprintf(cdcmd,"cd %s;",currentPath);
1008 } else {
1009 strcpy(cdcmd,"");
1010 }
1011 strncpy(tmp,start,end-start+1);
1012 sprintf(cmd,"(%s %s)", cdcmd, tmp);
1013
1014 fp = popen(cmd,"r");
1015 if (fp == NULL) {
1016 fprintf(stderr,"Command failed! Could not open piped command:\n%s\n",cmd);
1017 continue;
1018 }
1019 ReadInputFileNames(fp,"HOPE-THIS_ISNT_A_FILENAME.xyz5555");
1020 continue;
1021 }
1022
1023
1024 /* get rid of trailing whitespace including newline */
1025 while (isspace(input[strlen(input)-1])) {
1026 input[strlen(input)-1] = '\0';
1027 }
1028
1029 if ( numInputFileEntries == maxInputFileEntries ) { /* more space! */
1030 maxInputFileEntries += INPUT_ENTRY_BLOCK_SIZE;
1031 inputFileEntries = (InputFileEntry **) realloc(inputFileEntries,
1032 maxInputFileEntries*
1033 sizeof(InputFileEntry *));
1034 }
1035
1036 inputFileEntries[numInputFileEntries] = (InputFileEntry *)
1037 malloc(sizeof(InputFileEntry));
1038
1039 if ( input[strlen(input)-1] == ']' ) {
1040 inputFileEntries[numInputFileEntries]->glob = TRUE;
1041 inputFileEntries[numInputFileEntries]->repeat = FALSE;
1042
1043 /* star expand */
1044
1045 globPtr = input;
1046 charPtr = left;
1047 /* copy left of '*' */
1048 while ( (*globPtr != '\0') && (*globPtr != '*') ) {
1049 *charPtr = *globPtr;
1050 charPtr++;
1051 globPtr++;
1052 }
1053 *charPtr = '\0';
1054
1055 if (*globPtr == '\0') {
1056 fprintf(stderr, "WARNING: expanding non-star regular expression\n");
1057 inputFileEntries[numInputFileEntries]->repeat = TRUE;
1058 globPtr = input;
1059 charPtr = left;
1060 /* recopy left of whitespace */
1061 while ( (*globPtr != '\0') && (*globPtr != '*') &&
1062 (*globPtr != ' ') && (*globPtr != '\t')) {
1063 *charPtr = *globPtr;
1064 charPtr++;
1065 globPtr++;
1066 }
1067 *charPtr = '\0';
1068 *right = '\0';
1069 } else {
1070
1071 globPtr++;
1072 charPtr = right;
1073 /* copy right of '*' */
1074 while ( (*globPtr != '\0') && (*globPtr != ' ') &&
1075 (*globPtr != '\t') ) {
1076 *charPtr = *globPtr;
1077 charPtr++;
1078 globPtr++;
1079 }
1080 *charPtr = '\0';
1081 }
1082
1083 globPtr = SkipSpacesTabs(globPtr);
1084
1085 if ( *globPtr != '[' ) {
1086 fprintf(stderr, "ERROR: Invalid input file expansion expression (no '[')\n");
1087 exit(1);
1088 }
1089
1090 globPtr++;
1091 charPtr = leftNumText;
1092 /* copy left number */
1093 while ( isdigit(*globPtr) ) {
1094 *charPtr = *globPtr;
1095 charPtr++;
1096 globPtr++;
1097 }
1098 *charPtr = '\0';
1099
1100 if ( *globPtr != '-' ) {
1101 fprintf(stderr, "ERROR: Invalid input file expansion expression (no '-')\n");
1102 exit(1);
1103 }
1104
1105 globPtr++;
1106 charPtr = rightNumText;
1107 /* copy right number */
1108 while ( isdigit(*globPtr) ) {
1109 *charPtr = *globPtr;
1110 charPtr++;
1111 globPtr++;
1112 }
1113 *charPtr = '\0';
1114 if ( atoi(rightNumText) < atoi(leftNumText) ) {
1115 fprintf(stderr, "ERROR: Beginning of input range is higher than end.\n");
1116 exit(1);
1117 }
1118
1119
1120 if ( *globPtr != ']' ) {
1121 if ( *globPtr != '+' ) {
1122 fprintf(stderr, "ERROR: Invalid input file expansion expression (no ']')\n");
1123 exit(1);
1124 }
1125
1126 globPtr++;
1127 charPtr = skipNumText;
1128 /* copy skip number */
1129 while ( isdigit(*globPtr) ) {
1130 *charPtr = *globPtr;
1131 charPtr++;
1132 globPtr++;
1133 }
1134 *charPtr = '\0';
1135
1136 if ( *globPtr != ']' ) {
1137 fprintf(stderr, "ERROR: Invalid input file expansion expression (no ']')\n");
1138 exit(1);
1139 }
1140
1141 skipNum = atoi(skipNumText);
1142 } else {
1143 skipNum = 1;
1144 }
1145
1146 leftNum = atoi(leftNumText);
1147 rightNum = atoi(rightNumText);
1148
1149 if ( (leftNumText[0] == '0') && (leftNumText[1] != '\0') ) {
1150 padding = TRUE;
1151 numPadding = strlen(leftNumText);
1152 } else {
1153 padding = FALSE;
1154 }
1155
1156 inputFileEntries[numInputFileEntries]->startID = leftNum;
1157 inputFileEntries[numInputFileEntries]->endID = rightNum;
1158 inputFileEntries[numInputFileEntries]->skip = skipNum;
1159 inputFileEntries[numInputFileEntries]->numFiles = (rightNum-leftNum+1)/skipNum;
1160 strcpy(inputFileEntries[numInputFileEntries]->left, left);
1161 strcpy(inputFileEntries[numInputFileEntries]->right, right);
1162 if ( padding ) {
1163 inputFileEntries[numInputFileEntries]->numPadding = numPadding;
1164 } else {
1165 inputFileEntries[numInputFileEntries]->numPadding = -1;
1166 }
1167 } else {
1168 strcpy(inputFileEntries[numInputFileEntries]->left, input);
1169 if (baseFormat == JMOVIE_FILE_TYPE) {
1170 inputFileEntries[numInputFileEntries]->glob = TRUE;
1171 full_path[0] = '\0';
1172 strcpy(full_path, currentPath);
1173
1174 if (! stdinUsed) {
1175 strcat(full_path, "/");
1176 strcat(full_path, input);
1177 jmovie = fopen(input, "rb");
1178
1179 if (jmovie == NULL) {
1180 perror (input);
1181 exit (1);
1182 }
1183
1184 fseek (jmovie, (8*sizeof(char)), 0);
1185 fseek (jmovie, (2*sizeof(int)), 1);
1186
1187 if (fread (&(inputFileEntries[numInputFileEntries]->numFiles),
1188 sizeof(int), 1, jmovie) != 1) {
1189 perror ("Error in reading number of frames in JMOVIE");
1190 exit(1);
1191 }
1192 fclose (jmovie);
1193 }
1194
1195 strcpy(inputFileEntries[numInputFileEntries]->right,".jpg");
1196 inputFileEntries[numInputFileEntries]->numPadding = -1;
1197 inputFileEntries[numInputFileEntries]->startID = 1;
1198 inputFileEntries[numInputFileEntries]->endID = (inputFileEntries[numInputFileEntries]->numFiles-1);
1199 inputFileEntries[numInputFileEntries]->skip = 1;
1200 if (! realQuiet) {
1201 fprintf (stdout, "Encoding all %d frames from JMOVIE.\n", inputFileEntries[numInputFileEntries]->endID);
1202 }
1203 } else {
1204 inputFileEntries[numInputFileEntries]->glob = FALSE;
1205 inputFileEntries[numInputFileEntries]->numFiles = 1;
1206 /* fixes a bug from version 1.3: */
1207 inputFileEntries[numInputFileEntries]->numPadding = 0;
1208 /* fixes a bug from version 1.4 */
1209 strcpy(inputFileEntries[numInputFileEntries]->right,"\0");
1210 inputFileEntries[numInputFileEntries]->startID = 0;
1211 inputFileEntries[numInputFileEntries]->endID = 0;
1212 inputFileEntries[numInputFileEntries]->skip = 0;
1213 }
1214 }
1215
1216 numInputFiles += inputFileEntries[numInputFileEntries]->numFiles;
1217 numInputFileEntries++;
1218 }
1219 }
1220
1221
1222 /*===========================================================================*
1223 *
1224 * SkipSpacesTabs
1225 *
1226 * skip all spaces and tabs
1227 *
1228 * RETURNS: point to next character not a space or tab
1229 *
1230 * SIDE EFFECTS: none
1231 *
1232 *===========================================================================*/
1233 char *
1234 SkipSpacesTabs(start)
1235 char *start;
1236 {
1237 while ( (*start == ' ') || (*start == '\t') ) {
1238 start++;
1239 }
1240
1241 return start;
1242 }
1243
1244
1245 /*===========================================================================*
1246 *
1247 * GetFrameRate
1248 *
1249 * take a character string with the input frame rate
1250 * and return the correct frame rate code for use in the Sequence header
1251 *
1252 * RETURNS: frame rate code as per MPEG-I spec
1253 *
1254 * SIDE EFFECTS: none
1255 *
1256 *===========================================================================*/
1257 static int
1258 GetFrameRate(p)
1259 char *p;
1260 {
1261 float rate;
1262 int thouRate;
1263
1264 sscanf(p, "%f", &rate);
1265 thouRate = (int)(0.5+1000.0*rate);
1266
1267 if ( thouRate == 23976 ) return 1;
1268 else if ( thouRate == 24000 ) return 2;
1269 else if ( thouRate == 25000 ) return 3;
1270 else if ( thouRate == 29970 ) return 4;
1271 else if ( thouRate == 30000 ) return 5;
1272 else if ( thouRate == 50000 ) return 6;
1273 else if ( thouRate == 59940 ) return 7;
1274 else if ( thouRate == 60000 ) return 8;
1275 else {
1276 fprintf(stderr,"INVALID FRAME RATE: %s frames/sec\n", p);
1277 exit(1);
1278 }
1279 }
1280
1281
1282 /*===========================================================================*
1283 *
1284 * GetAspectRatio
1285 *
1286 * take a character string with the pixel aspect ratio
1287 * and returns the correct aspect ratio code for use in the Sequence header
1288 *
1289 * RETURNS: aspect ratio code as per MPEG-I spec
1290 *
1291 * SIDE EFFECTS: none
1292 *
1293 *===========================================================================*/
1294 static int
1295 GetAspectRatio(p)
1296 char *p;
1297 {
1298 float ratio;
1299 int ttRatio;
1300
1301 sscanf(p, "%f", &ratio);
1302 ttRatio = (int)(0.5+ratio*10000.0);
1303
1304 if ( ttRatio == 10000 ) return 1;
1305 else if ( ttRatio == 6735 ) return 2;
1306 else if ( ttRatio == 7031 ) return 3;
1307 else if ( ttRatio == 7615 ) return 4;
1308 else if ( ttRatio == 8055 ) return 5;
1309 else if ( ttRatio == 8437 ) return 6;
1310 else if ( ttRatio == 8935 ) return 7;
1311 else if ( ttRatio == 9157 ) return 8;
1312 else if ( ttRatio == 9815 ) return 9;
1313 else if ( ttRatio == 10255 ) return 10;
1314 else if ( ttRatio == 10695 ) return 11;
1315 else if ( ttRatio == 10950 ) return 12;
1316 else if ( ttRatio == 11575 ) return 13;
1317 else if ( ttRatio == 12015 ) return 14;
1318 else {
1319 fprintf(stderr,"INVALID ASPECT RATIO: %s frames/sec\n", p);
1320 exit(1);
1321 }
1322 }
1323
1324
1325
1326
1327
1328
1329 /****************************************************************
1330 * Jim Boucher's code
1331 *
1332 *
1333 ****************************************************************/
1334 void
1335 JM2JPEG()
1336 {
1337 char full_path[MAXPATHLEN + 256];
1338 char inter_file[MAXPATHLEN +256];
1339 int ci;
1340
1341 for(ci = 0; ci < numInputFileEntries; ci++) {
1342 inter_file[0] = '\0';
1343 full_path[0] = '\0';
1344 strcpy(full_path, currentPath);
1345
1346 if (! stdinUsed) {
1347 strcat(full_path, "/");
1348 strcat(full_path, inputFileEntries[ci]->left);
1349 strcpy(inter_file,full_path);
1350
1351 if (! realQuiet) {
1352 fprintf(stdout, "Extracting JPEG's in the JMOVIE from %s\n",full_path);
1353 }
1354
1355 JMovie2JPEG(full_path,
1356 inter_file,
1357 inputFileEntries[ci]->startID, inputFileEntries[ci]->endID);
1358 } else {
1359 fprintf (stderr, "ERROR: JMovie format not supported with stdin yet.\n");
1360 exit(1);
1361 }
1362
1363 }
1364 }