⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppmtompeg.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 2 页
字号:
        else            asprintfN(&outputDest, "to file '%s'", outputFileName);        if (childProcess)            combineDest = strdup("for delivery to combine server");        else            combineDest = strdup("");            pm_message("%s:  ENCODING FRAMES %u-%u to %s %s",                   hostname, frameStart, frameEnd, outputDest, combineDest);        strfree(combineDest);        strfree(outputDest);    }}static voidencodeSomeFrames(struct inputSource * const inputSourceP,                 boolean              const childProcess,                 enum frameContext    const context,                  unsigned int         const frameStart,                 unsigned int         const frameEnd,                 int32                const qtable[],                 int32                const niqtable[],                 FILE *               const ofp,                 const char *         const outputFileName,                 bool                 const wantVbvUnderflowWarning,                 bool                 const wantVbvOverflowWarning,                 boolean              const printStats,                 unsigned int *       const encodeTimeP) {        time_t framesTimeStart, framesTimeEnd;    unsigned int inputFrameBits;    unsigned int totalBits;    announceJob(context, childProcess, frameStart, frameEnd, outputFileName);    time(&framesTimeStart);    if (printStats)        PrintStartStats(framesTimeStart, context == CONTEXT_JUSTFRAMES,                        frameStart, frameEnd, inputSourceP);    GenMPEGStream(inputSourceP, context, frameStart, frameEnd,                  qtable, niqtable, childProcess, ofp, outputFileName,                   wantVbvUnderflowWarning, wantVbvOverflowWarning,                  &inputFrameBits, &totalBits);    time(&framesTimeEnd);    *encodeTimeP = (unsigned int)(framesTimeEnd - framesTimeStart);    if (!realQuiet)        pm_message("%s:  COMPLETED FRAMES %u-%u (%u seconds)",                   hostname, frameStart, frameEnd, *encodeTimeP);    if (printStats)        PrintEndStats(framesTimeStart, framesTimeEnd,                       inputFrameBits, totalBits);}static voidencodeFrames(struct inputSource * const inputSourceP,             boolean              const childProcess,             const char *         const masterHostname,             int                  const masterPortNumber,             int                  const whichGOP,             bool                 const specificFrames,             unsigned int         const whichFrameStart,             unsigned int         const whichFrameEnd,             int32                const qtable[],             int32                const niqtable[],             FILE *               const ofp,             const char *         const outputFileName,             bool                 const wantVbvUnderflowWarning,             bool                 const wantVbvOverflowWarning) {/*----------------------------------------------------------------------------  Encode the stream.  If 'specificFrames' is true, then encode frames  'whichFrameStart' through 'whichFrameEnd' individually.  Otherwise,  encode the entire input stream as a complete MPEG stream.    'childProcess' means to do it as a child process that is under the  supervision of a master process and is possibly doing only part of  a larger batch.    (If we had proper modularity, we wouldn't care, but parallel operation  was glued on to this program after it was complete).    One thing we don't do when running as a child process is print  statistics; our master will do that for the whole job.----------------------------------------------------------------------------*/    unsigned int frameStart, frameEnd;    enum frameContext context;    unsigned int      lastEncodeTime;        /* How long it took the encoder to do the last set of frames */    boolean           printStats;        /* We want the encoder to print start & end stats */    if (whichGOP != -1) {        /* He wants just one particular GOP from the middle of the movie. */        ComputeGOPFrames(whichGOP, &frameStart, &frameEnd,                          inputSourceP->numInputFiles);        context = CONTEXT_GOP;    } else if (specificFrames) {        /* He wants some pure frames from the middle of the movie */        if (whichFrameStart > whichFrameEnd)            pm_error("You specified a starting frame number (%d) that is "                     "greater than the ending frame number (%d) "                     "you specified.", whichFrameStart, whichFrameEnd);        if (whichFrameEnd + 1 > inputSourceP->numInputFiles)            pm_error("You specified ending frame number %d, which is "                     "beyond the number of input files you supplied (%u)",                     whichFrameEnd, inputSourceP->numInputFiles);        frameStart = whichFrameStart;        frameEnd   = whichFrameEnd;        context = CONTEXT_JUSTFRAMES;    } else {        /* He wants the whole movie */        frameStart = 0;        frameEnd   = inputSourceP->numInputFiles - 1;        context = CONTEXT_WHOLESTREAM;    }        printStats = !childProcess;        encodeSomeFrames(inputSourceP, childProcess, context, frameStart, frameEnd,                     customQtable, customNIQtable,                     ofp, outputFileName,                      wantVbvUnderflowWarning, wantVbvOverflowWarning,                     printStats,                     &lastEncodeTime);    if (childProcess) {        boolean moreWorkToDo;                /* A child is not capable of generating GOP or stream headers */        assert(context == CONTEXT_JUSTFRAMES);                moreWorkToDo = TRUE;  /* initial assumption */        while (moreWorkToDo) {            int nextFrameStart, nextFrameEnd;            NotifyMasterDone(masterHostname, masterPortNumber, machineNumber,                              lastEncodeTime, &moreWorkToDo,                             &nextFrameStart, &nextFrameEnd);            if (moreWorkToDo)                encodeSomeFrames(inputSourceP, childProcess,                                  CONTEXT_JUSTFRAMES,                                  nextFrameStart, nextFrameEnd,                                 customQtable, customNIQtable,                                 NULL, outputFileName,                                  wantVbvUnderflowWarning,                                  wantVbvOverflowWarning,                                 FALSE,                                 &lastEncodeTime);        }        if (!realQuiet)            pm_message("%s: Child exiting.  Master has no more work.",                       hostname);    }}static voidrunMaster(struct inputSource * const inputSourceP,          const char *         const paramFileName,          const char *         const outputFileName) {    if (paramFileName[0] != '/' && paramFileName[0] != '~')        pm_error("For parallel mode, you must "                 "use an absolute path for parameter file.  "                 "You specified '%s'", paramFileName);    else        MasterServer(inputSourceP, paramFileName, outputFileName);}static voidgetUserFrameFile(void *       const handle,                 unsigned int const frameNumber,                 FILE **      const ifPP) {        struct inputSource * const inputSourceP = (struct inputSource *) handle;    if (frameNumber >= inputSourceP->numInputFiles)        *ifPP = NULL;    else {        const char * fileName;        const char * inputFileName;        GetNthInputFileName(inputSourceP, frameNumber, &inputFileName);                asprintfN(&fileName, "%s/%s", currentFramePath, inputFileName);                *ifPP = fopen(fileName, "rb");        if (*ifPP == NULL)            pm_error("Unable to open file '%s'.  Errno = %d (%s)",                     fileName, errno, strerror(errno));                strfree(inputFileName);        strfree(fileName);    }}static voidnullDisposeFile(void *       const handle,                unsigned int const frameNumber) {}static unsigned intframePoolSize(bool const sequentialInput) {/*----------------------------------------------------------------------------   Return the number of frames that our frame memory pool needs to have.   'sequentialInput' means we'll be reading from input that comes in frame   number order and we can't go back, so we'll have to have a bigger buffer   of frames than otherwise.-----------------------------------------------------------------------------*/    unsigned int numOfFrames;    numOfFrames = 0;  /* initial value */    if (sequentialInput) {        unsigned int idx;        unsigned int bcount;        for ( idx = 0, bcount = 0; idx < strlen(framePattern); idx++) {            /* counts the maximum number of B frames between two reference             * frames.              */                        switch( framePattern[idx] ) {            case 'b':                 bcount++;                break;            case 'i':            case 'p':                if (bcount > numOfFrames)                    numOfFrames = bcount;                bcount = 0;                break;            }                        /* add 2 to hold the forward and past reference frames in addition             * to the maximum number of B's              */        }                numOfFrames += 2;    } else {        /* non-interactive, only 3 frames needed */        numOfFrames = 3;    }    return numOfFrames;}intmain(int argc, char **argv) {    FILE *ofP;    time_t  initTimeStart;    struct cmdlineInfo cmdline;    struct params params;    ppm_init(&argc, argv);    strcpy(encoder_name, argv[0]);    compileTests();    time(&initTimeStart);    SetStatFileName("");    hostname = getHostName();    parseArgs(argc, argv, &cmdline);    ReadParamFile(cmdline.paramFileName, cmdline.function, &params);    /* Jim Boucher's stuff:       if we are using a movie format then break up into frames    */    if ((!cmdline.childProcess) && (baseFormat == JMOVIE_FILE_TYPE))        JM2JPEG(params.inputSourceP);    if (printSNR || (referenceFrame == DECODED_FRAME))        decodeRefFrames = TRUE;    showBitRatePerFrame = (bitRateInfoOption && !cmdline.childProcess);    frameSummary = (!noFrameSummaryOption && !cmdline.childProcess);    numMachines = min(numMachines, cmdline.maxMachines);    Tune_Init();    Frame_Init(framePoolSize(params.inputSourceP->stdinUsed));    if (specificsOn)         Specifics_Init();    ComputeFrameTable(params.inputSourceP->stdinUsed ?                       0 : params.inputSourceP->numInputFiles);    if (ioServer) {        IoServer(params.inputSourceP, cmdline.masterHostname,                  cmdline.masterPortNumber);        return 0;    } else if (outputServer) {        CombineServer(cmdline.outputFrames,                       cmdline.masterHostname, cmdline.masterPortNumber);    } else if (decodeServer) {        DecodeServer(cmdline.outputFrames, outputFileName,                      cmdline.masterHostname, cmdline.masterPortNumber);    } else {        if ((!cmdline.specificFrames) &&            ((numMachines == 0) || (cmdline.function != ENCODE_FRAMES)) ) {            ofP = fopen(outputFileName, "wb");            if (ofP == NULL)                pm_error("Could not open output file!");        } else            ofP = NULL;                if (cmdline.function == ENCODE_FRAMES) {            if ((numMachines == 0) || (cmdline.specificFrames)) {                encodeFrames(params.inputSourceP,                             cmdline.childProcess,                              cmdline.masterHostname, cmdline.masterPortNumber,                             whichGOP, cmdline.specificFrames,                             cmdline.frameStart, cmdline.frameEnd,                             customQtable, customNIQtable,                             ofP, outputFileName,                             params.warnUnderflow, params.warnOverflow);                            } else                runMaster(params.inputSourceP,                          cmdline.paramFileName, outputFileName);        } else if ( cmdline.function == COMBINE_GOPS )            GOPsToMPEG(params.inputSourceP, outputFileName, ofP);        else if ( cmdline.function == COMBINE_FRAMES )            FramesToMPEG(ofP, params.inputSourceP,                         &getUserFrameFile, &nullDisposeFile);    }     Frame_Exit();            strfree(hostname);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -