#include "./ivfenc.h"
#include "./tools_common.h"
-#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER
+#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
#include "vpx/vp8cx.h"
#endif
-#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
+#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER || CONFIG_VP10_ENCODER
#include "vpx/vp8dx.h"
#endif
va_end(ap);
}
-int read_frame(struct VpxInputContext *input_ctx, vpx_image_t *img) {
+static int read_frame(struct VpxInputContext *input_ctx, vpx_image_t *img) {
FILE *f = input_ctx->file;
y4m_input *y4m = &input_ctx->y4m;
int shortread = 0;
return !shortread;
}
-int file_is_y4m(const char detect[4]) {
+static int file_is_y4m(const char detect[4]) {
if (memcmp(detect, "YUV4", 4) == 0) {
return 1;
}
return 0;
}
-int fourcc_is_ivf(const char detect[4]) {
+static int fourcc_is_ivf(const char detect[4]) {
if (memcmp(detect, "DKIF", 4) == 0) {
return 1;
}
NULL, "sharpness", 1, "Loop filter sharpness (0..7)");
static const arg_def_t static_thresh = ARG_DEF(
NULL, "static-thresh", 1, "Motion detection threshold");
-static const arg_def_t cpu_used_vp8 = ARG_DEF(
- NULL, "cpu-used", 1, "CPU Used (-16..16)");
-static const arg_def_t cpu_used_vp9 = ARG_DEF(
- NULL, "cpu-used", 1, "CPU Used (-8..8)");
static const arg_def_t auto_altref = ARG_DEF(
NULL, "auto-alt-ref", 1, "Enable automatic alt reference frames");
static const arg_def_t arnr_maxframes = ARG_DEF(
NULL, "cq-level", 1, "Constant/Constrained Quality level");
static const arg_def_t max_intra_rate_pct = ARG_DEF(
NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)");
-static const arg_def_t max_inter_rate_pct = ARG_DEF(
- NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)");
-static const arg_def_t gf_cbr_boost_pct = ARG_DEF(
- NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)");
-
-static const arg_def_t screen_content_mode = ARG_DEF(NULL, "screen-content-mode", 1,
- "Screen content mode");
#if CONFIG_VP8_ENCODER
+static const arg_def_t cpu_used_vp8 = ARG_DEF(
+ NULL, "cpu-used", 1, "CPU Used (-16..16)");
static const arg_def_t token_parts = ARG_DEF(
NULL, "token-parts", 1, "Number of token partitions to use, log2");
+static const arg_def_t screen_content_mode = ARG_DEF(
+ NULL, "screen-content-mode", 1, "Screen content mode");
static const arg_def_t *vp8_args[] = {
&cpu_used_vp8, &auto_altref, &noise_sens, &sharpness, &static_thresh,
&token_parts, &arnr_maxframes, &arnr_strength, &arnr_type,
};
#endif
-#if CONFIG_VP9_ENCODER
+#if CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
+static const arg_def_t cpu_used_vp9 = ARG_DEF(
+ NULL, "cpu-used", 1, "CPU Used (-8..8)");
static const arg_def_t tile_cols = ARG_DEF(
NULL, "tile-columns", 1, "Number of tile columns to use, log2");
static const arg_def_t tile_rows = ARG_DEF(
static const arg_def_t frame_periodic_boost = ARG_DEF(
NULL, "frame-boost", 1,
"Enable frame periodic boost (0: off (default), 1: on)");
+static const arg_def_t gf_cbr_boost_pct = ARG_DEF(
+ NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)");
+static const arg_def_t max_inter_rate_pct = ARG_DEF(
+ NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)");
+static const arg_def_t min_gf_interval = ARG_DEF(
+ NULL, "min-gf-interval", 1,
+ "min gf/arf frame interval (default 0, indicating in-built behavior)");
+static const arg_def_t max_gf_interval = ARG_DEF(
+ NULL, "max-gf-interval", 1,
+ "max gf/arf frame interval (default 0, indicating in-built behavior)");
+
+static const struct arg_enum_list color_space_enum[] = {
+ { "unknown", VPX_CS_UNKNOWN },
+ { "bt601", VPX_CS_BT_601 },
+ { "bt709", VPX_CS_BT_709 },
+ { "smpte170", VPX_CS_SMPTE_170 },
+ { "smpte240", VPX_CS_SMPTE_240 },
+ { "bt2020", VPX_CS_BT_2020 },
+ { "reserved", VPX_CS_RESERVED },
+ { "sRGB", VPX_CS_SRGB },
+ { NULL, 0 }
+};
+
+static const arg_def_t input_color_space = ARG_DEF_ENUM(
+ NULL, "color-space", 1,
+ "The color space of input content:", color_space_enum);
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
static const struct arg_enum_list bitdepth_enum[] = {
&tune_ssim, &cq_level, &max_intra_rate_pct, &max_inter_rate_pct,
&gf_cbr_boost_pct, &lossless,
&frame_parallel_decoding, &aq_mode, &frame_periodic_boost,
- &noise_sens, &tune_content,
+ &noise_sens, &tune_content, &input_color_space,
+ &min_gf_interval, &max_gf_interval,
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
&bitdeptharg, &inbitdeptharg,
#endif
VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS,
VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE,
VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT,
- VP8E_SET_MAX_INTER_BITRATE_PCT, VP8E_SET_GF_CBR_BOOST_PCT,
+ VP9E_SET_MAX_INTER_BITRATE_PCT, VP9E_SET_GF_CBR_BOOST_PCT,
VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_NOISE_SENSITIVITY,
VP9E_SET_TUNE_CONTENT, VP9E_SET_COLOR_SPACE,
+ VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL,
0
};
#endif
static const arg_def_t *no_args[] = { NULL };
-void usage_exit() {
+void usage_exit(void) {
int i;
+ const int num_encoder = get_vpx_encoder_count();
fprintf(stderr, "Usage: %s <options> -o dst_filename src_filename \n",
exec_name);
fprintf(stderr, "\nVP8 Specific Options:\n");
arg_show_usage(stderr, vp8_args);
#endif
-#if CONFIG_VP9_ENCODER
+#if CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
fprintf(stderr, "\nVP9 Specific Options:\n");
arg_show_usage(stderr, vp9_args);
#endif
" in fractional seconds. Default is 1/1000.\n");
fprintf(stderr, "\nIncluded encoders:\n\n");
- for (i = 0; i < get_vpx_encoder_count(); ++i) {
+ for (i = 0; i < num_encoder; ++i) {
const VpxInterface *const encoder = get_vpx_encoder_by_index(i);
- fprintf(stderr, " %-6s - %s\n",
- encoder->name, vpx_codec_iface_name(encoder->codec_interface()));
+ const char* defstr = (i == (num_encoder - 1)) ? "(default)" : "";
+ fprintf(stderr, " %-6s - %s %s\n",
+ encoder->name, vpx_codec_iface_name(encoder->codec_interface()),
+ defstr);
}
+ fprintf(stderr, "\n ");
+ fprintf(stderr, "Use --codec to switch to a non-default encoder.\n\n");
exit(EXIT_FAILURE);
}
#define NELEMENTS(x) (sizeof(x)/sizeof(x[0]))
#define MAX(x,y) ((x)>(y)?(x):(y))
-#if CONFIG_VP8_ENCODER && !CONFIG_VP9_ENCODER
+#if CONFIG_VP8_ENCODER && !(CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER)
#define ARG_CTRL_CNT_MAX NELEMENTS(vp8_arg_ctrl_map)
-#elif !CONFIG_VP8_ENCODER && CONFIG_VP9_ENCODER
+#elif !CONFIG_VP8_ENCODER && (CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER)
#define ARG_CTRL_CNT_MAX NELEMENTS(vp9_arg_ctrl_map)
#else
#define ARG_CTRL_CNT_MAX MAX(NELEMENTS(vp8_arg_ctrl_map), \
};
-void validate_positive_rational(const char *msg,
- struct vpx_rational *rat) {
+static void validate_positive_rational(const char *msg,
+ struct vpx_rational *rat) {
if (rat->den < 0) {
rat->num *= -1;
rat->den *= -1;
static void parse_global_config(struct VpxEncoderConfig *global, char **argv) {
char **argi, **argj;
struct arg arg;
+ const int num_encoder = get_vpx_encoder_count();
+
+ if (num_encoder < 1)
+ die("Error: no valid encoder available\n");
/* Initialize default parameters */
memset(global, 0, sizeof(*global));
- global->codec = get_vpx_encoder_by_index(0);
+ global->codec = get_vpx_encoder_by_index(num_encoder - 1);
global->passes = 0;
global->color_type = I420;
/* Assign default deadline to good quality */
}
/* Validate global config */
if (global->passes == 0) {
-#if CONFIG_VP9_ENCODER
+#if CONFIG_VP9_ENCODER || CONFIG_VP10_ENCODER
// Make default VP9 passes = 2 until there is a better quality 1-pass
// encoder
if (global->codec != NULL && global->codec->name != NULL)
}
-void open_input_file(struct VpxInputContext *input) {
+static void open_input_file(struct VpxInputContext *input) {
/* Parse certain options from the input file, if possible */
input->file = strcmp(input->filename, "-")
? fopen(input->filename, "rb") : set_binary_mode(stdin);
rewind(input->file);
}
+ /* Default to 1:1 pixel aspect ratio. */
+ input->pixel_aspect_ratio.numerator = 1;
+ input->pixel_aspect_ratio.denominator = 1;
+
/* For RAW input sources, these bytes will applied on the first frame
* in read_frame().
*/
input->file_type = FILE_TYPE_Y4M;
input->width = input->y4m.pic_w;
input->height = input->y4m.pic_h;
+ input->pixel_aspect_ratio.numerator = input->y4m.par_n;
+ input->pixel_aspect_ratio.denominator = input->y4m.par_d;
input->framerate.numerator = input->y4m.fps_n;
input->framerate.denominator = input->y4m.fps_d;
input->fmt = input->y4m.vpx_fmt;
} else if (strcmp(global->codec->name, "vp9") == 0) {
ctrl_args = vp9_args;
ctrl_args_map = vp9_arg_ctrl_map;
+#endif
+#if CONFIG_VP10_ENCODER
+ } else if (strcmp(global->codec->name, "vp10") == 0) {
+ // TODO(jingning): Reuse VP9 specific encoder configuration parameters.
+ // Consider to expand this set for VP10 encoder control.
+ ctrl_args = vp9_args;
+ ctrl_args_map = vp9_arg_ctrl_map;
#endif
}
continue;
}
- if (0) {
- } else if (arg_match(&arg, &outputfile, argi)) {
+ if (arg_match(&arg, &outputfile, argi)) {
config->out_fn = arg.val;
} else if (arg_match(&arg, &fpf_name, argi)) {
config->stats_fn = arg.val;
config->cfg.kf_mode = VPX_KF_DISABLED;
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
} else if (arg_match(&arg, &test16bitinternalarg, argi)) {
- if (strcmp(global->codec->name, "vp9") == 0) {
+ if (strcmp(global->codec->name, "vp9") == 0 ||
+ strcmp(global->codec->name, "vp10") == 0) {
test_16bit_internal = 1;
}
#endif
}
}
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
- if (strcmp(global->codec->name, "vp9") == 0) {
+ if (strcmp(global->codec->name, "vp9") == 0 ||
+ strcmp(global->codec->name, "vp10") == 0) {
config->use_16bit_internal = test_16bit_internal |
(config->cfg.g_profile > 1);
}
static void open_output_file(struct stream_state *stream,
- struct VpxEncoderConfig *global) {
+ struct VpxEncoderConfig *global,
+ const struct VpxRational *pixel_aspect_ratio) {
const char *fn = stream->config.out_fn;
const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg;
write_webm_file_header(&stream->ebml, cfg,
&global->framerate,
stream->config.stereo_fmt,
- global->codec->fourcc);
+ global->codec->fourcc,
+ pixel_aspect_ratio);
}
#endif
}
FOREACH_STREAM(setup_pass(stream, &global, pass));
- FOREACH_STREAM(open_output_file(stream, &global));
+ FOREACH_STREAM(open_output_file(stream, &global,
+ &input.pixel_aspect_ratio));
FOREACH_STREAM(initialize_encoder(stream, &global));
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
- if (strcmp(global.codec->name, "vp9") == 0) {
+ if (strcmp(global.codec->name, "vp9") == 0 ||
+ strcmp(global.codec->name, "vp10") == 0) {
// Check to see if at least one stream uses 16 bit internal.
// Currently assume that the bit_depths for all streams using
// highbitdepth are the same.