[x265] [PATCH] common: parse the command line arguments and set the Input parameters to the encoder

Gopu Govindaswamy gopu at multicorewareinc.com
Wed Oct 16 08:13:42 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1381904011 -19800
# Node ID de3b1f54873c23189284f63f471d4c95440bacc6
# Parent  09c0e0209d84313a49a15ac3806f03223a1546de
common: parse the command line arguments and set the Input parameters to the encoder

diff -r 09c0e0209d84 -r de3b1f54873c source/common/common.cpp
--- a/source/common/common.cpp	Wed Oct 16 10:11:23 2013 +0530
+++ b/source/common/common.cpp	Wed Oct 16 11:43:31 2013 +0530
@@ -420,3 +420,149 @@
     fprintf(stderr, "\n");
     fflush(stderr);
 }
+
+extern "C"
+int x265_param_parse(x265_param_t *p, const char *name, const char *value)
+{
+    int berror = 0;
+    int valuewasnull;
+
+    /* Enable or Disable - default is Enable */
+    int bvalue = 1;
+
+    if (!name)
+        return X265_PARAM_BAD_NAME;
+
+    if (!value)
+        value = "1";
+
+    if (!strncmp(name, "no-", 3))
+        bvalue = 0; 
+    else
+        bvalue = 1;
+
+    valuewasnull = !value;
+
+#define OPT(STR) else if (!strcmp( name, STR))
+    if (0);
+    OPT("fps")
+        p->frameRate = atoi(value);
+    OPT("threads")
+        p->poolNumThreads = atoi(value);
+    OPT("frame-threads")
+        p->frameNumThreads = atoi(value);
+    OPT("log")
+        p->logLevel = atoi(value);
+    OPT("no-wpp")
+        p->bEnableWavefront = bvalue;
+    OPT("wpp")
+        p->bEnableWavefront = bvalue;
+    OPT("ctu")
+        p->maxCUSize =(uint32_t) atoi(value);
+    OPT("tu-intra-depth")
+        p->tuQTMaxIntraDepth = (uint32_t) atoi(value);
+    OPT("tu-inter-depth")
+        p->tuQTMaxInterDepth =(uint32_t) atoi(value);
+    OPT("me")
+        p->searchMethod = atoi(value);
+    OPT("subme")
+        p->subpelRefine = atoi(value);
+    OPT("merange") 
+        p->searchRange = atoi(value);
+    OPT("no-rect")
+        p->bEnableRectInter = bvalue;
+    OPT("rect")
+        p->bEnableRectInter = bvalue;
+    OPT("no-amp")
+        p->bEnableAMP = bvalue;
+    OPT("amp")
+        p->bEnableAMP = bvalue;
+    OPT("max-merge")
+        p->maxNumMergeCand = (uint32_t)atoi(value);
+    OPT("no-early-skip")
+        p->bEnableEarlySkip = bvalue;
+    OPT("early-skip")
+        p->bEnableEarlySkip = bvalue;
+    OPT("no-fast-cbf")
+        p->bEnableCbfFastMode = bvalue;
+    OPT("fast-cbf")
+        p->bEnableCbfFastMode = bvalue;
+    OPT("rdpenalty")
+        p->rdPenalty = atoi(value);
+    OPT("no-tskip")
+        p->bEnableTransformSkip = bvalue;
+    OPT("tskip")
+        p->bEnableTransformSkip = bvalue;
+    OPT("no-tskip-fast")
+        p->bEnableTSkipFast = bvalue;
+    OPT("tskip-fast")
+        p->bEnableTSkipFast = bvalue;
+    OPT("no-strong-intra-smoothing")
+        p->bEnableStrongIntraSmoothing = bvalue;
+    OPT("strong-intra-smoothing")
+        p->bEnableStrongIntraSmoothing = bvalue;
+    OPT("no-constrained-intra")
+        p->bEnableConstrainedIntra = bvalue;
+    OPT("constrained-intra")
+        p->bEnableConstrainedIntra = bvalue;
+    OPT("refresh")
+        p->decodingRefreshType = atoi(value);
+    OPT("keyint")
+        p->keyframeMax = atoi(value);
+    OPT("rc-lookahead")
+        p->lookaheadDepth = atoi(value);
+    OPT("bframes")
+        p->bframes = atoi(value);
+    OPT("bframe-bias")
+        p->bFrameBias = atoi(value);
+    OPT("b-adapt")
+        p->bFrameAdaptive = atoi(value);
+    OPT("ref")
+        p->maxNumReferences = atoi(value);
+    OPT("no-weightp")
+        p->bEnableWeightedPred = bvalue;
+    OPT("weightp")
+        p->bEnableWeightedPred = bvalue;
+    OPT("bitrate")
+        p->rc.bitrate = atoi(value);
+    OPT("qp")
+        p->rc.qp = atoi(value);
+    OPT("cbqpoffs")
+        p->cbQpOffset = atoi(value);
+    OPT("crqpoffs")
+        p->crQpOffset = atoi(value);
+    OPT("rd")
+        p->bRDLevel = atoi(value);
+    OPT("no-signhide")
+        p->bEnableSignHiding = bvalue;
+    OPT("signhide")
+        p->bEnableSignHiding = bvalue;
+    OPT("no-lft")
+        p->bEnableLoopFilter = bvalue;
+    OPT("lft")
+        p->bEnableLoopFilter = bvalue;
+    OPT("no-sao")
+        p->bEnableSAO = bvalue;
+    OPT("sao")
+        p->bEnableSAO = bvalue;
+    OPT("sao-lcu-bounds")
+        p->saoLcuBoundary = atoi(value);
+    OPT("sao-lcu-opt")
+        p->saoLcuBasedOptimization = atoi(value);
+    OPT("no-ssim")
+        p->bEnableSsim = bvalue;
+    OPT("ssim")
+        p->bEnableSsim = bvalue;
+    OPT("no-psnr")
+        p->bEnablePsnr = atoi(value);
+    OPT("psnr")
+        p->bEnablePsnr = bvalue;
+    OPT("hash")
+        p->decodedPictureHashSEI = atoi(value);
+    else
+        return X265_PARAM_BAD_NAME;
+#undef OPT
+
+    berror |= valuewasnull;
+    return berror ? X265_PARAM_BAD_VALUE : 0;
+}
diff -r 09c0e0209d84 -r de3b1f54873c source/x265.cpp
--- a/source/x265.cpp	Wed Oct 16 10:11:23 2013 +0530
+++ b/source/x265.cpp	Wed Oct 16 11:43:31 2013 +0530
@@ -290,6 +290,7 @@
 
     bool parse(int argc, char **argv, x265_param_t* param)
     {
+        int berror = 0;
         int help = 0;
         int cpuid = 0;
         uint32_t inputBitDepth = 8;
@@ -345,16 +346,30 @@
                     log(X265_LOG_WARNING, "short option '%c' unrecognized\n", c);
                     return true;
                 }
-#define HELP(message)
-#define STROPT(longname, var, argreq, flag, helptext) \
-    else if (!strcmp(long_options[long_options_index].name, longname)) \
-        (var) = optarg;
-#define OPT(longname, var, argreq, flag, helptext) \
-    else if (!strcmp(long_options[long_options_index].name, longname)) \
-        (var) = (argreq == no_argument) ? (strncmp(longname, "no-", 3) ? 1 : 0) : atoi(optarg);
-#include "x265opts.h"
+#define OPT(longname) \
+    else if (!strcmp(long_options[long_options_index].name, longname))
+
+            if (0);
+                OPT("frames") this->framesToBeEncoded = (uint32_t)atoi(optarg);
+                OPT("no-progress") this->bProgress = (!strncmp(long_options[long_options_index].name, "no-", 3) ? 0 : 1);
+                OPT("frame-skip") this->frameSkip = (uint32_t)atoi(optarg);
+                OPT("csv") csvfn = optarg;
+                OPT("output") bitstreamfn = optarg;
+                OPT("input") inputfn = optarg;
+                OPT("recon") reconfn = optarg;
+                OPT("input-depth") inputBitDepth = (uint32_t)atoi(optarg);
+                OPT("recon-depth") outputBitDepth = (uint32_t)atoi(optarg);
+                OPT("input-res") inputRes = optarg;
+            else
+                berror |= x265_param_parse(param, long_options[long_options_index].name, optarg);
+
+            if (berror)
+            {
+                const char *name = long_options_index > 0 ? long_options[long_options_index].name : argv[optind-2];
+                log(X265_LOG_ERROR, "invalid argument: %s = %s\n", name, optarg);
+                return true;
+            }
 #undef OPT
-#undef STROPT
             }
         }
 
diff -r 09c0e0209d84 -r de3b1f54873c source/x265.def.in
--- a/source/x265.def.in	Wed Oct 16 10:11:23 2013 +0530
+++ b/source/x265.def.in	Wed Oct 16 11:43:31 2013 +0530
@@ -2,6 +2,7 @@
 x265_encoder_open_${X265_BUILD}
 x265_setup_primitives
 x265_param_default
+x265_param_parse
 x265_picture_init
 x265_param_apply_profile
 x265_max_bit_depth
diff -r 09c0e0209d84 -r de3b1f54873c source/x265.h
--- a/source/x265.h	Wed Oct 16 10:11:23 2013 +0530
+++ b/source/x265.h	Wed Oct 16 11:43:31 2013 +0530
@@ -191,6 +191,8 @@
 static const char * const x265_motion_est_names[] = { "dia", "hex", "umh", "star", "full", 0 };
 
 #define X265_MAX_SUBPEL_LEVEL   7
+#define X265_PARAM_BAD_NAME -1
+#define X265_PARAM_BAD_VALUE -2
 
 /* Log level */
 #define X265_LOG_NONE          (-1)
@@ -410,6 +412,10 @@
  *      close an encoder handler.  Optionally return the global PSNR value (6 * psnrY + psnrU + psnrV) / 8 */
 void x265_encoder_close(x265_t *, double *globalPsnr);
 
+/* x265_param_parse:
+ *     parse the command line arguments and set the Input parameters to the encoder */
+int x265_param_parse( x265_param_t *p, const char *name, const char *value);
+
 /***
  * Release library static allocations
  */


More information about the x265-devel mailing list