📄 encoder.cpp
字号:
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
Bruce Lin (blin@microsoft.com), Microsoft Corporation
Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
Simon Winder (swinder@microsoft.com), Microsoft Corporation
(date: March, 1996)
and edited by
Hiroyuki Katata (katata@imgsl.mkhar.sharp.co.jp), Sharp Corporation
Norio Ito (norio@imgsl.mkhar.sharp.co.jp), Sharp Corporation
Shuichi Watanabe (watanabe@imgsl.mkhar.sharp.co.jp), Sharp Corporation
(date: October, 1997)
and also edited by
Xuemin Chen (xchen@nlvl.com). Next Level Systems, Inc.
Bob Eifrig (beifrig@nlvl.com) Next Level Systems, Inc.
and also edited by
Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
and also edited by
Yoshihiro Kikuchi (TOSHIBA CORPORATION)
Takeshi Nagai (TOSHIBA CORPORATION)
Toshiaki Watanabe (TOSHIBA CORPORATION)
Noboru Yamaguchi (TOSHIBA CORPORATION)
Marc Mongenet (Marc.Mongenet@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)
Mathias Wien (wien@ient.rwth-aachen.de) RWTH Aachen / Robert BOSCH GmbH
and also edited by
Yoshinori Suzuki (Hitachi, Ltd.)
and also edited by
Hideaki Kimata (NTT)
and also edited by
Fujitsu Laboratories Ltd. (contact: Eishi Morimatsu)
and also edited by
Massimo Ravasi (Massimo.Ravasi@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)
and also edited by
Takefumi Nagumo (nagumo@av.crl.sony.co.jp), Sony Corporation
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Sharp retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1997.
Module Name:
encoder.cpp
Abstract:
caller for encoder
Revision History:
May.09, 1999: tm5 rate control by DemoGraFX, duhoff@mediaone.net
Aug.24, 1999 : NEWPRED added by Hideaki Kimata (NTT)
Aug.30, 1999 : set _MAX_PATH to 128 (directly specified) by Hideaki Kimata (NTT)
Sep.06 1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.)
Nov.05 1999 : New parameter set file format (Simon Winder, Microsoft)
Nov.11 1999 : Fixed Complexity Estimation syntax support, version 2 (Massimo Ravasi, EPFL)
Feb.12 2000 : Bug Fix of OBSS by Takefumi Nagumo (Sony)
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#ifdef __PC_COMPILER_
#include <windows.h>
#include <mmsystem.h>
#endif // __PC_COMPILER_
#include "typeapi.h"
#include "codehead.h"
#include "paramset.h"
#include "mode.hpp"
#include "tm5rc.hpp"
#include "fstream.h"
#include "sesenc.hpp"
// #include "encoder/tps_sesenc.hpp" // deleted by Sharp (98/2/12)
///// WAVELET VTC: begin ////////////////////////////////
#include "dataStruct.hpp" // hjlee
///// WAVELET VTC: end ////////////////////////////////
#ifndef __GLOBAL_VAR_
#define __GLOBAL_VAR_
#endif
#include "global.hpp"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
#define _FOR_QUARTERSAMPLE
#ifndef _FOR_QUARTERSAMPLE // to use rgiDefaultIntraQMatrixAlpha from global.hpp now
#define _FOR_GSSP_
#ifdef _FOR_GSSP_
Int rgiDefaultIntraQMatrixAlpha [BLOCK_SQUARE_SIZE] = {
8, 17, 18, 19, 21, 23, 25, 27,
17, 18, 19, 21, 23, 25, 27, 28,
20, 21, 22, 23, 24, 26, 28, 30,
21, 22, 23, 24, 26, 28, 30, 32,
22, 23, 24, 26, 28, 30, 32, 35,
23, 24, 26, 28, 30, 32, 35, 38,
25, 26, 28, 30, 32, 35, 38, 41,
27, 28, 30, 32, 35, 38, 41, 45
};
Int rgiDefaultInterQMatrixAlpha [BLOCK_SQUARE_SIZE] = {
16, 17, 18, 19, 20, 21, 22, 23,
17, 18, 19, 20, 21, 22, 23, 24,
18, 19, 20, 21, 22, 23, 24, 25,
19, 20, 21, 22, 23, 24, 26, 27,
20, 21, 22, 23, 25, 26, 27, 28,
21, 22, 23, 24, 26, 27, 28, 30,
22, 23, 24, 26, 27, 28, 30, 31,
23, 24, 25, 27, 28, 30, 31, 33
};
#else
Int rgiDefaultIntraQMatrixAlpha [BLOCK_SQUARE_SIZE] = {
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16
};
Int rgiDefaultInterQMatrixAlpha [BLOCK_SQUARE_SIZE] = {
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16
};
#endif
#endif // _FOR_QUARTERSAMPLE
Void nextValidLine (FILE *pfPara, UInt* pnLine);
Void readVTCParam(CVTCEncoder *pvtcenc, FILE *pfPara, UInt* pnLine, UInt *frmWidth, UInt *frmHeight);
Void RunVTCCodec(char *VTCCtlFile);
Void GetIVal(CxParamSet *pPar, char *pchName, Int iInd, Int *piRtn);
Void GetDVal(CxParamSet *pPar, char *pchName, Int iInd, Double *pdRtn);
Void GetSVal(CxParamSet *pPar, char *pchName, Int iInd, char **ppchRtn);
Void GetAVal(CxParamSet *pPar, char *pchName, Int iInd, Double **ppdRtn, Int *piCount);
Void readBoolParam(CxParamSet *pPar, char *pchName, Int iInd, Bool *pbVal);
Int bPrint = 0;
#define VERSION_STRING "Version 2.1.0 (000403)"
// please update version number when you
// make changes in the following
#define BASE_LAYER 0
#define ENHN_LAYER 1
#define NO_SCALABILITY 0
#define TEMPORAL_SCALABILITY 1
#define SPATIAL_SCALABILITY 2
Int main (Int argc, Char* argv[])
{
UInt nLine = 1;
UInt* pnLine = &nLine;
FILE *pfPara;
if (argc != 2) {
printf ("Usage: %s parameter_file\n %s -version", argv [0], argv[0]);
exit (1);
}
if(argv[1][0]=='-' && argv[1][1]=='v')
{
printf("Microsoft MPEG-4 Visual CODEC %s\n",VERSION_STRING);
exit(0);
}
if ((pfPara = fopen (argv[1], "r")) == NULL ){
printf ("Parameter File Not Found\n");
exit (1);
}
// all the parameters to the encoder
Int iVersion;
Int iVTCFlag;
UInt uiFrmWidth, uiFrmHeight;
UInt firstFrm, lastFrm;
Bool bNot8Bit;
UInt uiQuantPrecision;
UInt nBits;
UInt firstVO, lastVO;
UInt nVO;
UInt uiFrmWidth_SS,uiFrmHeight_SS;
UInt uiHor_sampling_m,uiHor_sampling_n;
UInt uiVer_sampling_m,uiVer_sampling_n;
Bool bAnyScalability;
Int iSpatialOption;
char *pchPrefix;
char *pchBmpDir;
char *pchOutBmpDir;
char *pchOutStrFile;
char *pchSptDir;
char *pchSptPntDir;
// version 2 start
UInt uiHor_sampling_m_shape,uiHor_sampling_n_shape;
UInt uiVer_sampling_m_shape,uiVer_sampling_n_shape;
UInt uiUseRefShape;
UInt uiUseRefTexture;
// version 2 end
Int *rgiTemporalScalabilityType;
Bool *rgbSpatialScalability;
Bool *rgbScalability;
Int *rgiEnhancementType;
//OBSSFIX_MODE3
Int *rgiEnhancementTypeSpatial;
//~OBSSFIX_MODE3
AlphaUsage *rgfAlphaUsage;
Int *rgiAlphaShapeExtension; // MAC-V2 (SB)
Bool *rgbShapeOnly;
Int *rgiBinaryAlphaTH;
Int *rgbNoCrChange;
Int *rgiBinaryAlphaRR;
Bool *rgbRoundingControlDisable;
Int *rgiInitialRoundingType;
Int *rgiNumPbetweenIVOP;
Int *rgiNumBbetweenPVOP;
Int *rgiGOVperiod;
Bool *rgbDeblockFilterDisable;
Int *rgiTSRate;
Int *rgiEnhcTSRate;
ChromType *rgfChrType;
Bool *rgbAllowSkippedPMBs;
SptMode *rgSpriteMode;
Bool *rgbDumpMB;
Bool *rgbTrace;
UInt *rguiSpriteUsage;
UInt *rguiWarpingAccuracy;
Int *rgiNumPnts;
// version 2 start
UInt *rguiVerID;
// version 2 end
UInt *rguiRateControl [2];
UInt *rguiBitsBudget [2];
Bool *rgbAdvPredDisable [2];
Bool *rgbErrorResilientDisable [2];
Bool *rgbDataPartitioning [2];
Bool *rgbReversibleVlc [2];
Int *rgiVPBitTh [2];
Bool *rgbInterlacedCoding [2];
Quantizer* rgfQuant [2];
Bool *rgbLoadIntraMatrix [2];
Int **rgppiIntraQuantizerMatrix [2];
Bool *rgbLoadInterMatrix [2];
Int **rgppiInterQuantizerMatrix [2];
Bool *rgiIntraDCSwitchingThr [2];
Int *rgiIStep [2];
Int *rgiPStep [2];
Int *rgiStepBCode [2];
Bool *rgbLoadIntraMatrixAlpha [2];
Int **rgppiIntraQuantizerMatrixAlpha [2];
Bool *rgbLoadInterMatrixAlpha [2];
Int **rgppiInterQuantizerMatrixAlpha [2];
Int *rgiIStepAlpha [2];
Int *rgiPStepAlpha [2];
Int *rgiBStepAlpha [2];
Bool *rgbNoGrayQuantUpdate [2];
UInt *rguiSearchRange [2];
Bool *rgbOriginalME [2];
Bool *rgbComplexityEstimationDisable [2];
Bool *rgbOpaque [2];
Bool *rgbTransparent [2];
Bool *rgbIntraCAE [2];
Bool *rgbInterCAE [2];
Bool *rgbNoUpdate [2];
Bool *rgbUpsampling [2];
Bool *rgbIntraBlocks [2];
Bool *rgbInterBlocks [2];
Bool *rgbInter4vBlocks [2];
Bool *rgbNotCodedBlocks [2];
Bool *rgbDCTCoefs [2];
Bool *rgbDCTLines [2];
Bool *rgbVLCSymbols [2];
Bool *rgbVLCBits [2];
Bool *rgbAPM [2];
Bool *rgbNPM [2];
Bool *rgbInterpolateMCQ [2];
Bool *rgbForwBackMCQ [2];
Bool *rgbHalfpel2 [2];
Bool *rgbHalfpel4 [2];
UInt *rguiVolControlParameters[2];
UInt *rguiChromaFormat[2];
UInt *rguiLowDelay[2];
UInt *rguiVBVParams[2];
UInt *rguiBitRate[2];
UInt *rguiVbvBufferSize[2];
UInt *rguiVbvBufferOccupany[2];
Double *rgdFrameFrequency[2];
Bool *rgbTopFieldFirst [2];
Bool *rgbAlternateScan [2];
Int *rgiDirectModeRadius [2];
Int *rgiMVFileUsage[2];
char **pchMVFileName[2];
// version 2 start
Bool *rgbNewpredEnable[2];
Bool *rgbNewpredSegType[2];
char **pchNewpredRefName[2];
char **pchNewpredSlicePoint[2];
Bool *rgbSadctDisable[2];
Bool *rgbQuarterSample[2];
RRVmodeStr *RRVmode[2];
UInt *rguiEstimationMethod [2];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -