ref: 41ddc536d6e82c4b86f521d5ed864f986198fe28
parent: 7ef2e9553ce4c8985a36fbf8d5927ce9e83fa2de
parent: 5b38a94c9ad9e0a192192a1f855191b4af79ee2c
author: huili2 <huili2@cisco.com>
date: Tue May 13 08:58:09 EDT 2014
Merge pull request #825 from ruil2/console_cleanup1 cleanup encoder console app
--- a/codec/console/enc/src/welsenc.cpp
+++ b/codec/console/enc/src/welsenc.cpp
@@ -312,85 +312,6 @@
return iRet;
}
-int ParseCommandLine (int argc, char** argv, SEncParamExt& sParam) {
- char* pCmd;
- int i = 0;
-
- while (i < argc) {
- pCmd = argv[i++];
-
- if (!strcmp (pCmd, "-numl") && (i < argc))
- sParam.iSpatialLayerNum = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-numt") && (i < argc))
- sParam.iTemporalLayerNum = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-iper") && (i < argc))
- sParam.uiIntraPeriod = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-nalsize") && (i < argc))
- sParam.uiMaxNalSize = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-spsid") && (i < argc))
- sParam.bEnableSpsPpsIdAddition = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-denois") && (i < argc))
- sParam.bEnableDenoise = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-bgd") && (i < argc))
- sParam.bEnableBackgroundDetection = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-aq") && (i < argc))
- sParam.bEnableAdaptiveQuant = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-fs") && (i < argc))
- sParam.bEnableFrameSkip = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-ltr") && (i < argc))
- sParam.bEnableLongTermReference = atoi (argv[i++]) ? true : false;
-
- else if (!strcmp (pCmd, "-ltrnum") && (i < argc))
- sParam.iLTRRefNum = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-ltrper") && (i < argc))
- sParam.iLtrMarkPeriod = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-threadIdc") && (i < argc))
- sParam.iMultipleThreadIdc= atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-deblockIdc") && (i < argc))
- sParam.iLoopFilterDisableIdc = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-alphaOffset") && (i < argc))
- sParam.iLoopFilterAlphaC0Offset = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-betaOffset") && (i < argc))
- sParam.iLoopFilterBetaOffset = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-rcm") && (i < argc))
- sParam.iRCMode = (RC_MODES) atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-tarb") && (i < argc))
- sParam.iTargetBitrate = 1000*atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-ltarb") && (i + 1 < argc)) {
- int iLayer = atoi (argv[i++]);
- sParam.sSpatialLayers[iLayer].iSpatialBitrate = atoi (argv[i++]);
- }
-
- else if (!strcmp (pCmd, "-trace") && (i < argc))
- g_LevelSetting = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-dw") && (i < argc))
- sParam.iPicWidth = atoi (argv[i++]);
-
- else if (!strcmp (pCmd, "-dh") && (i < argc))
- sParam.iPicHeight = atoi (argv[i++]);
- }
-
- return 0;
-}
-
void PrintHelp() {
printf ("\n Wels SVC Encoder Usage:\n\n");
printf (" Syntax: welsenc.exe -h\n");
@@ -421,6 +342,7 @@
printf (" -tarb Overall target bitrate\n");
printf (" -numl Number Of Layers: Must exist with layer_cfg file and the number of input layer_cfg file must equal to the value set by this command\n");
printf (" The options below are layer-based: (need to be set with layer id)\n");
+ printf (" -lconfig (Layer) (spatial layer configure file)\n");
printf (" -drec (Layer) (reconstruction file);example: -drec 0 rec.yuv. Setting the reconstruction file, this will only functioning when dumping reconstruction is enabled\n");
printf (" -dw (Layer) (output width)\n");
printf (" -dh (Layer) (output height)\n");
@@ -517,17 +439,14 @@
else if (!strcmp (pCommand, "-numl") && (n < argc)) {
pSvcParam.iSpatialLayerNum = atoi (argv[n++]);
- for (int ln = 0 ; (ln < pSvcParam.iSpatialLayerNum) && (n < argc) ; ln++) {
-// pSvcParam.sDependencyLayers[ln].uiDependencyId = ln;
- sFileSet.strLayerCfgFile[ln].assign (argv[n++]);
+ }
+ else if (!strcmp (pCommand, "-lconfig") && (n < argc)) {
+ unsigned int iLayer = atoi (argv[n++]);
+ sFileSet.strLayerCfgFile[iLayer].assign (argv[n++]);
+ CReadConfig cRdLayerCfg (sFileSet.strLayerCfgFile[iLayer]);
+ if (-1 == ParseLayerConfig (cRdLayerCfg, iLayer, pSvcParam, sFileSet)) {
+ return 1;
}
-
- for (int8_t iLayer = 0; iLayer < pSvcParam.iSpatialLayerNum; ++ iLayer) {
- CReadConfig cRdLayerCfg (sFileSet.strLayerCfgFile[iLayer]);
- if (-1 == ParseLayerConfig (cRdLayerCfg, iLayer, pSvcParam, sFileSet)) {
- return 1;
- }
- }
} else if (!strcmp (pCommand, "-drec") && (n + 1 < argc)) {
unsigned int iLayer = atoi (argv[n++]);
const unsigned int iLen = strlen (argv[n]);
@@ -632,9 +551,10 @@
sParam.iInputCsp = videoFormatI420; // color space of input sequence
sParam.uiIntraPeriod = 320; // period of Intra frame
sParam.bEnableSpsPpsIdAddition = 1;
- sParam.bPrefixNalAddingCtrl = 1;
+ sParam.bPrefixNalAddingCtrl = 0;
int iIndexLayer = 0;
+ sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_BASELINE;
sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 160;
sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 90;
sParam.sSpatialLayers[iIndexLayer].fFrameRate = 7.5f;
@@ -642,6 +562,7 @@
sParam.sSpatialLayers[iIndexLayer].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
++ iIndexLayer;
+ sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE;
sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 320;
sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 180;
sParam.sSpatialLayers[iIndexLayer].fFrameRate = 15.0f;
@@ -649,6 +570,7 @@
sParam.sSpatialLayers[iIndexLayer].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
++ iIndexLayer;
+ sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE;
sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 640;
sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 360;
sParam.sSpatialLayers[iIndexLayer].fFrameRate = 30.0f;
@@ -657,6 +579,7 @@
sParam.sSpatialLayers[iIndexLayer].sSliceCfg.sSliceArgument.uiSliceNum = 1;
++ iIndexLayer;
+ sParam.sSpatialLayers[iIndexLayer].uiProfileIdc = PRO_SCALABLE_BASELINE;
sParam.sSpatialLayers[iIndexLayer].iVideoWidth = 1280;
sParam.sSpatialLayers[iIndexLayer].iVideoHeight = 720;
sParam.sSpatialLayers[iIndexLayer].fFrameRate = 30.0f;
@@ -674,174 +597,7 @@
return 0;
}
-/* For SVC Demo test */
-int ProcessEncodingSvcWithParam (ISVCEncoder* pPtrEnc, int argc, char** argv) {
- const char* kpSrcFile = argv[1];
- const char* kpStrBsFile = argv[2];
-
- if (pPtrEnc == NULL || kpSrcFile == NULL || kpStrBsFile == NULL)
- return 1;
-
- FILE* pFpBs = NULL;
- FILE* pFpSrc = NULL;
- SFrameBSInfo sFbi;
- SEncParamExt sSvcParam;
- int64_t iStart = 0, iTotal = 0;
- int32_t ret = 0;
-
- int32_t iPicLumaSize = 0;
- int32_t iFrameSize = 0;
- uint8_t* pPlanes[3] = { 0 };
- int32_t iFrame = 0;
- SSourcePicture* pSrcPic = NULL;
-#if defined ( STICK_STREAM_SIZE )
- FILE* fTrackStream = fopen ("coding_size.stream", "wb");;
-#endif
-
- pFpSrc = fopen (kpSrcFile, "rb");
- if (NULL == pFpSrc)
- return 1;
- pFpBs = fopen (kpStrBsFile, "wb");
- if (NULL == pFpBs) {
- fclose (pFpSrc);
- pFpSrc = NULL;
- return 1;
- }
-
- memset (&sFbi, 0, sizeof (SFrameBSInfo));
- memset (&sSvcParam, 0, sizeof (SEncParamExt));
-
- FillSpecificParameters (sSvcParam);
-
- int iParsedNum = 3;
- if (ParseCommandLine (argc - iParsedNum, argv + iParsedNum, sSvcParam) != 0) {
- printf ("parse pCommand line failed\n");
- ret = 1;
- goto ERROR_RET;
- }
- pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &g_LevelSetting);
- if (cmResultSuccess != pPtrEnc->InitializeExt (&sSvcParam)) {
- fprintf (stderr, "Encoder Initialization failed!\n");
- ret = 1;
- goto ERROR_RET;
- }
- iPicLumaSize = sSvcParam.iPicWidth * sSvcParam.iPicHeight;
- switch (sSvcParam.iInputCsp) {
- int iStride;
- case videoFormatI420:
- case videoFormatYV12:
- iFrameSize = (3 * iPicLumaSize) >> 1;
- pPlanes[0] = new uint8_t[iFrameSize];
- pPlanes[1] = pPlanes[0] + iPicLumaSize;
- pPlanes[2] = pPlanes[1] + (iPicLumaSize >> 2);
- break;
- case videoFormatYUY2:
- case videoFormatYVYU:
- case videoFormatUYVY:
- iStride = CALC_BI_STRIDE (sSvcParam.iPicWidth, 16);
- iFrameSize = iStride * sSvcParam.iPicHeight;
- pPlanes[0] = new uint8_t[iFrameSize];
- break;
- case videoFormatRGB:
- case videoFormatBGR:
- iStride = CALC_BI_STRIDE (sSvcParam.iPicWidth, 24);
- iFrameSize = iStride * sSvcParam.iPicHeight;
- pPlanes[0] = new uint8_t[iFrameSize];
- break;
- case videoFormatBGRA:
- case videoFormatRGBA:
- case videoFormatARGB:
- case videoFormatABGR:
- iStride = 4 * sSvcParam.iPicWidth;
- iFrameSize = iStride * sSvcParam.iPicHeight;
- pPlanes[0] = new uint8_t[iFrameSize];
- break;
- default:
- ret = 1;
- goto ERROR_RET;
- }
-
- pSrcPic = new SSourcePicture;
- if (pSrcPic == NULL) {
- ret = 1;
- goto ERROR_RET;
- }
-
- pSrcPic->iColorFormat = sSvcParam.iInputCsp;
- pSrcPic->iPicHeight = sSvcParam.iPicHeight;
- pSrcPic->iPicWidth = sSvcParam.iPicWidth;
- pSrcPic->iStride[0] = sSvcParam.iPicWidth;
- pSrcPic->iStride[1] = pSrcPic->iStride[2] = sSvcParam.iPicWidth >> 1;
-
- pSrcPic->pData[0] = pPlanes[0];
- pSrcPic->pData[1] = pSrcPic->pData[0] + (sSvcParam.iPicWidth * sSvcParam.iPicHeight);
- pSrcPic->pData[2] = pSrcPic->pData[1] + (sSvcParam.iPicWidth * sSvcParam.iPicHeight >> 2);
-
- while (true) {
- if (feof (pFpSrc))
- break;
-#ifdef ONLY_ENC_FRAMES_NUM
- if (iFrame >= ONLY_ENC_FRAMES_NUM)
- break;
-#endif//ONLY_ENC_FRAMES_NUM
- if (fread (pPlanes[0], sizeof (uint8_t), iFrameSize, pFpSrc) <= 0)
- break;
-
- iStart = WelsTime();
- long iEncode = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
- iTotal += WelsTime() - iStart;
- if (cmResultSuccess != iEncode) {
- fprintf (stderr, "EncodeFrame() failed: %ld.\n", iEncode);
- break;
- }
-
- /* Write bit-stream */
- if (pFpBs != NULL && videoFrameTypeSkip != sFbi.eOutputFrameType) { // file handler to write bit stream
- int iLayer = 0;
- while (iLayer < sFbi.iLayerNum) {
- SLayerBSInfo* pLayerBsInfo = &sFbi.sLayerInfo[iLayer];
- if (pLayerBsInfo != NULL) {
- int iLayerSize = 0;
- int iNalIdx = pLayerBsInfo->iNalCount - 1;
- do {
- iLayerSize += pLayerBsInfo->iNalLengthInByte[iNalIdx];
- -- iNalIdx;
- } while (iNalIdx >= 0);
- fwrite (pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs); // write pure bit stream into file
- }
- ++ iLayer;
- }
- ++ iFrame;
- }
- }
-
- if (iFrame > 0) {
- double dElapsed = iTotal / 1e6;
- printf ("Frames: %d\nencode time: %f sec\nFPS: %f fps\n", iFrame, dElapsed, (iFrame * 1.0) / dElapsed);
- }
-
- if (NULL != pPlanes[0]) {
- delete [] pPlanes[0];
- pPlanes[0] = NULL;
- }
-ERROR_RET:
- if (pFpBs) {
- fclose (pFpBs);
- pFpBs = NULL;
- }
- if (pFpSrc) {
- fclose (pFpSrc);
- pFpSrc = NULL;
- }
- if (pSrcPic) {
- delete pSrcPic;
- pSrcPic = NULL;
- }
- return ret;
-}
-
-
-int ProcessEncodingSvcWithConfig (ISVCEncoder* pPtrEnc, int argc, char** argv) {
+int ProcessEncoding(ISVCEncoder* pPtrEnc, int argc, char** argv,bool bConfigFile) {
int iRet = 0;
if (pPtrEnc == NULL)
@@ -871,24 +627,31 @@
SFilesSet fs;
// for configuration file
CReadConfig cRdCfg;
- int iParsedNum = 2;
+ int iParsedNum = 1;
memset (&sFbi, 0, sizeof (SFrameBSInfo));
memset (&sSvcParam, 0, sizeof (SEncParamExt));
memset (&fs.sRecFileName[0][0], 0, sizeof (fs.sRecFileName));
- sSvcParam.iInputCsp = videoFormatI420; // I420 in default
- sSvcParam.sSpatialLayers[0].uiProfileIdc = PRO_BASELINE;
-// svc_cfg->sDependencyLayers[0].frext_mode = 0;
- // for configuration file
- cRdCfg.Openf (argv[1]);
- if (!cRdCfg.ExistFile()) {
- fprintf (stderr, "Specified file: %s not exist, maybe invalid path or parameter settting.\n",
- cRdCfg.GetFileName().c_str());
- iRet = 1;
- goto INSIDE_MEM_FREE;
- }
+ FillSpecificParameters (sSvcParam);
+ // if configure file exit, reading configure file firstly
+ if(bConfigFile){
+ iParsedNum = 2;
+ cRdCfg.Openf (argv[1]);
+ if (!cRdCfg.ExistFile()) {
+ fprintf (stderr, "Specified file: %s not exist, maybe invalid path or parameter settting.\n",
+ cRdCfg.GetFileName().c_str());
+ iRet = 1;
+ goto INSIDE_MEM_FREE;
+ }
+ iRet = ParseConfig (cRdCfg, pSrcPic, sSvcParam, fs);
+ if (iRet) {
+ fprintf (stderr, "parse svc parameter config file failed.\n");
+ iRet = 1;
+ goto INSIDE_MEM_FREE;
+ }
+ }
pSrcPic = new SSourcePicture;
if (pSrcPic == NULL) {
iRet = 1;
@@ -897,19 +660,29 @@
//fill default pSrcPic
pSrcPic->iColorFormat = videoFormatI420;
pSrcPic->uiTimeStamp = 0;
- iRet = ParseConfig (cRdCfg, pSrcPic, sSvcParam, fs);
- if (iRet) {
- fprintf (stderr, "parse svc parameter config file failed.\n");
- iRet = 1;
- goto INSIDE_MEM_FREE;
- }
+ // if configure file exit, reading configure file firstly
+ if(bConfigFile){
+ iParsedNum = 2;
+ cRdCfg.Openf (argv[1]);
+ if (!cRdCfg.ExistFile()) {
+ fprintf (stderr, "Specified file: %s not exist, maybe invalid path or parameter settting.\n",
+ cRdCfg.GetFileName().c_str());
+ iRet = 1;
+ goto INSIDE_MEM_FREE;
+ }
+ iRet = ParseConfig (cRdCfg, pSrcPic, sSvcParam, fs);
+ if (iRet) {
+ fprintf (stderr, "parse svc parameter config file failed.\n");
+ iRet = 1;
+ goto INSIDE_MEM_FREE;
+ }
+ }
if (ParseCommandLine (argc - iParsedNum, argv + iParsedNum, pSrcPic, sSvcParam, fs) != 0) {
printf ("parse pCommand line failed\n");
iRet = 1;
goto INSIDE_MEM_FREE;
}
-
//finish reading the configurations
iSourceWidth = pSrcPic->iPicWidth;
iSourceHeight = pSrcPic->iPicHeight;
@@ -930,6 +703,8 @@
pSrcPic->pData[2] = pSrcPic->pData[1] + (iSourceWidth * iSourceHeight >> 2);
//update sSvcParam
+ sSvcParam.iPicWidth = 0;
+ sSvcParam.iPicHeight = 0;
for (int iLayer = 0; iLayer < sSvcParam.iSpatialLayerNum; iLayer++) {
SSpatialLayerConfig* pDLayer = &sSvcParam.sSpatialLayers[iLayer];
sSvcParam.iPicWidth = WELS_MAX (sSvcParam.iPicWidth, pDLayer->iVideoWidth);
@@ -1176,7 +951,7 @@
} else {
if (!strstr (argv[1], ".cfg")) { // check configuration type (like .cfg?)
if (argc > 2) {
- iRet = ProcessEncodingSvcWithParam (pSVCEncoder, argc, argv);
+ iRet = ProcessEncoding(pSVCEncoder, argc, argv,false);
if (iRet != 0)
goto exit;
} else if (argc == 2 && ! strcmp (argv[1], "-h"))
@@ -1186,7 +961,7 @@
goto exit;
}
} else {
- iRet = ProcessEncodingSvcWithConfig (pSVCEncoder, argc, argv);
+ iRet = ProcessEncoding(pSVCEncoder, argc, argv,true);
if (iRet > 0)
goto exit;
}