History

vpxenc: add --aq-mode flag to control adaptive quantization

Guillaume Martres committed 13 years ago

Commit e4f3b971 parent 37a83b48 files · +34 −17Browse files

Unified · Split

8 files
  1. vp9/common/vp9_onyx.h +7 −0
  2. vp9/encoder/vp9_encodeframe.c +5 −5
  3. vp9/encoder/vp9_firstpass.c +5 −5
  4. vp9/encoder/vp9_onyx_if.c +2 −4
  5. vp9/encoder/vp9_onyx_int.h +0 −1
  6. vp9/vp9_cx_iface.c +7 −0
  7. vpx/vp8cx.h +3 −0
  8. vpxenc.c +5 −2
vp9/common/vp9_onyx.h+7−0
@@ -64,6 +64,12 @@ extern "C" · 63 unmodified lines
6464 FRAMEFLAGS_ALTREF = 4,
6565 } FRAMETYPE_FLAGS;
6666
67+ typedef enum {
68+ NO_AQ = 0,
69+ VARIANCE_AQ = 1,
70+ AQ_MODES_COUNT // This should always be the last member of the enum
71+ } AQ_MODES;
72+
6773 typedef struct {
6874 int version; // 4 versions of bitstream defined:
6975 // 0 - best quality/slowest decode,
@@ -128,6 +134,7 @@ extern "C" · 58 unmodified lines
128134 int best_allowed_q;
129135 int cq_level;
130136 int lossless;
137+ int aq_mode; // Adaptive Quantization mode
131138
132139 // two pass datarate control
133140 int two_pass_vbrbias; // two pass datarate control tweaks
vp9/encoder/vp9_encodeframe.c+5−5
@@ -409,7 +409,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, · 408 unmodified lines
409409 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y)
410410 xd->mi_8x8[x_idx + y * mis] = mi_addr;
411411
412− if (cpi->sf.variance_adaptive_quantization) {
412+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
413413 vp9_mb_init_quantizer(cpi, x);
414414 }
415415
@@ -558,7 +558,7 @@ static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, · 142 unmodified lines
558558
559559 /* segment ID */
560560 if (seg->enabled) {
561− if (!cpi->sf.variance_adaptive_quantization) {
561+ if (!cpi->oxcf.aq_mode == VARIANCE_AQ) {
562562 uint8_t *map = seg->update_map ? cpi->segmentation_map
563563 : cm->last_frame_seg_map;
564564 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col);
@@ -635,7 +635,7 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, · 70 unmodified lines
635635
636636 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize);
637637
638− if (cpi->sf.variance_adaptive_quantization) {
638+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
639639 int energy;
640640 if (bsize <= BLOCK_16X16) {
641641 energy = x->mb_energy;
@@ -651,7 +651,7 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, · 9 unmodified lines
651651 if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
652652 vp9_activity_masking(cpi, x);
653653
654− if (cpi->sf.variance_adaptive_quantization) {
654+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
655655 vp9_clear_system_state(); // __asm emms;
656656 x->rdmult = round(x->rdmult * rdmult_ratio);
657657 }
@@ -670,7 +670,7 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, · 12 unmodified lines
670670 totaldist, bsize, ctx, best_rd);
671671 }
672672
673− if (cpi->sf.variance_adaptive_quantization) {
673+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
674674 x->rdmult = orig_rdmult;
675675 if (*totalrate != INT_MAX) {
676676 vp9_clear_system_state(); // __asm emms;
vp9/encoder/vp9_firstpass.c+5−5
@@ -602,14 +602,14 @@ void vp9_first_pass(VP9_COMP *cpi) { · 601 unmodified lines
602602 num_8x8_blocks_wide_lookup[xd->mi_8x8[0]->mbmi.sb_type],
603603 cm->mi_rows, cm->mi_cols);
604604
605− if (cpi->sf.variance_adaptive_quantization) {
605+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
606606 int energy = vp9_block_energy(cpi, x, xd->mi_8x8[0]->mbmi.sb_type);
607607 error_weight = vp9_vaq_inv_q_ratio(energy);
608608 }
609609
610610 // do intra 16x16 prediction
611611 this_error = vp9_encode_intra(x, use_dc_pred);
612− if (cpi->sf.variance_adaptive_quantization) {
612+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
613613 vp9_clear_system_state(); // __asm emms;
614614 this_error *= error_weight;
615615 }
@@ -647,7 +647,7 @@ void vp9_first_pass(VP9_COMP *cpi) { · 31 unmodified lines
647647 first_pass_motion_search(cpi, x, &best_ref_mv,
648648 &mv.as_mv, lst_yv12,
649649 &motion_error, recon_yoffset);
650− if (cpi->sf.variance_adaptive_quantization) {
650+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
651651 vp9_clear_system_state(); // __asm emms;
652652 motion_error *= error_weight;
653653 }
@@ -658,7 +658,7 @@ void vp9_first_pass(VP9_COMP *cpi) { · 4 unmodified lines
658658 tmp_err = INT_MAX;
659659 first_pass_motion_search(cpi, x, &zero_ref_mv, &tmp_mv.as_mv,
660660 lst_yv12, &tmp_err, recon_yoffset);
661− if (cpi->sf.variance_adaptive_quantization) {
661+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
662662 vp9_clear_system_state(); // __asm emms;
663663 tmp_err *= error_weight;
664664 }
@@ -678,7 +678,7 @@ void vp9_first_pass(VP9_COMP *cpi) { · 13 unmodified lines
678678 first_pass_motion_search(cpi, x, &zero_ref_mv,
679679 &tmp_mv.as_mv, gld_yv12,
680680 &gf_motion_error, recon_yoffset);
681− if (cpi->sf.variance_adaptive_quantization) {
681+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
682682 vp9_clear_system_state(); // __asm emms;
683683 gf_motion_error *= error_weight;
684684 }
vp9/encoder/vp9_onyx_if.c+2−4
@@ -764,8 +764,6 @@ void vp9_set_speed_features(VP9_COMP *cpi) { · 763 unmodified lines
764764 sf->static_segmentation = 0;
765765 #endif
766766
767− sf->variance_adaptive_quantization = 0;
768−
769767 switch (mode) {
770768 case 0: // This is the best quality mode.
771769 break;
@@ -3188,7 +3186,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, · 2416 unmodified lines
31883186 }
31893187 }
31903188
3191− if (cpi->sf.variance_adaptive_quantization) {
3189+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
31923190 vp9_vaq_frame_setup(cpi);
31933191 }
31943192
@@ -3975,7 +3973,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags, · 780 unmodified lines
39753973
39763974 vp9_setup_interp_filters(&cpi->mb.e_mbd, DEFAULT_INTERP_FILTER, cm);
39773975
3978− if (cpi->sf.variance_adaptive_quantization) {
3976+ if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
39793977 vp9_vaq_init();
39803978 }
39813979
vp9/encoder/vp9_onyx_int.h+0−1
@@ -248,7 +248,6 @@ typedef struct { · 247 unmodified lines
248248 int auto_mv_step_size;
249249 int optimize_coefficients;
250250 int static_segmentation;
251− int variance_adaptive_quantization;
252251 int comp_inter_joint_search_thresh;
253252 int adaptive_rd_thresh;
254253 int skip_encode_sb;
vp9/vp9_cx_iface.c+7−0
@@ -38,6 +38,7 @@ struct vp9_extracfg { · 37 unmodified lines
3838 unsigned int rc_max_intra_bitrate_pct;
3939 unsigned int lossless;
4040 unsigned int frame_parallel_decoding_mode;
41+ unsigned int aq_mode;
4142 };
4243
4344 struct extraconfig_map {
@@ -66,6 +67,7 @@ static const struct extraconfig_map extracfg_map[] = { · 22 unmodified lines
6667 0, /* rc_max_intra_bitrate_pct */
6768 0, /* lossless */
6869 0, /* frame_parallel_decoding_mode */
70+ 0, /* aq_mode */
6971 }
7072 }
7173 };
@@ -157,6 +159,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, · 85 unmodified lines
157159 RANGE_CHECK_HI(cfg, rc_max_quantizer, 0);
158160 RANGE_CHECK_HI(cfg, rc_min_quantizer, 0);
159161 }
162+ RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODES_COUNT - 1);
160163
161164 RANGE_CHECK_HI(cfg, g_threads, 64);
162165 RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
@@ -335,6 +338,8 @@ static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, · 172 unmodified lines
335338 oxcf->error_resilient_mode = cfg.g_error_resilient;
336339 oxcf->frame_parallel_decoding_mode = vp8_cfg.frame_parallel_decoding_mode;
337340
341+ oxcf->aq_mode = vp8_cfg.aq_mode;
342+
338343 oxcf->ss_number_layers = cfg.ss_number_layers;
339344 /*
340345 printf("Current VP9 Settings: \n");
@@ -445,6 +450,7 @@ static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, · 104 unmodified lines
445450 MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct);
446451 MAP(VP9E_SET_LOSSLESS, xcfg.lossless);
447452 MAP(VP9E_SET_FRAME_PARALLEL_DECODING, xcfg.frame_parallel_decoding_mode);
453+ MAP(VP9E_SET_AQ_MODE, xcfg.aq_mode);
448454 }
449455
450456 res = validate_config(ctx, &ctx->cfg, &xcfg);
@@ -1071,6 +1077,7 @@ static vpx_codec_ctrl_fn_map_t vp9e_ctf_maps[] = { · 620 unmodified lines
10711077 {VP8E_SET_MAX_INTRA_BITRATE_PCT, set_param},
10721078 {VP9E_SET_LOSSLESS, set_param},
10731079 {VP9E_SET_FRAME_PARALLEL_DECODING, set_param},
1080+ {VP9E_SET_AQ_MODE, set_param},
10741081 {VP9_GET_REFERENCE, get_reference},
10751082 {VP9E_SET_SVC, vp9e_set_svc},
10761083 {VP9E_SET_SVC_PARAMETERS, vp9e_set_svc_parameters},
vpx/vp8cx.h+3−0
@@ -193,6 +193,7 @@ enum vp8e_enc_control_id { · 192 unmodified lines
193193 VP9E_SET_TILE_COLUMNS,
194194 VP9E_SET_TILE_ROWS,
195195 VP9E_SET_FRAME_PARALLEL_DECODING,
196+ VP9E_SET_AQ_MODE,
196197
197198 VP9E_SET_SVC,
198199 VP9E_SET_SVC_PARAMETERS
@@ -343,6 +344,8 @@ VPX_CTRL_USE_TYPE(VP9E_SET_LOSSLESS, unsigned int) · 144 unmodified lines
343344
344345 VPX_CTRL_USE_TYPE(VP9E_SET_FRAME_PARALLEL_DECODING, unsigned int)
345346
347+VPX_CTRL_USE_TYPE(VP9E_SET_AQ_MODE, unsigned int)
348+
346349 /*! @} - end defgroup vp8_encoder */
347350 #ifdef __cplusplus
348351 } // extern "C"
vpxenc.c+5−2
@@ -561,6 +561,9 @@ static const arg_def_t lossless = ARG_DEF(NULL, "lossless", 1, "Lossless mode"); · 560 unmodified lines
561561 #if CONFIG_VP9_ENCODER
562562 static const arg_def_t frame_parallel_decoding = ARG_DEF(
563563 NULL, "frame-parallel", 1, "Enable frame parallel decodability features");
564+static const arg_def_t aq_mode = ARG_DEF(
565+ NULL, "aq-mode", 1,
566+ "Adaptive quantization mode (0: disabled (by default), 1: variance based)");
564567 #endif
565568
566569 #if CONFIG_VP8_ENCODER
@@ -585,7 +588,7 @@ static const arg_def_t *vp9_args[] = { · 18 unmodified lines
585588 &cpu_used, &auto_altref, &noise_sens, &sharpness, &static_thresh,
586589 &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type,
587590 &tune_ssim, &cq_level, &max_intra_rate_pct, &lossless,
588− &frame_parallel_decoding,
591+ &frame_parallel_decoding, &aq_mode,
589592 NULL
590593 };
591594 static const int vp9_arg_ctrl_map[] = {
@@ -594,7 +597,7 @@ static const int vp9_arg_ctrl_map[] = { · 2 unmodified lines
594597 VP9E_SET_TILE_COLUMNS, VP9E_SET_TILE_ROWS,
595598 VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE,
596599 VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT,
597− VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING,
600+ VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
598601 0
599602 };
600603 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t