[x265] [PATCH] cli: allow --output-depth to select output|internal bit depth
Steve Borho
steve at borho.org
Mon May 11 15:50:57 CEST 2015
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1431352241 18000
# Mon May 11 08:50:41 2015 -0500
# Branch stable
# Node ID 11a86f89911c43cda4bbea2bd2383aadf5df4252
# Parent c7ac09d16802becbb13167d8fc497ace2101ad86
cli: allow --output-depth to select output|internal bit depth
diff -r c7ac09d16802 -r 11a86f89911c doc/reST/cli.rst
--- a/doc/reST/cli.rst Mon May 11 08:15:56 2015 -0500
+++ b/doc/reST/cli.rst Mon May 11 08:50:41 2015 -0500
@@ -419,6 +419,16 @@
**CLI ONLY**
+.. opton:: --output-depth, -D 8|10
+
+ Bitdepth of output HEVC bitstream, which is also the internal bit
+ depth of the encoder. If the requested bit depth is not the bit
+ depth of the linked libx265, it will attempt to bind libx265_main
+ for an 8bit encoder, or libx265_main10 for a 10bit encoder, with the
+ same API version as the linked libx265.
+
+ **CLI ONLY**
+
Profile, Level, Tier
====================
diff -r c7ac09d16802 -r 11a86f89911c source/x265.cpp
--- a/source/x265.cpp Mon May 11 08:15:56 2015 -0500
+++ b/source/x265.cpp Mon May 11 08:50:41 2015 -0500
@@ -75,6 +75,8 @@
OutputFile* output;
FILE* qpfile;
const char* reconPlayCmd;
+ const x265_api* api;
+ x265_param* param;
bool bProgress;
bool bForceY4m;
bool bDither;
@@ -92,6 +94,10 @@
input = NULL;
recon = NULL;
output = NULL;
+ qpfile = NULL;
+ reconPlayCmd = NULL;
+ api = NULL;
+ param = NULL;
framesToBeEncoded = seek = 0;
totalbytes = 0;
bProgress = true;
@@ -99,15 +105,12 @@
startTime = x265_mdate();
prevUpdateTime = 0;
bDither = false;
- qpfile = NULL;
- reconPlayCmd = NULL;
}
void destroy();
- void printStatus(uint32_t frameNum, x265_param *param);
- bool parse(int argc, char **argv, x265_param* param);
+ void printStatus(uint32_t frameNum);
+ bool parse(int argc, char **argv);
bool parseQPFile(x265_picture &pic_org);
- bool validateFanout(x265_param*);
};
void CLIOptions::destroy()
@@ -126,7 +129,7 @@
output = NULL;
}
-void CLIOptions::printStatus(uint32_t frameNum, x265_param *param)
+void CLIOptions::printStatus(uint32_t frameNum)
{
char buf[200];
int64_t time = x265_mdate();
@@ -153,11 +156,12 @@
prevUpdateTime = time;
}
-bool CLIOptions::parse(int argc, char **argv, x265_param* param)
+bool CLIOptions::parse(int argc, char **argv)
{
bool bError = 0;
int help = 0;
int inputBitDepth = 8;
+ int outputBitDepth = 0;
int reconFileBitDepth = 0;
const char *inputfn = NULL;
const char *reconfn = NULL;
@@ -178,15 +182,31 @@
int c = getopt_long(argc, argv, short_options, long_options, NULL);
if (c == -1)
break;
- if (c == 'p')
+ else if (c == 'p')
preset = optarg;
- if (c == 't')
+ else if (c == 't')
tune = optarg;
+ else if (c == 'D')
+ outputBitDepth = atoi(optarg);
else if (c == '?')
showHelp(param);
}
- if (x265_param_default_preset(param, preset, tune) < 0)
+ api = x265_api_get(outputBitDepth);
+ if (!api)
+ {
+ x265_log(NULL, X265_LOG_WARNING, "falling back to default bit-depth\n");
+ api = x265_api_get(0);
+ }
+
+ param = api->param_alloc();
+ if (!param)
+ {
+ x265_log(NULL, X265_LOG_ERROR, "param alloc failed\n");
+ return true;
+ }
+
+ if (api->param_default_preset(param, preset, tune) < 0)
{
x265_log(NULL, X265_LOG_ERROR, "preset or tune unrecognized\n");
return true;
@@ -255,6 +275,7 @@
OPT("profile") profile = optarg; /* handled last */
OPT("preset") /* handled above */;
OPT("tune") /* handled above */;
+ OPT("output-depth") /* handled above */;
OPT("recon-y4m-exec") reconPlayCmd = optarg;
OPT("qpfile")
{
@@ -266,7 +287,7 @@
}
}
else
- bError |= !!x265_param_parse(param, long_options[long_options_index].name, optarg);
+ bError |= !!api->param_parse(param, long_options[long_options_index].name, optarg);
if (bError)
{
@@ -297,9 +318,9 @@
return true;
}
- if (param->internalBitDepth != x265_max_bit_depth)
+ if (param->internalBitDepth != api->max_bit_depth)
{
- x265_log(param, X265_LOG_ERROR, "Only bit depths of %d are supported in this build\n", x265_max_bit_depth);
+ x265_log(param, X265_LOG_ERROR, "Only bit depths of %d are supported in this build\n", api->max_bit_depth);
return true;
}
@@ -351,7 +372,7 @@
info.timebaseNum = param->fpsDenom;
info.timebaseDenom = param->fpsNum;
- if (x265_param_apply_profile(param, profile))
+ if (api->param_apply_profile(param, profile))
return true;
if (param->logLevel >= X265_LOG_INFO)
@@ -458,20 +479,20 @@
GetConsoleTitle(orgConsoleTitle, CONSOLE_TITLE_SIZE);
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
- const x265_api* api = x265_api_get(0); /* Use 0 to indicate native bit depth of the linked libx265 */
- /* x265_api_get(0) is guaranteed to return a non-null pointer */
-
ReconPlay* reconPlay = NULL;
- x265_param* param = api->param_alloc();
CLIOptions cliopt;
- if (cliopt.parse(argc, argv, param))
+ if (cliopt.parse(argc, argv))
{
cliopt.destroy();
- api->param_free(param);
+ if (cliopt.api)
+ cliopt.api->param_free(cliopt.param);
exit(1);
}
+ x265_param* param = cliopt.param;
+ const x265_api* api = cliopt.api;
+
/* This allows muxers to modify bitstream format */
cliopt.output->setParam(param);
@@ -593,7 +614,7 @@
}
}
- cliopt.printStatus(outFrameCount, param);
+ cliopt.printStatus(outFrameCount);
}
/* Flush the encoder */
@@ -623,7 +644,7 @@
}
}
- cliopt.printStatus(outFrameCount, param);
+ cliopt.printStatus(outFrameCount);
if (!numEncoded)
break;
diff -r c7ac09d16802 -r 11a86f89911c source/x265cli.h
--- a/source/x265cli.h Mon May 11 08:15:56 2015 -0500
+++ b/source/x265cli.h Mon May 11 08:50:41 2015 -0500
@@ -30,7 +30,7 @@
namespace x265 {
#endif
-static const char short_options[] = "o:P:p:f:F:r:I:i:b:s:t:q:m:hwV?";
+static const char short_options[] = "o:D:P:p:f:F:r:I:i:b:s:t:q:m:hwV?";
static const struct option long_options[] =
{
{ "help", no_argument, NULL, 'h' },
@@ -59,6 +59,7 @@
{ "y4m", no_argument, NULL, 0 },
{ "no-progress", no_argument, NULL, 0 },
{ "output", required_argument, NULL, 'o' },
+ { "output-depth", required_argument, NULL, 'D' },
{ "input", required_argument, NULL, 0 },
{ "input-depth", required_argument, NULL, 0 },
{ "input-res", required_argument, NULL, 0 },
@@ -242,6 +243,7 @@
H0("-V/--version Show version info and exit\n");
H0("\nOutput Options:\n");
H0("-o/--output <filename> Bitstream output file name\n");
+ H0("-D/--output-depth 8|10 Output bit depth (also internal bit depth). Default %d\n", param->internalBitDepth);
H0(" --log-level <string> Logging level: none error warning info debug full. Default %s\n", x265::logLevelNames[param->logLevel + 1]);
H0(" --no-progress Disable CLI progress reports\n");
H0(" --[no-]cu-stats Enable logging stats about distribution of cu across all modes. Default %s\n",OPT(param->bLogCuStats));
More information about the x265-devel
mailing list