Adds highbitdepth support to svc examples
Change-Id: I59946642cb5c370726da33f4448a3deaba7d3f11
This commit is contained in:
parent
d32a0c29a2
commit
4bad0e6f12
@ -61,12 +61,30 @@ static const arg_def_t min_bitrate_arg =
|
|||||||
static const arg_def_t max_bitrate_arg =
|
static const arg_def_t max_bitrate_arg =
|
||||||
ARG_DEF(NULL, "max-bitrate", 1, "Maximum bitrate");
|
ARG_DEF(NULL, "max-bitrate", 1, "Maximum bitrate");
|
||||||
|
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
static const struct arg_enum_list bitdepth_enum[] = {
|
||||||
|
{"8", VPX_BITS_8},
|
||||||
|
{"10", VPX_BITS_10},
|
||||||
|
{"12", VPX_BITS_12},
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const arg_def_t bitdepth_arg =
|
||||||
|
ARG_DEF_ENUM("d", "bit-depth", 1, "Bit depth for codec 8, 10 or 12. ",
|
||||||
|
bitdepth_enum);
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
|
||||||
|
|
||||||
static const arg_def_t *svc_args[] = {
|
static const arg_def_t *svc_args[] = {
|
||||||
&frames_arg, &width_arg, &height_arg,
|
&frames_arg, &width_arg, &height_arg,
|
||||||
&timebase_arg, &bitrate_arg, &skip_frames_arg, &spatial_layers_arg,
|
&timebase_arg, &bitrate_arg, &skip_frames_arg, &spatial_layers_arg,
|
||||||
&kf_dist_arg, &scale_factors_arg, &passes_arg, &pass_arg,
|
&kf_dist_arg, &scale_factors_arg, &passes_arg, &pass_arg,
|
||||||
&fpf_name_arg, &min_q_arg, &max_q_arg, &min_bitrate_arg,
|
&fpf_name_arg, &min_q_arg, &max_q_arg, &min_bitrate_arg,
|
||||||
&max_bitrate_arg, &temporal_layers_arg, NULL
|
&max_bitrate_arg, &temporal_layers_arg,
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
&bitdepth_arg,
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t default_frames_to_skip = 0;
|
static const uint32_t default_frames_to_skip = 0;
|
||||||
@ -189,6 +207,27 @@ static void parse_command_line(int argc, const char **argv_,
|
|||||||
min_bitrate = arg_parse_uint(&arg);
|
min_bitrate = arg_parse_uint(&arg);
|
||||||
} else if (arg_match(&arg, &max_bitrate_arg, argi)) {
|
} else if (arg_match(&arg, &max_bitrate_arg, argi)) {
|
||||||
max_bitrate = arg_parse_uint(&arg);
|
max_bitrate = arg_parse_uint(&arg);
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
} else if (arg_match(&arg, &bitdepth_arg, argi)) {
|
||||||
|
enc_cfg->g_bit_depth = arg_parse_enum(&arg);
|
||||||
|
switch (enc_cfg->g_bit_depth) {
|
||||||
|
case VPX_BITS_8:
|
||||||
|
enc_cfg->g_input_bit_depth = 8;
|
||||||
|
enc_cfg->g_profile = 0;
|
||||||
|
break;
|
||||||
|
case VPX_BITS_10:
|
||||||
|
enc_cfg->g_input_bit_depth = 10;
|
||||||
|
enc_cfg->g_profile = 2;
|
||||||
|
break;
|
||||||
|
case VPX_BITS_12:
|
||||||
|
enc_cfg->g_input_bit_depth = 12;
|
||||||
|
enc_cfg->g_profile = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("Error: Invalid bit depth selected (%d)\n", enc_cfg->g_bit_depth);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
} else {
|
} else {
|
||||||
++argj;
|
++argj;
|
||||||
}
|
}
|
||||||
@ -291,8 +330,17 @@ int main(int argc, const char **argv) {
|
|||||||
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
|
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
|
||||||
|
|
||||||
// Allocate image buffer
|
// Allocate image buffer
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, enc_cfg.g_w, enc_cfg.g_h, 32))
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
if (!vpx_img_alloc(&raw, enc_cfg.g_input_bit_depth == 8 ?
|
||||||
|
VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
|
||||||
|
enc_cfg.g_w, enc_cfg.g_h, 32)) {
|
||||||
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
|
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, enc_cfg.g_w, enc_cfg.g_h, 32)) {
|
||||||
|
die("Failed to allocate image %dx%d\n", enc_cfg.g_w, enc_cfg.g_h);
|
||||||
|
}
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
|
||||||
if (!(infile = fopen(app_input.input_filename, "rb")))
|
if (!(infile = fopen(app_input.input_filename, "rb")))
|
||||||
die("Failed to open %s for reading\n", app_input.input_filename);
|
die("Failed to open %s for reading\n", app_input.input_filename);
|
||||||
|
@ -461,13 +461,27 @@ int main(int argc, char **argv) {
|
|||||||
FILE *infile = NULL;
|
FILE *infile = NULL;
|
||||||
struct RateControlMetrics rc;
|
struct RateControlMetrics rc;
|
||||||
int64_t cx_time = 0;
|
int64_t cx_time = 0;
|
||||||
|
const int min_args_base = 11;
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
vpx_bit_depth_t bit_depth = VPX_BITS_8;
|
||||||
|
int input_bit_depth = 8;
|
||||||
|
const int min_args = min_args_base + 1;
|
||||||
|
#else
|
||||||
|
const int min_args = min_args_base;
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
// Check usage and arguments.
|
// Check usage and arguments.
|
||||||
if (argc < 11) {
|
if (argc < min_args) {
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
|
||||||
|
"<rate_num> <rate_den> <speed> <frame_drop_threshold> <mode> "
|
||||||
|
"<Rate_0> ... <Rate_nlayers-1> <bit-depth> \n", argv[0]);
|
||||||
|
#else
|
||||||
die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
|
die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
|
||||||
"<rate_num> <rate_den> <speed> <frame_drop_threshold> <mode> "
|
"<rate_num> <rate_den> <speed> <frame_drop_threshold> <mode> "
|
||||||
"<Rate_0> ... <Rate_nlayers-1> \n", argv[0]);
|
"<Rate_0> ... <Rate_nlayers-1> \n", argv[0]);
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder = get_vpx_encoder_by_name(argv[3]);
|
encoder = get_vpx_encoder_by_name(argv[3]);
|
||||||
@ -487,13 +501,38 @@ int main(int argc, char **argv) {
|
|||||||
die("Invalid layering mode (0..12) %s", argv[10]);
|
die("Invalid layering mode (0..12) %s", argv[10]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 11 + mode_to_num_layers[layering_mode]) {
|
if (argc != min_args + mode_to_num_layers[layering_mode]) {
|
||||||
die("Invalid number of arguments");
|
die("Invalid number of arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
switch (strtol(argv[argc-1], NULL, 0)) {
|
||||||
|
case 8:
|
||||||
|
bit_depth = VPX_BITS_8;
|
||||||
|
input_bit_depth = 8;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
bit_depth = VPX_BITS_10;
|
||||||
|
input_bit_depth = 10;
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
bit_depth = VPX_BITS_12;
|
||||||
|
input_bit_depth = 12;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("Invalid bit depth (8, 10, 12) %s", argv[argc-1]);
|
||||||
|
}
|
||||||
|
if (!vpx_img_alloc(&raw,
|
||||||
|
bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 :
|
||||||
|
VPX_IMG_FMT_I42016,
|
||||||
|
width, height, 32)) {
|
||||||
|
die("Failed to allocate image", width, height);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
|
||||||
die("Failed to allocate image", width, height);
|
die("Failed to allocate image", width, height);
|
||||||
}
|
}
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
|
||||||
// Populate encoder configuration.
|
// Populate encoder configuration.
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
@ -506,6 +545,14 @@ int main(int argc, char **argv) {
|
|||||||
cfg.g_w = width;
|
cfg.g_w = width;
|
||||||
cfg.g_h = height;
|
cfg.g_h = height;
|
||||||
|
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
if (bit_depth != VPX_BITS_8) {
|
||||||
|
cfg.g_bit_depth = bit_depth;
|
||||||
|
cfg.g_input_bit_depth = input_bit_depth;
|
||||||
|
cfg.g_profile = 2;
|
||||||
|
}
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
|
||||||
// Timebase format e.g. 30fps: numerator=1, demoninator = 30.
|
// Timebase format e.g. 30fps: numerator=1, demoninator = 30.
|
||||||
cfg.g_timebase.num = strtol(argv[6], NULL, 0);
|
cfg.g_timebase.num = strtol(argv[6], NULL, 0);
|
||||||
cfg.g_timebase.den = strtol(argv[7], NULL, 0);
|
cfg.g_timebase.den = strtol(argv[7], NULL, 0);
|
||||||
@ -515,7 +562,9 @@ int main(int argc, char **argv) {
|
|||||||
die("Invalid speed setting: must be positive");
|
die("Invalid speed setting: must be positive");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 11; (int)i < 11 + mode_to_num_layers[layering_mode]; ++i) {
|
for (i = min_args_base;
|
||||||
|
(int)i < min_args_base + mode_to_num_layers[layering_mode];
|
||||||
|
++i) {
|
||||||
cfg.ts_target_bitrate[i - 11] = strtol(argv[i], NULL, 0);
|
cfg.ts_target_bitrate[i - 11] = strtol(argv[i], NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +625,13 @@ int main(int argc, char **argv) {
|
|||||||
cfg.ss_number_layers = 1;
|
cfg.ss_number_layers = 1;
|
||||||
|
|
||||||
// Initialize codec.
|
// Initialize codec.
|
||||||
|
#if CONFIG_VP9_HIGHBITDEPTH
|
||||||
|
if (vpx_codec_enc_init(
|
||||||
|
&codec, encoder->codec_interface(), &cfg,
|
||||||
|
bit_depth == VPX_BITS_8 ? 0 : VPX_CODEC_USE_HIGHBITDEPTH))
|
||||||
|
#else
|
||||||
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
|
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
|
||||||
|
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||||
die_codec(&codec, "Failed to initialize encoder");
|
die_codec(&codec, "Failed to initialize encoder");
|
||||||
|
|
||||||
if (strncmp(encoder->name, "vp8", 3) == 0) {
|
if (strncmp(encoder->name, "vp8", 3) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user