📄 pframe.c
字号:
mbAddrInc = 1; } /* now output the difference */ for ( tempX = 0; tempX < 6; tempX++ ) { if ( GET_ITH_BIT(pattern, 5-tempX) ) { Mpost_RLEHuffPBlock(fba[tempX], bb); } } numPBits += (bb->cumulativeBits-totalBits); totalBits = bb->cumulativeBits; } if (overflowChange) { /* undo an overflow-caused Qscale change */ overflowChange = FALSE; QScale -= overflowValue; overflowValue = 0; } mbAddress++; /* Rate Control */ if (bitstreamMode == FIXED_RATE) { incMacroBlockBits( bb->cumulativeBits- rc_blockStart); rc_blockStart = bb->cumulativeBits; MB_RateOut(TYPE_PFRAME); } } } if ( printSNR ) { BlockComputeSNR(current,snr,psnr); totalSNR += snr[0]; totalPSNR += psnr[0]; }#ifdef BLEAHBLEAH { FILE *filePtr; filePtr = fopen("PFRAME.yuv", "wb"); for ( y = 0; y < Fsize_y; y++ ) { for ( x = 0; x < Fsize_x; x++ ) fprintf(filePtr, "%d ", current->decoded_y[y][x]); fprintf(filePtr, "\n"); } fclose(filePtr); }#endif Mhead_GenSliceEnder(bb); /* Rate Control */ if (bitstreamMode == FIXED_RATE) { updateRateControl(TYPE_PFRAME); } /* UPDATE STATISTICS */ endTime = time_elapsed(); totalTime += (endTime-startTime); if ( showBitRatePerFrame ) { /* ASSUMES 30 FRAMES PER SECOND */ fprintf(bitRateFile, "%5d\t%8d\n", current->id, 30*(bb->cumulativeBits-totalFrameBits)); } if ( frameSummary && (! realQuiet) ) { fprintf(stdout, "FRAME %d (P): I BLOCKS: %d; " "P BLOCKS: %d SKIPPED: %d (%ld seconds)\n", current->id, numIBlocks, numPBlocks, numSkipped, (long)(endTime-startTime)/TIME_RATE); if ( printSNR ) { fprintf(stdout, "FRAME %d: SNR: %.1f\t%.1f\t%.1f\t" "PSNR: %.1f\t%.1f\t%.1f\n", current->id, snr[0], snr[1], snr[2], psnr[0], psnr[1], psnr[2]); } } numFrameBits += (bb->cumulativeBits-totalFrameBits); numPIBlocks += numIBlocks; numPPBlocks += numPBlocks; numPSkipped += numSkipped; numPIBits += numIBits; numPPBits += numPBits;}/*===========================================================================* * * ResetPFrameStats * * reset the P-frame statistics * * RETURNS: nothing * * SIDE EFFECTS: none * *===========================================================================*/void ResetPFrameStats(){ numPIBlocks = 0; numPPBlocks = 0; numPSkipped = 0; numPIBits = 0; numPPBits = 0; numFrames = 0; numFrameBits = 0; totalTime = 0;}/*===========================================================================* * * SetPQScale * * set the P-frame Q-scale * * RETURNS: nothing * * SIDE EFFECTS: qscaleP * *===========================================================================*/void SetPQScale(qP)int qP;{ qscaleP = qP;}/*===========================================================================* * * GetPQScale * * return the P-frame Q-scale * * RETURNS: the P-frame Q-scale * * SIDE EFFECTS: none * *===========================================================================*/int GetPQScale(){ return qscaleP;}floatPFrameTotalTime(void) { return (float)totalTime/(float)TIME_RATE;}voidShowPFrameSummary(unsigned int const inputFrameBits, unsigned int const totalBits, FILE * const fpointer) { if (numFrames > 0) { fprintf(fpointer, "-------------------------\n"); fprintf(fpointer, "*****P FRAME SUMMARY*****\n"); fprintf(fpointer, "-------------------------\n"); if ( numPIBlocks != 0 ) { fprintf(fpointer, " I Blocks: %5d (%6d bits) (%5d bpb)\n", numPIBlocks, numPIBits, numPIBits/numPIBlocks); } else { fprintf(fpointer, " I Blocks: %5d\n", 0); } if ( numPPBlocks != 0 ) { fprintf(fpointer, " P Blocks: %5d (%6d bits) (%5d bpb)\n", numPPBlocks, numPPBits, numPPBits/numPPBlocks); } else { fprintf(fpointer, " P Blocks: %5d\n", 0); } fprintf(fpointer, " Skipped: %5d\n", numPSkipped); fprintf(fpointer, " Frames: %5d (%6d bits) (%5d bpf) (%2.1f%% of total)\n", numFrames, numFrameBits, numFrameBits/numFrames, 100.0*(float)numFrameBits/(float)totalBits); fprintf(fpointer, " Compression: %3d:1 (%9.4f bpp)\n", numFrames*inputFrameBits/numFrameBits, 24.0*(float)numFrameBits/(float)(numFrames*inputFrameBits)); if ( printSNR ) fprintf(fpointer, " Avg Y SNR/PSNR: %.1f %.1f\n", totalSNR/(float)numFrames, totalPSNR/(float)numFrames); if ( totalTime == 0 ) { fprintf(fpointer, " Seconds: NONE\n"); } else { fprintf(fpointer, " Seconds: %9ld (%9.4f fps) (%9ld pps) (%9ld mps)\n", (long)(totalTime/TIME_RATE), (float)((float)(TIME_RATE*numFrames)/(float)totalTime), (long)((float)TIME_RATE*(float)numFrames*(float)inputFrameBits/(24.0*(float)totalTime)), (long)((float)TIME_RATE*(float)numFrames*(float)inputFrameBits/(256.0*24.0*(float)totalTime))); } }}/*===========================================================================* * * EstimateSecondsPerPFrame * * compute an estimate of the number of seconds required per P-frame * * RETURNS: the estimate, in seconds * * SIDE EFFECTS: none * *===========================================================================*/float EstimateSecondsPerPFrame(){ if ( numFrames == 0 ) { return 10.0; } else { return (float)totalTime/((float)TIME_RATE*(float)numFrames); }}/*===========================================================================* * * ComputeHalfPixelData * * compute all half-pixel data required for half-pixel motion vector * search (luminance only) * * RETURNS: frame->halfX, ->halfY, and ->halfBoth modified * * SIDE EFFECTS: none * *===========================================================================*/void ComputeHalfPixelData(frame)MpegFrame *frame;{ register int x, y; /* we add 1 before dividing by 2 because .5 is supposed to be rounded up * (see MPEG-1, page D-31) */ if ( frame->halfX == NULL ) { /* need to allocate memory */ Frame_AllocHalf(frame); } /* compute halfX */ for ( y = 0; y < Fsize_y; y++ ) { for ( x = 0; x < Fsize_x-1; x++ ) { frame->halfX[y][x] = (frame->ref_y[y][x]+ frame->ref_y[y][x+1]+1)>>1; } } /* compute halfY */ for ( y = 0; y < Fsize_y-1; y++ ) { for ( x = 0; x < Fsize_x; x++ ) { frame->halfY[y][x] = (frame->ref_y[y][x]+ frame->ref_y[y+1][x]+1)>>1; } } /* compute halfBoth */ for ( y = 0; y < Fsize_y-1; y++ ) { for ( x = 0; x < Fsize_x-1; x++ ) { frame->halfBoth[y][x] = (frame->ref_y[y][x]+ frame->ref_y[y][x+1]+ frame->ref_y[y+1][x]+ frame->ref_y[y+1][x+1]+2)>>2; } } frame->halfComputed = TRUE;}/* * 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: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/pframe.c,v 1.22 1995/08/07 21:51:23 smoot Exp $ * $Log: pframe.c,v $ * Revision 1.22 1995/08/07 21:51:23 smoot * fixed LumMotionError call, simpler now with option type * * Revision 1.21 1995/06/21 22:23:16 smoot * fixed specifics file bug * generalized timeing stuff * binary writes * TUNEing stuff * * Revision 1.20 1995/04/14 23:07:41 smoot * reorganized to ease rate control experimentation * * Revision 1.19 1995/02/24 23:49:27 smoot * added specifications file format 2 * * Revision 1.18 1995/02/01 21:48:17 smoot * cleanup * * Revision 1.17 1995/01/23 06:30:01 darryl * fixed bug in "MMB Type "pattern" and Rate control * * Revision 1.15 1995/01/19 23:49:28 smoot * moved rev_dct, make pattern changable by ComputeDiffDCTs * * Revision 1.14 1995/01/19 23:09:07 eyhung * Changed copyrights * * Revision 1.13 1995/01/19 23:00:26 smoot * Fixed 1st/last MB in slice color bug in P-frames * * Revision 1.12 1995/01/17 22:10:27 smoot * Fixed B/P Qscale bug * * Revision 1.11 1995/01/16 08:14:41 eyhung * added realQuiet * * Revision 1.10 1994/12/07 00:40:36 smoot * Added seperate P and B search ranges * * Revision 1.9 1994/11/14 22:38:18 smoot * merged specifics and rate control * * Revision 1.8 1994/11/01 05:01:09 darryl * with rate control changes added * * Revision 2.1 1994/10/31 00:05:39 darryl * version before, hopefully, final changes * * Revision 2.0 1994/10/24 02:38:26 darryl * will be adding the experiment code * * Revision 1.1 1994/09/27 00:15:44 darryl * Initial revision * * Revision 1.7 1994/03/15 00:27:11 keving * nothing * * Revision 1.6 1993/12/22 19:19:01 keving * nothing * * Revision 1.5 1993/07/22 22:23:43 keving * nothing * * Revision 1.4 1993/06/30 20:06:09 keving * nothing * * Revision 1.3 1993/06/03 21:08:08 keving * nothing * * Revision 1.2 1993/03/02 23:03:42 keving * nothing * * Revision 1.1 1993/02/19 19:14:12 keving * nothing * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -