OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #define MIN_DECAY_FACTOR 0.01 | 53 #define MIN_DECAY_FACTOR 0.01 |
54 #define MIN_GF_INTERVAL 4 | 54 #define MIN_GF_INTERVAL 4 |
55 #define MIN_KF_BOOST 300 | 55 #define MIN_KF_BOOST 300 |
56 #define NEW_MV_MODE_PENALTY 32 | 56 #define NEW_MV_MODE_PENALTY 32 |
57 #define SVC_FACTOR_PT_LOW 0.45 | 57 #define SVC_FACTOR_PT_LOW 0.45 |
58 #define DARK_THRESH 64 | 58 #define DARK_THRESH 64 |
59 #define DEFAULT_GRP_WEIGHT 1.0 | 59 #define DEFAULT_GRP_WEIGHT 1.0 |
60 #define RC_FACTOR_MIN 0.75 | 60 #define RC_FACTOR_MIN 0.75 |
61 #define RC_FACTOR_MAX 1.75 | 61 #define RC_FACTOR_MAX 1.75 |
62 | 62 |
| 63 |
| 64 #define INTRA_WEIGHT_EXPERIMENT 0 |
| 65 #if INTRA_WEIGHT_EXPERIMENT |
| 66 #define NCOUNT_INTRA_THRESH 8192 |
| 67 #define NCOUNT_INTRA_FACTOR 3 |
| 68 #define NCOUNT_FRAME_II_THRESH 5.0 |
| 69 #endif |
| 70 |
63 #define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001) | 71 #define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x) - 0.000001 : (x) + 0.000001) |
64 | 72 |
65 #if ARF_STATS_OUTPUT | 73 #if ARF_STATS_OUTPUT |
66 unsigned int arf_count = 0; | 74 unsigned int arf_count = 0; |
67 #endif | 75 #endif |
68 | 76 |
69 // Resets the first pass file to the given position using a relative seek from | 77 // Resets the first pass file to the given position using a relative seek from |
70 // the current position. | 78 // the current position. |
71 static void reset_fpf_position(TWO_PASS *p, | 79 static void reset_fpf_position(TWO_PASS *p, |
72 const FIRSTPASS_STATS *position) { | 80 const FIRSTPASS_STATS *position) { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 int64_t coded_error = 0; | 471 int64_t coded_error = 0; |
464 int64_t sr_coded_error = 0; | 472 int64_t sr_coded_error = 0; |
465 | 473 |
466 int sum_mvr = 0, sum_mvc = 0; | 474 int sum_mvr = 0, sum_mvc = 0; |
467 int sum_mvr_abs = 0, sum_mvc_abs = 0; | 475 int sum_mvr_abs = 0, sum_mvc_abs = 0; |
468 int64_t sum_mvrs = 0, sum_mvcs = 0; | 476 int64_t sum_mvrs = 0, sum_mvcs = 0; |
469 int mvcount = 0; | 477 int mvcount = 0; |
470 int intercount = 0; | 478 int intercount = 0; |
471 int second_ref_count = 0; | 479 int second_ref_count = 0; |
472 const int intrapenalty = INTRA_MODE_PENALTY; | 480 const int intrapenalty = INTRA_MODE_PENALTY; |
473 int neutral_count = 0; | 481 double neutral_count; |
474 int new_mv_count = 0; | 482 int new_mv_count = 0; |
475 int sum_in_vectors = 0; | 483 int sum_in_vectors = 0; |
476 MV lastmv = {0, 0}; | 484 MV lastmv = {0, 0}; |
477 TWO_PASS *twopass = &cpi->twopass; | 485 TWO_PASS *twopass = &cpi->twopass; |
478 const MV zero_mv = {0, 0}; | 486 const MV zero_mv = {0, 0}; |
479 int recon_y_stride, recon_uv_stride, uv_mb_height; | 487 int recon_y_stride, recon_uv_stride, uv_mb_height; |
480 | 488 |
481 YV12_BUFFER_CONFIG *const lst_yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); | 489 YV12_BUFFER_CONFIG *const lst_yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); |
482 YV12_BUFFER_CONFIG *gld_yv12 = get_ref_frame_buffer(cpi, GOLDEN_FRAME); | 490 YV12_BUFFER_CONFIG *gld_yv12 = get_ref_frame_buffer(cpi, GOLDEN_FRAME); |
483 YV12_BUFFER_CONFIG *const new_yv12 = get_frame_new_buffer(cm); | 491 YV12_BUFFER_CONFIG *const new_yv12 = get_frame_new_buffer(cm); |
(...skipping 12 matching lines...) Expand all Loading... |
496 #if CONFIG_FP_MB_STATS | 504 #if CONFIG_FP_MB_STATS |
497 if (cpi->use_fp_mb_stats) { | 505 if (cpi->use_fp_mb_stats) { |
498 vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->initial_mbs); | 506 vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->initial_mbs); |
499 } | 507 } |
500 #endif | 508 #endif |
501 | 509 |
502 vp9_clear_system_state(); | 510 vp9_clear_system_state(); |
503 | 511 |
504 intra_factor = 0.0; | 512 intra_factor = 0.0; |
505 brightness_factor = 0.0; | 513 brightness_factor = 0.0; |
| 514 neutral_count = 0.0; |
506 | 515 |
507 set_first_pass_params(cpi); | 516 set_first_pass_params(cpi); |
508 vp9_set_quantizer(cm, find_fp_qindex(cm->bit_depth)); | 517 vp9_set_quantizer(cm, find_fp_qindex(cm->bit_depth)); |
509 | 518 |
510 if (lc != NULL) { | 519 if (lc != NULL) { |
511 twopass = &lc->twopass; | 520 twopass = &lc->twopass; |
512 | 521 |
513 cpi->lst_fb_idx = cpi->svc.spatial_layer_id; | 522 cpi->lst_fb_idx = cpi->svc.spatial_layer_id; |
514 cpi->ref_frame_flags = VP9_LAST_FLAG; | 523 cpi->ref_frame_flags = VP9_LAST_FLAG; |
515 | 524 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_MOTION_ZERO_MASK; | 820 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_MOTION_ZERO_MASK; |
812 if (this_error > FPMB_ERROR_LARGE_TH) { | 821 if (this_error > FPMB_ERROR_LARGE_TH) { |
813 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LARGE_MASK; | 822 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LARGE_MASK; |
814 } else if (this_error < FPMB_ERROR_SMALL_TH) { | 823 } else if (this_error < FPMB_ERROR_SMALL_TH) { |
815 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_SMALL_MASK; | 824 cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_SMALL_MASK; |
816 } | 825 } |
817 } | 826 } |
818 #endif | 827 #endif |
819 | 828 |
820 if (motion_error <= this_error) { | 829 if (motion_error <= this_error) { |
| 830 vp9_clear_system_state(); |
| 831 |
821 // Keep a count of cases where the inter and intra were very close | 832 // Keep a count of cases where the inter and intra were very close |
822 // and very low. This helps with scene cut detection for example in | 833 // and very low. This helps with scene cut detection for example in |
823 // cropped clips with black bars at the sides or top and bottom. | 834 // cropped clips with black bars at the sides or top and bottom. |
| 835 #if INTRA_WEIGHT_EXPERIMENT |
824 if (((this_error - intrapenalty) * 9 <= motion_error * 10) && | 836 if (((this_error - intrapenalty) * 9 <= motion_error * 10) && |
825 this_error < 2 * intrapenalty) | 837 (this_error < (2 * intrapenalty))) { |
826 ++neutral_count; | 838 neutral_count += 1.0; |
| 839 // Also track cases where the intra is not much worse than the inter |
| 840 // and use this in limiting the GF/arf group length. |
| 841 } else if ((this_error > NCOUNT_INTRA_THRESH) && |
| 842 (this_error < (NCOUNT_INTRA_FACTOR * motion_error))) { |
| 843 neutral_count += (double)motion_error / |
| 844 DOUBLE_DIVIDE_CHECK((double)this_error); |
| 845 } |
| 846 #else |
| 847 if (((this_error - intrapenalty) * 9 <= motion_error * 10) && |
| 848 (this_error < (2 * intrapenalty))) { |
| 849 neutral_count += 1.0; |
| 850 } |
| 851 #endif |
827 | 852 |
828 mv.row *= 8; | 853 mv.row *= 8; |
829 mv.col *= 8; | 854 mv.col *= 8; |
830 this_error = motion_error; | 855 this_error = motion_error; |
831 xd->mi[0].src_mi->mbmi.mode = NEWMV; | 856 xd->mi[0].src_mi->mbmi.mode = NEWMV; |
832 xd->mi[0].src_mi->mbmi.mv[0].as_mv = mv; | 857 xd->mi[0].src_mi->mbmi.mv[0].as_mv = mv; |
833 xd->mi[0].src_mi->mbmi.tx_size = TX_4X4; | 858 xd->mi[0].src_mi->mbmi.tx_size = TX_4X4; |
834 xd->mi[0].src_mi->mbmi.ref_frame[0] = LAST_FRAME; | 859 xd->mi[0].src_mi->mbmi.ref_frame[0] = LAST_FRAME; |
835 xd->mi[0].src_mi->mbmi.ref_frame[1] = NONE; | 860 xd->mi[0].src_mi->mbmi.ref_frame[1] = NONE; |
836 vp9_build_inter_predictors_sby(xd, mb_row << 1, mb_col << 1, bsize); | 861 vp9_build_inter_predictors_sby(xd, mb_row << 1, mb_col << 1, bsize); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 #define LOW_SR_DIFF_TRHESH 0.1 | 1278 #define LOW_SR_DIFF_TRHESH 0.1 |
1254 #define SR_DIFF_MAX 128.0 | 1279 #define SR_DIFF_MAX 128.0 |
1255 | 1280 |
1256 static double get_sr_decay_rate(const VP9_COMP *cpi, | 1281 static double get_sr_decay_rate(const VP9_COMP *cpi, |
1257 const FIRSTPASS_STATS *frame) { | 1282 const FIRSTPASS_STATS *frame) { |
1258 const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE) | 1283 const int num_mbs = (cpi->oxcf.resize_mode != RESIZE_NONE) |
1259 ? cpi->initial_mbs : cpi->common.MBs; | 1284 ? cpi->initial_mbs : cpi->common.MBs; |
1260 double sr_diff = | 1285 double sr_diff = |
1261 (frame->sr_coded_error - frame->coded_error) / num_mbs; | 1286 (frame->sr_coded_error - frame->coded_error) / num_mbs; |
1262 double sr_decay = 1.0; | 1287 double sr_decay = 1.0; |
| 1288 double modified_pct_inter; |
| 1289 double modified_pcnt_intra; |
1263 const double motion_amplitude_factor = | 1290 const double motion_amplitude_factor = |
1264 frame->pcnt_motion * ((frame->mvc_abs + frame->mvr_abs) / 2); | 1291 frame->pcnt_motion * ((frame->mvc_abs + frame->mvr_abs) / 2); |
1265 const double pcnt_intra = 100 * (1.0 - frame->pcnt_inter); | 1292 |
| 1293 modified_pct_inter = frame->pcnt_inter; |
| 1294 #if INTRA_WEIGHT_EXPERIMENT |
| 1295 if ((frame->intra_error / DOUBLE_DIVIDE_CHECK(frame->coded_error)) < |
| 1296 (double)NCOUNT_FRAME_II_THRESH) |
| 1297 modified_pct_inter = frame->pcnt_inter - frame->pcnt_neutral; |
| 1298 #endif |
| 1299 modified_pcnt_intra = 100 * (1.0 - modified_pct_inter); |
| 1300 |
1266 | 1301 |
1267 if ((sr_diff > LOW_SR_DIFF_TRHESH)) { | 1302 if ((sr_diff > LOW_SR_DIFF_TRHESH)) { |
1268 sr_diff = MIN(sr_diff, SR_DIFF_MAX); | 1303 sr_diff = MIN(sr_diff, SR_DIFF_MAX); |
1269 sr_decay = 1.0 - (SR_DIFF_PART * sr_diff) - | 1304 sr_decay = 1.0 - (SR_DIFF_PART * sr_diff) - |
1270 (MOTION_AMP_PART * motion_amplitude_factor) - | 1305 (MOTION_AMP_PART * motion_amplitude_factor) - |
1271 (INTRA_PART * pcnt_intra); | 1306 (INTRA_PART * modified_pcnt_intra); |
1272 } | 1307 } |
1273 return MAX(sr_decay, MIN(DEFAULT_DECAY_LIMIT, frame->pcnt_inter)); | 1308 return MAX(sr_decay, MIN(DEFAULT_DECAY_LIMIT, modified_pct_inter)); |
1274 } | 1309 } |
1275 | 1310 |
1276 // This function gives an estimate of how badly we believe the prediction | 1311 // This function gives an estimate of how badly we believe the prediction |
1277 // quality is decaying from frame to frame. | 1312 // quality is decaying from frame to frame. |
1278 static double get_zero_motion_factor(const VP9_COMP *cpi, | 1313 static double get_zero_motion_factor(const VP9_COMP *cpi, |
1279 const FIRSTPASS_STATS *frame) { | 1314 const FIRSTPASS_STATS *frame) { |
1280 const double zero_motion_pct = frame->pcnt_inter - | 1315 const double zero_motion_pct = frame->pcnt_inter - |
1281 frame->pcnt_motion; | 1316 frame->pcnt_motion; |
1282 double sr_decay = get_sr_decay_rate(cpi, frame); | 1317 double sr_decay = get_sr_decay_rate(cpi, frame); |
1283 return MIN(sr_decay, zero_motion_pct); | 1318 return MIN(sr_decay, zero_motion_pct); |
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2614 !vp9_is_upper_layer_key_frame(cpi)) { | 2649 !vp9_is_upper_layer_key_frame(cpi)) { |
2615 twopass->kf_group_bits -= bits_used; | 2650 twopass->kf_group_bits -= bits_used; |
2616 twopass->last_kfgroup_zeromotion_pct = twopass->kf_zeromotion_pct; | 2651 twopass->last_kfgroup_zeromotion_pct = twopass->kf_zeromotion_pct; |
2617 } | 2652 } |
2618 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0); | 2653 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0); |
2619 | 2654 |
2620 // Increment the gf group index ready for the next frame. | 2655 // Increment the gf group index ready for the next frame. |
2621 ++twopass->gf_group.index; | 2656 ++twopass->gf_group.index; |
2622 | 2657 |
2623 // If the rate control is drifting consider adjustment to min or maxq. | 2658 // If the rate control is drifting consider adjustment to min or maxq. |
2624 if ((cpi->oxcf.rc_mode == VPX_VBR) && | 2659 if ((cpi->oxcf.rc_mode != VPX_Q) && |
2625 (cpi->twopass.gf_zeromotion_pct < VLOW_MOTION_THRESHOLD) && | 2660 (cpi->twopass.gf_zeromotion_pct < VLOW_MOTION_THRESHOLD) && |
2626 !cpi->rc.is_src_frame_alt_ref) { | 2661 !cpi->rc.is_src_frame_alt_ref) { |
2627 const int maxq_adj_limit = | 2662 const int maxq_adj_limit = |
2628 rc->worst_quality - twopass->active_worst_quality; | 2663 rc->worst_quality - twopass->active_worst_quality; |
| 2664 const int minq_adj_limit = |
| 2665 (cpi->oxcf.rc_mode == VPX_CQ) ? 0 : MINQ_ADJ_LIMIT; |
2629 | 2666 |
2630 // Undershoot. | 2667 // Undershoot. |
2631 if (rc->rate_error_estimate > cpi->oxcf.under_shoot_pct) { | 2668 if (rc->rate_error_estimate > cpi->oxcf.under_shoot_pct) { |
2632 --twopass->extend_maxq; | 2669 --twopass->extend_maxq; |
2633 if (rc->rolling_target_bits >= rc->rolling_actual_bits) | 2670 if (rc->rolling_target_bits >= rc->rolling_actual_bits) |
2634 ++twopass->extend_minq; | 2671 ++twopass->extend_minq; |
2635 // Overshoot. | 2672 // Overshoot. |
2636 } else if (rc->rate_error_estimate < -cpi->oxcf.over_shoot_pct) { | 2673 } else if (rc->rate_error_estimate < -cpi->oxcf.over_shoot_pct) { |
2637 --twopass->extend_minq; | 2674 --twopass->extend_minq; |
2638 if (rc->rolling_target_bits < rc->rolling_actual_bits) | 2675 if (rc->rolling_target_bits < rc->rolling_actual_bits) |
2639 ++twopass->extend_maxq; | 2676 ++twopass->extend_maxq; |
2640 } else { | 2677 } else { |
2641 // Adjustment for extreme local overshoot. | 2678 // Adjustment for extreme local overshoot. |
2642 if (rc->projected_frame_size > (2 * rc->base_frame_target) && | 2679 if (rc->projected_frame_size > (2 * rc->base_frame_target) && |
2643 rc->projected_frame_size > (2 * rc->avg_frame_bandwidth)) | 2680 rc->projected_frame_size > (2 * rc->avg_frame_bandwidth)) |
2644 ++twopass->extend_maxq; | 2681 ++twopass->extend_maxq; |
2645 | 2682 |
2646 // Unwind undershoot or overshoot adjustment. | 2683 // Unwind undershoot or overshoot adjustment. |
2647 if (rc->rolling_target_bits < rc->rolling_actual_bits) | 2684 if (rc->rolling_target_bits < rc->rolling_actual_bits) |
2648 --twopass->extend_minq; | 2685 --twopass->extend_minq; |
2649 else if (rc->rolling_target_bits > rc->rolling_actual_bits) | 2686 else if (rc->rolling_target_bits > rc->rolling_actual_bits) |
2650 --twopass->extend_maxq; | 2687 --twopass->extend_maxq; |
2651 } | 2688 } |
2652 | 2689 |
2653 twopass->extend_minq = clamp(twopass->extend_minq, 0, MINQ_ADJ_LIMIT); | 2690 twopass->extend_minq = clamp(twopass->extend_minq, 0, minq_adj_limit); |
2654 twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit); | 2691 twopass->extend_maxq = clamp(twopass->extend_maxq, 0, maxq_adj_limit); |
2655 } | 2692 } |
2656 } | 2693 } |
OLD | NEW |