📄 ppmtompeg.c
字号:
/*===========================================================================* * main.c * * Main procedure * *===========================================================================*//* * Copyright (c) 1995 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. *//*==============* * HEADER FILES * *==============*/#include <assert.h>#include <sys/utsname.h>#include "all.h"#include "mtypes.h"#include "mpeg.h"#include "motion_search.h"#include "prototypes.h"#include "param.h"#include "parallel.h"#include "readframe.h"#include "combine.h"#include "frames.h"#include "jpeg.h"#include "specifics.h"#include "opts.h"#include "frametype.h"#include "input.h"#include "ppm.h"#include "nstring.h"#include <time.h>int main _ANSI_ARGS_((int argc, char **argv));/*==================* * GLOBAL VARIABLES * *==================*/boolean showBitRatePerFrame;boolean frameSummary;extern time_t IOtime;int whichGOP = -1;boolean ioServer = FALSE;boolean outputServer = FALSE;boolean decodeServer = FALSE;int quietTime = 0;boolean realQuiet = FALSE;boolean noFrameSummaryOption = FALSE;boolean debugSockets = FALSE;boolean debugMachines = FALSE;boolean bitRateInfoOption = FALSE;boolean computeMVHist = FALSE;int baseFormat;extern boolean specificsOn;extern FrameSpecList *fsl;boolean pureDCT=FALSE;char encoder_name[1024];const char * hostname;/*================================* * External PROCEDURE prototypes * *================================*/void init_idctref _ANSI_ARGS_((void));void init_fdct _ANSI_ARGS_((void));struct cmdlineInfo { bool childProcess; int function; const char * masterHostname; int masterPortNumber; unsigned int outputFrames; int maxMachines; const char * paramFileName; bool specificFrames; unsigned int frameStart; unsigned int frameEnd;};static voidparseArgs(int const argc, char ** const argv, struct cmdlineInfo * const cmdlineP) { int idx; if (argc-1 < 1) pm_error("You must specify at least one argument: the parameter " "file name"); cmdlineP->function = ENCODE_FRAMES; cmdlineP->childProcess = FALSE; /* initial assumption */ cmdlineP->outputFrames = 0; cmdlineP->maxMachines = MAXINT; cmdlineP->specificFrames = FALSE; /* parse the arguments */ idx = 1; while ( idx < argc-1 ) { if ( argv[idx][0] != '-' ) pm_error("argument '%s', which must be an option because " "it is not the last argument, " "does not start with '-'", argv[idx]); if ( strcmp(argv[idx], "-stat") == 0 ) { if ( idx+1 < argc-1 ) { SetStatFileName(argv[idx+1]); idx += 2; } else { pm_error("Invalid -stat option"); } } else if ( strcmp(argv[idx], "-gop") == 0 ) { if ((cmdlineP->function != ENCODE_FRAMES) || (cmdlineP->specificFrames)) pm_error("Invalid -gop option"); if ( idx+1 < argc-1 ) { whichGOP = atoi(argv[idx+1]); idx += 2; } else { pm_error("Invalid -gop option"); } } else if ( strcmp(argv[idx], "-frames") == 0 ) { if ( (cmdlineP->function != ENCODE_FRAMES) || (whichGOP != -1) ) { pm_error("invalid -frames option"); } if ( idx+2 < argc-1 ) { int const frameStart = atoi(argv[idx+1]); int const frameEnd = atoi(argv[idx+2]); if (frameStart > frameEnd) pm_error("Start frame number %d is greater than end " "frame number %d", frameStart, frameEnd); if (frameStart < 0) pm_error("Start frame number %d is less than zero", frameStart); cmdlineP->specificFrames = TRUE; cmdlineP->frameStart = frameStart; cmdlineP->frameEnd = frameEnd; idx += 3; } else pm_error("-frames needs to be followed by two values"); } else if (strcmp(argv[idx], "-combine_gops") == 0) { if ((cmdlineP->function != ENCODE_FRAMES) || (whichGOP != -1) || (cmdlineP->specificFrames)) { pm_error("Invalid -combine_gops option"); } cmdlineP->function = COMBINE_GOPS; idx++; } else if (strcmp(argv[idx], "-combine_frames") == 0) { if ((cmdlineP->function != ENCODE_FRAMES) || (whichGOP != -1) || (cmdlineP->specificFrames)) pm_error("Invalid -combine_frames option"); cmdlineP->function = COMBINE_FRAMES; idx++; } else if ( strcmp(argv[idx], "-child") == 0 ) { if ( idx+7 < argc-1 ) { int combinePortNumber; /* This used to be important information, when the child notified the combine server. Now the master notifies the combine server after the child notifies the master it is done. So this value is unused. */ cmdlineP->masterHostname = argv[idx+1]; cmdlineP->masterPortNumber = atoi(argv[idx+2]); ioPortNumber = atoi(argv[idx+3]); combinePortNumber = atoi(argv[idx+4]); decodePortNumber = atoi(argv[idx+5]); machineNumber = atoi(argv[idx+6]); remoteIO = atoi(argv[idx+7]); IOhostName = cmdlineP->masterHostname; } else pm_error("Not enough option values for -child option. " "Need 7."); cmdlineP->childProcess = TRUE; idx += 8; } else if ( strcmp(argv[idx], "-io_server") == 0 ) { if ( idx+2 < argc-1 ) { cmdlineP->masterHostname = argv[idx+1]; cmdlineP->masterPortNumber = atoi(argv[idx+2]); } else { pm_error("Invalid -io_server option"); } ioServer = TRUE; idx += 3; } else if ( strcmp(argv[idx], "-output_server") == 0 ) { if ( idx+3 < argc-1 ) { cmdlineP->masterHostname = argv[idx+1]; cmdlineP->masterPortNumber = atoi(argv[idx+2]); cmdlineP->outputFrames = atoi(argv[idx+3]); } else { pm_error("-output_server option requires 3 option values. " "You specified %d", argc-1 - idx); } outputServer = TRUE; idx += 4; } else if ( strcmp(argv[idx], "-decode_server") == 0 ) { if ( idx+3 < argc-1 ) { cmdlineP->masterHostname = argv[idx+1]; cmdlineP->masterPortNumber = atoi(argv[idx+2]); cmdlineP->outputFrames = atoi(argv[idx+3]); } else { pm_error("Invalid -decode_server option"); } cmdlineP->function = COMBINE_FRAMES; decodeServer = TRUE; idx += 4; } else if ( strcmp(argv[idx], "-nice") == 0 ) { niceProcesses = TRUE; idx++; } else if ( strcmp(argv[idx], "-max_machines") == 0 ) { if ( idx+1 < argc-1 ) { cmdlineP->maxMachines = atoi(argv[idx+1]); } else { pm_error("Invalid -max_machines option"); } idx += 2; } else if ( strcmp(argv[idx], "-quiet") == 0 ) { if ( idx+1 < argc-1 ) { quietTime = atoi(argv[idx+1]); } else { pm_error("Invalid -quiet option"); } idx += 2; } else if ( strcmp(argv[idx], "-realquiet") == 0 ) { realQuiet = TRUE; idx++; } else if (( strcmp(argv[idx], "-float_dct") == 0 ) || ( strcmp(argv[idx], "-float-dct") == 0 )) { pureDCT = TRUE; init_idctref(); init_fdct(); idx++; } else if ( strcmp(argv[idx], "-no_frame_summary") == 0 ) { if ( idx < argc-1 ) { noFrameSummaryOption = TRUE; } else { pm_error("Invalid -no_frame_summary option"); } idx++; } else if ( strcmp(argv[idx], "-snr") == 0 ) { printSNR = TRUE; idx++; } else if ( strcmp(argv[idx], "-mse") == 0 ) { printSNR = printMSE = TRUE; idx++; } else if ( strcmp(argv[idx], "-debug_sockets") == 0 ) { debugSockets = TRUE; idx++; } else if ( strcmp(argv[idx], "-debug_machines") == 0 ) { debugMachines = TRUE; idx++; } else if ( strcmp(argv[idx], "-bit_rate_info") == 0 ) { if ( idx+1 < argc-1 ) { bitRateInfoOption = TRUE; SetBitRateFileName(argv[idx+1]); idx += 2; } else { pm_error("Invalid -bit_rate_info option"); } } else if ( strcmp(argv[idx], "-mv_histogram") == 0 ) { computeMVHist = TRUE; idx++; } else { pm_error("Unrecognized option: '%s'", argv[idx]); } } cmdlineP->paramFileName = argv[argc-1];}static const char *getHostName(void) {/*---------------------------------------------------------------------------- Return the host name of this system.-----------------------------------------------------------------------------*/ struct utsname utsname; int rc; rc = uname(&utsname); if (rc < 0) pm_error("Unable to find out host name. " "uname() failed with errno %d (%s)", errno, strerror(errno)); return strdup(utsname.nodename);}static voidcompileTests() { /* There was code here (assert() calls) that verified that uint16 is 16 bits, etc. It caused compiler warnings that said, "Of course it is!" (actually, "statement has no effect"). There isn't enough chance that uint16, etc. are defined incorrectly to warrant those asserts. 2000.05.07 */ if ( (-8 >> 3) != -1 ) { fprintf(stderr, "ERROR: Right shifts are NOT arithmetic!!!\n"); fprintf(stderr, "Change >> to multiplies by powers of 2\n"); exit(1); }}static voidannounceJob(enum frameContext const context, bool const childProcess, unsigned int const frameStart, unsigned int const frameEnd, const char * const outputFileName) { if (!realQuiet) { const char * outputDest; const char * combineDest; if (context == CONTEXT_JUSTFRAMES) asprintfN(&outputDest, "to individual frame files");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -