📄 mpeg.c
字号:
currentPath, inputFileName); strfree(inputFileName); } fprintf(fpointer, "OUTPUT: %s\n", outputFileName); if (resizeFrame) fprintf(fpointer, "RESIZED TO: %dx%d\n", outputWidth, outputHeight); fprintf(fpointer, "PATTERN: %s\n", framePattern); fprintf(fpointer, "GOP_SIZE: %d\n", gopSize); fprintf(fpointer, "SLICES PER FRAME: %d\n", slicesPerFrame); if (searchRangeP==searchRangeB) fprintf(fpointer, "RANGE: +/-%d\n", searchRangeP/2); else fprintf(fpointer, "RANGES: +/-%d %d\n", searchRangeP/2,searchRangeB/2); fprintf(fpointer, "PIXEL SEARCH: %s\n", pixelFullSearch ? "FULL" : "HALF"); fprintf(fpointer, "PSEARCH: %s\n", PSearchName()); fprintf(fpointer, "BSEARCH: %s\n", BSearchName()); fprintf(fpointer, "QSCALE: %d %d %d\n", qscaleI, GetPQScale(), GetBQScale()); if (specificsOn) fprintf(fpointer, "(Except as modified by Specifics file)\n"); if ( referenceFrame == DECODED_FRAME ) { fprintf(fpointer, "REFERENCE FRAME: DECODED\n"); } else if ( referenceFrame == ORIGINAL_FRAME ) { fprintf(fpointer, "REFERENCE FRAME: ORIGINAL\n"); } else pm_error("Illegal referenceFrame!!!"); /* For new Rate control parameters */ if (getRateMode() == FIXED_RATE) { fprintf(fpointer, "PICTURE RATE: %d\n", frameRateRounded); if (getBitRate() != -1) { fprintf(fpointer, "\nBIT RATE: %d\n", getBitRate()); } if (getBufferSize() != -1) { fprintf(fpointer, "BUFFER SIZE: %d\n", getBufferSize()); } } } if (!realQuiet) fprintf(stdout, "\n\n");}booleanNonLocalRefFrame(int const id) {/*---------------------------------------------------------------------------- Return TRUE if frame number 'id' might be referenced from a non-local process. This is a conservative estimate. We return FALSE iff there is no way based on the information we have that the frame could be referenced by a non-local process.-----------------------------------------------------------------------------*/ boolean retval; int const lastIPid = FType_PastRef(id); /* might be accessed by B-frame */ if (lastIPid+1 < realStart) retval = TRUE; else { unsigned int const nextIPid = FType_FutureRef(id); /* if B-frame is out of range, then current frame can be ref'd by it */ /* might be accessed by B-frame */ if (nextIPid > realEnd+1) retval = TRUE; /* might be accessed by P-frame */ if ((nextIPid > realEnd) && (FType_Type(nextIPid) == 'p')) retval = TRUE; } return retval;} /*===========================================================================* * * SetFrameRate * * sets global frame rate variables. value passed is MPEG frame rate code. * * RETURNS: TRUE or FALSE * * SIDE EFFECTS: frameRateRounded, frameRateInteger * *===========================================================================*/voidSetFrameRate(){ switch(frameRate) { case 1: frameRateRounded = 24; frameRateInteger = FALSE; break; case 2: frameRateRounded = 24; frameRateInteger = TRUE; break; case 3: frameRateRounded = 25; frameRateInteger = TRUE; break; case 4: frameRateRounded = 30; frameRateInteger = FALSE; break; case 5: frameRateRounded = 30; frameRateInteger = TRUE; break; case 6: frameRateRounded = 50; frameRateInteger = TRUE; break; case 7: frameRateRounded = 60; frameRateInteger = FALSE; break; case 8: frameRateRounded = 60; frameRateInteger = TRUE; break; } printf("frame rate(%d) set to %d\n", frameRate, frameRateRounded);}/*=====================* * INTERNAL PROCEDURES * *=====================*//*===========================================================================* * * ComputeDHMSTime * * turn some number of seconds (someTime) into a string which * summarizes that time according to scale (days, hours, minutes, or * seconds) * * RETURNS: nothing * * SIDE EFFECTS: none * *===========================================================================*/static voidComputeDHMSTime(someTime, timeText) int32 someTime; char *timeText;{ int days, hours, mins, secs; days = someTime / (24*60*60); someTime -= days*24*60*60; hours = someTime / (60*60); someTime -= hours*60*60; mins = someTime / 60; secs = someTime - mins*60; if ( days > 0 ) { sprintf(timeText, "Total time: %d days and %d hours", days, hours); } else if ( hours > 0 ) { sprintf(timeText, "Total time: %d hours and %d minutes", hours, mins); } else if ( mins > 0 ) { sprintf(timeText, "Total time: %d minutes and %d seconds", mins, secs); } else { sprintf(timeText, "Total time: %d seconds", secs); }}voidComputeGOPFrames(int const whichGOP, unsigned int * const firstFrameP, unsigned int * const lastFrameP, unsigned int const numFrames) {/*---------------------------------------------------------------------------- Figure out which frames are in GOP number 'whichGOP'.-----------------------------------------------------------------------------*/ unsigned int passedB; unsigned int currGOP; unsigned int gopNum; unsigned int frameNum; unsigned int firstFrame, lastFrame; bool foundGop; /* calculate first, last frames of whichGOP GOP */ gopNum = 0; frameNum = 0; passedB = 0; currGOP = 0; foundGop = FALSE; while (!foundGop) { if (frameNum >= numFrames) pm_error("There aren't that many GOPs!"); if (gopNum == whichGOP) { foundGop = TRUE; firstFrame = frameNum; } /* go past one gop */ /* must go past at least one frame */ do { currGOP += (1 + passedB); ++frameNum; passedB = 0; while ((frameNum < numFrames) && (FType_Type(frameNum) == 'b')) { ++frameNum; ++passedB; } } while ((frameNum < numFrames) && ((FType_Type(frameNum) != 'i') || (currGOP < gopSize))); currGOP -= gopSize; if (gopNum == whichGOP) lastFrame = (frameNum - passedB - 1); ++gopNum; } *firstFrameP = firstFrame; *lastFrameP = lastFrame;}static voiddoEndStats(FILE * const fpointer, time_t const startTime, time_t const endTime, unsigned int const inputFrameBits, unsigned int const totalBits, float const totalCPU) { int32 const diffTime = endTime - startTime; char timeText[256]; ComputeDHMSTime(diffTime, timeText); fprintf(fpointer, "TIME COMPLETED: %s", ctime(&endTime)); fprintf(fpointer, "%s\n\n", timeText); ShowIFrameSummary(inputFrameBits, totalBits, fpointer); ShowPFrameSummary(inputFrameBits, totalBits, fpointer); ShowBFrameSummary(inputFrameBits, totalBits, fpointer); fprintf(fpointer, "---------------------------------------------\n"); fprintf(fpointer, "Total Compression: %3d:1 (%9.4f bpp)\n", framesOutput*inputFrameBits/totalBits, 24.0*(float)(totalBits)/(float)(framesOutput*inputFrameBits)); if (diffTime > 0) { fprintf(fpointer, "Total Frames Per Sec Elapsed: %f (%ld mps)\n", (float)framesOutput/(float)diffTime, (long)((float)framesOutput * (float)inputFrameBits / (256.0*24.0*(float)diffTime))); } else { fprintf(fpointer, "Total Frames Per Sec Elapsed: Infinite!\n"); } if ( totalCPU == 0.0 ) { fprintf(fpointer, "CPU Time: NONE!\n"); } else { fprintf(fpointer, "Total Frames Per Sec CPU : %f (%ld mps)\n", (float)framesOutput/totalCPU, (long)((float)framesOutput * (float)inputFrameBits/(256.0*24.0*totalCPU))); } fprintf(fpointer, "Total Output Bit Rate (%d fps): %d bits/sec\n", frameRateRounded, frameRateRounded*totalBits/framesOutput); fprintf(fpointer, "MPEG file created in : %s\n", outputFileName); fprintf(fpointer, "\n\n"); if ( computeMVHist ) { ShowPMVHistogram(fpointer); ShowBBMVHistogram(fpointer); ShowBFMVHistogram(fpointer); }}/*===========================================================================* * * PrintEndStats * * print end statistics (summary, time information) * * RETURNS: nothing * * SIDE EFFECTS: none * *===========================================================================*/voidPrintEndStats(time_t const startTime, time_t const endTime, unsigned int const inputFrameBits, unsigned int const totalBits) { float totalCPU; totalCPU = 0.0; totalCPU += IFrameTotalTime(); totalCPU += PFrameTotalTime(); totalCPU += BFrameTotalTime(); if (!realQuiet) { fprintf(stdout, "\n\n"); doEndStats(stdout, startTime, endTime, inputFrameBits, totalBits, totalCPU); } if (statFile) { doEndStats(statFile, startTime, endTime, inputFrameBits, totalBits, totalCPU); fclose(statFile); }}voidReadDecodedRefFrame(MpegFrame * const frameP, unsigned int const frameNumber) { FILE *fpointer; char fileName[256]; int width, height; register int y; width = Fsize_x; height = Fsize_y; sprintf(fileName, "%s.decoded.%u", outputFileName, frameNumber); if (! realQuiet) { fprintf(stdout, "reading %s\n", fileName); fflush(stdout); } if ((fpointer = fopen(fileName, "rb")) == NULL) { sleep(1); if ((fpointer = fopen(fileName, "rb")) == NULL) { fprintf(stderr, "Cannot open %s\n", fileName); exit(1); }} Frame_AllocDecoded(frameP, TRUE); for ( y = 0; y < height; y++ ) { size_t bytesRead; bytesRead = fread(frameP->decoded_y[y], 1, width, fpointer); if (bytesRead != width) pm_error("Could not read enough bytes from '%s;", fileName); } for (y = 0; y < (height >> 1); y++) { /* U */ size_t const bytesToRead = width/2; size_t bytesRead; bytesRead = fread(frameP->decoded_cb[y], 1, bytesToRead, fpointer); if (bytesRead != bytesToRead) pm_message("Could not read enough bytes from '%s'", fileName); } for (y = 0; y < (height >> 1); y++) { /* V */ size_t const bytesToRead = width/2; size_t bytesRead; bytesRead = fread(frameP->decoded_cr[y], 1, bytesToRead, fpointer); if (bytesRead != bytesToRead) pm_message("Could not read enough bytes from '%s'", fileName); } fclose(fpointer);}static voidOpenBitRateFile() { bitRateFile = fopen(bitRateFileName, "w"); if ( bitRateFile == NULL ) { pm_message("ERROR: Could not open bit rate file: '%s'", bitRateFileName); showBitRatePerFrame = FALSE; }}static voidCloseBitRateFile() { fclose(bitRateFile);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -