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

📄 encoder.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 4 页
字号:
  insertCmd(cmdBuf, CMD_INT, 256,     "-tuneIntra",  & sp->tuneIntra);  insertCmd(cmdBuf, CMD_INT, 256,     "-tuneInter",  & sp->tuneInter);  insertCmd(cmdBuf, CMD_INT, 256,     "-tuneNonref", & sp->tuneNonref);  insertCmd(cmdBuf, CMD_INT, 20,      "-level",      & sp->level);  insertCmd(cmdBuf, CMD_INT, 16,      "-range",      & sp->range);  insertCmd(cmdBuf, CMD_INT, 1,       "-rangeMod",   & sp->rangeMod);  insertCmd(cmdBuf, CMD_INT, 0,       "-prof",       & sp->profile);#ifndef DISABLE_RDO  insertCmd(cmdBuf, CMD_INT, 1,       "-rdo",        & sp->rdo);#endif  insertCmd(cmdBuf, CMD_INT, 0,       "-filtermode", & sp->filterMode);  insertCmd(cmdBuf, CMD_INT, 0,       "-br",         & sp->brcBitRate);  insertCmd(cmdBuf, CMD_INT, 0,       "-brcBufSize", & sp->brcBufSize);  insertCmd(cmdBuf, CMD_FLAG, 0,      "-brcuseSEI",  & sp->useSEIMessages);  insertCmd(cmdBuf, CMD_FLAG, 0,      "-brcdisableMBLevel",&sp->brcdisableMBLevel);  insertCmd(cmdBuf, CMD_INT, 1,       "-brcFrameSkipsEnabled",  & sp->frameSkipEnabled);  insertCmd(cmdBuf, CMD_INT, 0,        "-brcQPStart", & sp->qpStart);  insertCmd(cmdBuf, CMD_INT, 0,       "-brcIgnoreIDRBits",  & sp->ignoreIDRBits);  insertCmd(cmdBuf, CMD_INT, 1,       "-sgmCount",   & sp->sgmCount);  insertCmd(cmdBuf, CMD_INT, 0,       "-sgmType",    & sp->sgmType);  insertCmd(cmdBuf, CMD_INT, 0,       "-alpha",      & sp->alphaOffset);  insertCmd(cmdBuf, CMD_INT, 0,       "-beta",       & sp->betaOffset);  insertCmd(cmdBuf, CMD_INT, 0,       "-qindex",     & sp->chromaQpIdx);  insertCmd(cmdBuf, CMD_INT, 1,       "-rframes",    & sp->maxNumRefFrms);  insertCmd(cmdBuf, CMD_INT, 0,       "-mbsperslice", & sp->nMbsPerSlice);    insertCmd(cmdBuf, CMD_INT, 0,       "-bytesperslice", & sp->nBytesPerSlice);    insertCmd(cmdBuf, CMD_INT, 0,       "-RIR",        & sp->nRandomIntraRefresh);  insertCmd(cmdBuf, CMD_INT, 0,       "-maxFrameNum",& sp->log2_max_frame_num_minus4);  insertCmd(cmdBuf, CMD_INT, 0,       "-scIntra",    & sp->scIntra);  insertCmd(cmdBuf, CMD_INT, 0,       "-entropy",    & sp->entropyEncoder);  // only set a flag, does not need additional parameter on command line  insertCmd(cmdBuf, CMD_FLAG, 0,      "-constipred",& sp->constIpred);  insertCmd(cmdBuf, CMD_FLAG, 0,      "-mfield",    & sp->makeMotField);  insertCmd(cmdBuf, CMD_INT, 0,       "-PLR",     & sp->plr);  insertCmd(cmdBuf, CMD_FLAG, 0,      "-AIR",        & (sp->sIntraRefresh));  // ternimate the list  cmdBuf->current->next = 0;  cmdBuf->current = cmdBuf->head->next;  /*  * Set default file and sequence parameters  */  // make these strings of zero length,   // the length will be used to determine whether string has been changed  up->origFileName[0]  = 0;  up->outFileName[0]   = 0;  up->recoFileName[0]  = 0;  up->cumuFileName[0]  = 0;  up->seqFormat        = SEPARATE_YUV_FILES;  up->recoFormat       = SEPARATE_YUV_FILES;    up->fInfo            = 0;  sp->origFpsTimes1000 = 30000;  sp->modeFlags        = 0x3f;  sp->qpInter          = 26;///// LOW_COMPLEX_PROF3  sp->low_complex_prof3=0;//////  for (i = 0; i < 4; i ++)    sp->cropOffsets[i] = 0;  return cmdBuf;}// the config file can not have more than 256 commands#define MAX_CFG_COMMANDS      256#define MAX_CFG_LINE_WIDTH    256/* * readOneCfgLine: * * Parameters: *      input                 Input config file *      oneString             Buffer to store the line *      maxStringLen          Max string length allowed * * Function: *      Read one line from the config file.  * * Returns: *      Length of the line. */int readOneCfgLine(FILE *input,                    char *oneString,                   int  maxStringLen){  int oneCh;  int strLen;  strLen = 0;  do  {    if ((oneCh = fgetc(input)) < 0)      break;        oneString[strLen ++] = (char) oneCh;  } while ((oneCh != '\n') && (strLen < maxStringLen - 1));  oneString[strLen] = 0;    // to terminate the string  return strLen;}/* * formatLine: * * Parameters: *      oneString             Config file that contains parameter strings * * Function: *      Format the string to make it easier to parse.  * * Returns: *      Length of the formatted string. */int formatLine(char *oneString){  int stringLen, i;  stringLen = (int) strlen(oneString);  // find the first # sign, which tells the position where comments start  i = 0;  while ((i < stringLen) && (oneString[i] != '#'))    i ++;  // truncate the string here  oneString[i] = 0;  stringLen = i;  // remove ending blank  while ((stringLen > 0) && (oneString[stringLen - 1] <= ' '))    stringLen --;  oneString[stringLen] = 0;  // remove leading blank  i = 0;  while ((i < stringLen) && (oneString[i] <= ' '))    i ++;  stringLen -= i;  if (stringLen > 0)    strcpy(oneString, oneString + i);    return stringLen;}/* * readConfigFile: * * Parameters: *      cfgFile               Config file that contains parameter strings *      argv                  Buffer where the parameter strings are stored *      maxCfgCmds            Maximal number of strings that are allowed * * Function: *      Read the parameter strings from a config file to an array.  * * Returns: *      Actual number of parameter strings read from the config file. */int readConfigFile(FILE *cfgFile,                    char **argv,                    int  maxCfgCmds){  int  argc;  char oneLine[MAX_CFG_LINE_WIDTH];  argc = 0;  while (readOneCfgLine(cfgFile, oneLine, MAX_CFG_LINE_WIDTH))  {    int lineLen;    if ((lineLen = formatLine(oneLine)) > 0)    {      char token[128];      char *linePtr;      linePtr = oneLine;      while ((sscanf(linePtr, "%s", token) > 0) && (argc < maxCfgCmds))      {        argv[argc] = (char *) malloc(128);        strcpy(argv[argc], token);        linePtr += strlen(token);        while ((linePtr[0] <= ' ') && (linePtr < (oneLine + lineLen)))          linePtr ++;        argc ++;      }    }  }  return argc;}/* * calculateMinPocBits: * * Parameters: *      frmSkip               Number of frames skipped in the input clip *      numNonref             Number of non-reference frames inserted * * Function: *      Calculate the minimal number of bits needed to store LSBs of POC *      (Picture Order Count).  * * Returns: *      0 error *      1 ok */int calculateMinPocBits(int frmSkip,                         int numNonref){  int maxPocMbs, minPocBits;  // maxPocMbs should be larger than twice of maximal increase in POC  maxPocMbs = 2 * ((frmSkip + 1) * (numNonref + 1) + 1);  minPocBits = 0;  while (maxPocMbs)  {    maxPocMbs >>= 1;    minPocBits ++;  }  return minPocBits;}/* * parseArg: * * Parameters: *      sp                    Coding parameters, used in this module & encoder * * Function: *      Check the cropping parameters. Perform correction if any parameters  *      are illegal. * * Returns: *      0 error *      1 ok */void validateCroppingOffsets(avceOpenParams_s *sp){  int i;  for (i = 0; i < 4; i ++)    sp->cropOffsets[i] = (sp->cropOffsets[i] >> 1) << 1;  if ((sp->cropOffsets[0] < 0) || (sp->cropOffsets[1] < 0) ||    (sp->cropOffsets[2] < 0) || (sp->cropOffsets[3] < 0) ||    ((sp->cropOffsets[0] + sp->cropOffsets[1]) > sp->picWidth) ||    ((sp->cropOffsets[2] + sp->cropOffsets[3]) > sp->picHeight))  {    for (i = 0; i < 4; i ++)      sp->cropOffsets[i] = 0;  }}// make a the smallest number larger or equal to a, and multiple of b#define ROUND_UP(a, b)    ((((a) + (b) - 1)/(b)) * (b))/* * parseArg: * * Parameters: *      cmdBuf                Buffer for storing the parsed commands *      argc                  Number of the input strings *      argv                  Array contains the input strings *      param                 User parameters, only used in this module *      seqParam              Coding parameters, used in this module & encoder * * Function: *      Parse encoder parameters * * Returns: *      0 error *      1 ok */static int parseArg(cmdBuf_s         *cmdBuf,                    int              argc,                     char             **argv,                     userParam_s      *param,                    avceOpenParams_s *seqParam){  int   i;  float origFps;    /*  * Read all parameters  */  for (i = 1; i < argc; i++) {    if (strcmp(argv[i], "-in") == 0) {      if (++i == argc) {        return 0;      }      param->seqFormat = SEPARATE_YUV_FILES;      strcpy(param->origFileName, argv[i]);    }    else if (strcmp(argv[i], "-inyuv") == 0) {      if (++i == argc) {        return 0;      }      param->seqFormat = COMBINED_YUV_FILE;      strcpy(param->origFileName, argv[i]);    }    else if (strcmp(argv[i], "-reco") == 0) {      if (++i == argc) {        return 0;      }      param->recoFormat = SEPARATE_YUV_FILES;      strcpy(param->recoFileName, argv[i]);    }    else if (strcmp(argv[i], "-recoyuv") == 0) {      if (++i == argc) {        return 0;      }      param->recoFormat = COMBINED_YUV_FILE;      strcpy(param->recoFileName, argv[i]);    }    else if (strcmp(argv[i], "-qcif") == 0) {      seqParam->picWidth  = 176;      seqParam->picHeight = 144;    }    else if (strcmp(argv[i], "-cif") == 0) {      seqParam->picWidth  = 352;      seqParam->picHeight = 288;    }    else if (strcmp(argv[i], "-origfps") == 0) {      i++;      if (i == argc || (sscanf(argv[i], "%f", &origFps) != 1)) {        return 0;      }      seqParam->origFpsTimes1000 = (int)(1000*origFps);    }    else if (strcmp(argv[i], "-modes") == 0) {      i++;      if (i == argc || (seqParam->modeFlags = parseModes(argv[i])) < 0) {        return 0;      }    }    else if (strcmp(argv[i], "-sgmParams") == 0) {      i ++;      // read up to 8 parameters, and move to next switch      seqParam->numSgmParams = 0;      while (i < argc) {        if (argv[i][0] == '-')        {          // see the next switch          i --;   // will be incremented later          break;        }                if (seqParam->numSgmParams < MAX_SLICE_PARAMS)        {          seqParam->sgmParams[seqParam->numSgmParams] = atoi(argv[i]);          seqParam->numSgmParams ++;        }        i ++;      }    }    else if (strcmp(argv[i], "-crop") == 0) {      int numParams;      i ++;      // read up to 8 parameters, and move to next switch      numParams = 0;      while (i < argc) {        if (argv[i][0] == '-')        {          // see the next switch          i --;   // will be incremented later          break;        }                if (seqParam->numSgmParams < 4)        {          seqParam->cropOffsets[numParams] = atoi(argv[i]);          numParams ++;        }        i ++;      }    }    else if (strcmp(argv[i], "-info") == 0) {             param->fInfo = 1;        }    else {      // have a regular check      cmdBuf->current = cmdBuf->head->next;      do      {        if (strcmp(argv[i], cmdBuf->current->id) == 0)         {          if (cmdBuf->current->type == CMD_FLAG)            * (int *) cmdBuf->current->data = 1;          else          {            i ++;            if (i == argc)              return 0;            if (cmdBuf->current->type == CMD_STR)              strcpy((char *) cmdBuf->current->data, argv[i]);            else              // must be CMD_INT, read the next token as an integer              if (sscanf(argv[i], "%d", cmdBuf->current->data) != 1)                return 0;          }          // to signal a command is received          cmdBuf->current->flag = 1;          // no further search          break;        }        else          cmdBuf->current = cmdBuf->current->next;      } while (cmdBuf->current != 0);      // ternimate the process if an illegal command is encountered      if (cmdBuf->current == 0)      {        fprintf(stderr, "Command ""%s"" is not defined!\n", argv[i]);        return 0;      }    }  }  // seqParam->qpInter is only used in setting pic_init_qp_minus26 in PPS  seqParam->qpInter = param->qpInter;  // log2_max_pic_order_cnt_lsb_minus4 depends on numSkipFrms and numNonref  seqParam->log2_max_pic_order_cnt_lsb_minus4 =     calculateMinPocBits(param->frmSkip, param->numNonref) - 4;  if (seqParam->log2_max_pic_order_cnt_lsb_minus4 < 0)    seqParam->log2_max_pic_order_cnt_lsb_minus4 = 0;  if (param->qpInter2 < 0)    param->qpInter2 = param->qpInter;  if (param->qpNonref < 0)    param->qpNonref = param->qpInter;  if ((param->idrFreq > 0) && (param->idrFreq < param->intraFreq))    param->idrFreq = param->intraFreq;  // validate the cropping offsets  validateCroppingOffsets(seqParam);  // the constraint is that if numLongs + numShorts > 0, numShorts > 0  if (seqParam->maxNumRefFrms == 1)    param->ltrIdr = 0;  if ((seqParam->picWidth & 0x0F) != 0) {    fprintf(stderr, "Error: picture width must be mutiple of 16\n");    return 0;  }  if ((seqParam->picHeight & 0x0F) != 0) {    fprintf(stderr, "Error: picture height must be mutiple of 16\n");    return 0;  }  if (strlen(param->origFileName) == 0) {    fprintf(stderr, "Source file required\n\n");    return 0;  }  if (strlen(param->outFileName) == 0) {

⌨️ 快捷键说明

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