summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJerome Jiang <jianj@google.com>2019-02-06 00:57:28 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-02-06 00:57:28 +0000
commitce4336c2ab60d185b431345987b2188511760e54 (patch)
treeeece9df8a685d0c9560c07e7ee7e8b33683df0fc /examples
parente05cea787872dc2f9ef163a62ca9021955730f71 (diff)
parenta4525dccec0cbd23b507cb58ce6d8b24a3dd4559 (diff)
downloadlibvpx-ce4336c2ab60d185b431345987b2188511760e54.tar.gz
Merge "No vpx_img_alloc for y4m input in example encoders."
Diffstat (limited to 'examples')
-rw-r--r--examples/vp9_spatial_svc_encoder.c25
-rw-r--r--examples/vpx_temporal_svc_encoder.c43
2 files changed, 42 insertions, 26 deletions
diff --git a/examples/vp9_spatial_svc_encoder.c b/examples/vp9_spatial_svc_encoder.c
index 92b310684..66316e0f9 100644
--- a/examples/vp9_spatial_svc_encoder.c
+++ b/examples/vp9_spatial_svc_encoder.c
@@ -788,19 +788,22 @@ int main(int argc, const char **argv) {
parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
+ // Y4M reader handles its own allocation.
+ if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
// Allocate image buffer
#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);
- }
+ 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);
+ }
#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);
- }
+ 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
+ }
// Initialize codec
if (vpx_svc_init(&svc_ctx, &codec, vpx_codec_vp9_cx(), &enc_cfg) !=
@@ -1127,7 +1130,9 @@ int main(int argc, const char **argv) {
printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
- vpx_img_free(&raw);
+ if (app_input.input_ctx.file_type != FILE_TYPE_Y4M) {
+ vpx_img_free(&raw);
+ }
// display average size, psnr
vpx_svc_dump_statistics(&svc_ctx);
vpx_svc_release(&svc_ctx);
diff --git a/examples/vpx_temporal_svc_encoder.c b/examples/vpx_temporal_svc_encoder.c
index aa2213a5b..ba71ca712 100644
--- a/examples/vpx_temporal_svc_encoder.c
+++ b/examples/vpx_temporal_svc_encoder.c
@@ -93,14 +93,15 @@ struct RateControlMetrics {
// in the stream.
static void set_rate_control_metrics(struct RateControlMetrics *rc,
vpx_codec_enc_cfg_t *cfg) {
- unsigned int i = 0;
+ int i = 0;
// Set the layer (cumulative) framerate and the target layer (non-cumulative)
// per-frame-bandwidth, for the rate control encoding stats below.
const double framerate = cfg->g_timebase.den / cfg->g_timebase.num;
+ const int ts_number_layers = cfg->ts_number_layers;
rc->layer_framerate[0] = framerate / cfg->ts_rate_decimator[0];
rc->layer_pfb[0] =
1000.0 * rc->layer_target_bitrate[0] / rc->layer_framerate[0];
- for (i = 0; i < cfg->ts_number_layers; ++i) {
+ for (i = 0; i < ts_number_layers; ++i) {
if (i > 0) {
rc->layer_framerate[i] = framerate / cfg->ts_rate_decimator[i];
rc->layer_pfb[i] =
@@ -119,6 +120,9 @@ static void set_rate_control_metrics(struct RateControlMetrics *rc,
rc->window_size = 15;
rc->avg_st_encoding_bitrate = 0.0;
rc->variance_st_encoding_bitrate = 0.0;
+ // Target bandwidth for the whole stream.
+ // Set to layer_target_bitrate for highest layer (total bitrate).
+ cfg->rc_target_bitrate = rc->layer_target_bitrate[ts_number_layers - 1];
}
static void printout_rate_control_summary(struct RateControlMetrics *rc,
@@ -657,6 +661,9 @@ int main(int argc, char **argv) {
die("Invalid number of arguments");
}
+ input_ctx.filename = argv[1];
+ open_input_file(&input_ctx);
+
#if CONFIG_VP9_HIGHBITDEPTH
switch (strtol(argv[argc - 1], NULL, 0)) {
case 8:
@@ -673,14 +680,22 @@ int main(int argc, char **argv) {
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);
+
+ // Y4M reader has its own allocation.
+ if (input_ctx.file_type != FILE_TYPE_Y4M) {
+ 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)) {
- die("Failed to allocate image", width, height);
+ // Y4M reader has its own allocation.
+ if (input_ctx.file_type != FILE_TYPE_Y4M) {
+ if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
+ die("Failed to allocate image", width, height);
+ }
}
#endif // CONFIG_VP9_HIGHBITDEPTH
@@ -758,13 +773,6 @@ int main(int argc, char **argv) {
set_rate_control_metrics(&rc, &cfg);
- // Target bandwidth for the whole stream.
- // Set to layer_target_bitrate for highest layer (total bitrate).
- cfg.rc_target_bitrate = rc.layer_target_bitrate[cfg.ts_number_layers - 1];
-
- input_ctx.filename = argv[1];
- open_input_file(&input_ctx);
-
if (input_ctx.file_type == FILE_TYPE_Y4M) {
if (input_ctx.width != cfg.g_w || input_ctx.height != cfg.g_h) {
die("Incorrect width or height: %d x %d", cfg.g_w, cfg.g_h);
@@ -962,7 +970,10 @@ int main(int argc, char **argv) {
// Try to rewrite the output file headers with the actual frame count.
for (i = 0; i < cfg.ts_number_layers; ++i) vpx_video_writer_close(outfile[i]);
- vpx_img_free(&raw);
+ if (input_ctx.file_type != FILE_TYPE_Y4M) {
+ vpx_img_free(&raw);
+ }
+
#if ROI_MAP
free(roi.roi_map);
#endif