| 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 |
| 11 #include "math.h" | 11 #include "math.h" |
| 12 #include "limits.h" | 12 #include "limits.h" |
| 13 #include "vp9/encoder/vp9_block.h" | 13 #include "vp9/encoder/vp9_block.h" |
| 14 #include "vp9/encoder/vp9_onyx_int.h" | 14 #include "vp9/encoder/vp9_onyx_int.h" |
| 15 #include "vp9/encoder/vp9_variance.h" | 15 #include "vp9/encoder/vp9_variance.h" |
| 16 #include "vp9/encoder/vp9_encodeintra.h" | 16 #include "vp9/encoder/vp9_encodeintra.h" |
| 17 #include "vp9/common/vp9_setupintrarecon.h" | 17 #include "vp9/common/vp9_setupintrarecon.h" |
| 18 #include "vp9/encoder/vp9_mcomp.h" | 18 #include "vp9/encoder/vp9_mcomp.h" |
| 19 #include "vp9/encoder/vp9_firstpass.h" | 19 #include "vp9/encoder/vp9_firstpass.h" |
| 20 #include "vpx_scale/vpxscale.h" | 20 #include "vpx_scale/vpx_scale.h" |
| 21 #include "vp9/encoder/vp9_encodeframe.h" | 21 #include "vp9/encoder/vp9_encodeframe.h" |
| 22 #include "vp9/encoder/vp9_encodemb.h" | 22 #include "vp9/encoder/vp9_encodemb.h" |
| 23 #include "vp9/common/vp9_extend.h" | 23 #include "vp9/common/vp9_extend.h" |
| 24 #include "vp9/common/vp9_systemdependent.h" | 24 #include "vp9/common/vp9_systemdependent.h" |
| 25 #include "vpx_mem/vpx_mem.h" | 25 #include "vpx_mem/vpx_mem.h" |
| 26 #include "vp9/common/vp9_swapyv12buffer.h" | 26 #include "vp9/common/vp9_swapyv12buffer.h" |
| 27 #include <stdio.h> | 27 #include <stdio.h> |
| 28 #include "vp9/encoder/vp9_quantize.h" | 28 #include "vp9/encoder/vp9_quantize.h" |
| 29 #include "vp9/encoder/vp9_rdopt.h" | 29 #include "vp9/encoder/vp9_rdopt.h" |
| 30 #include "vp9/encoder/vp9_ratectrl.h" | 30 #include "vp9/encoder/vp9_ratectrl.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, | 289 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, |
| 290 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, | 290 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, |
| 291 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, | 291 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, |
| 292 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, | 292 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
, |
| 293 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000 | 293 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000 |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 static double simple_weight(YV12_BUFFER_CONFIG *source) { | 296 static double simple_weight(YV12_BUFFER_CONFIG *source) { |
| 297 int i, j; | 297 int i, j; |
| 298 | 298 |
| 299 unsigned char *src = source->y_buffer; | 299 uint8_t *src = source->y_buffer; |
| 300 double sum_weights = 0.0; | 300 double sum_weights = 0.0; |
| 301 | 301 |
| 302 // Loop throught the Y plane raw examining levels and creating a weight for th
e image | 302 // Loop throught the Y plane raw examining levels and creating a weight for th
e image |
| 303 i = source->y_height; | 303 i = source->y_height; |
| 304 do { | 304 do { |
| 305 j = source->y_width; | 305 j = source->y_width; |
| 306 do { | 306 do { |
| 307 sum_weights += weight_table[ *src]; | 307 sum_weights += weight_table[ *src]; |
| 308 src++; | 308 src++; |
| 309 } while (--j); | 309 } while (--j); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 338 | 338 |
| 339 void vp9_end_first_pass(VP9_COMP *cpi) { | 339 void vp9_end_first_pass(VP9_COMP *cpi) { |
| 340 output_stats(cpi, cpi->output_pkt_list, cpi->twopass.total_stats); | 340 output_stats(cpi, cpi->output_pkt_list, cpi->twopass.total_stats); |
| 341 } | 341 } |
| 342 | 342 |
| 343 static void zz_motion_search(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *r
econ_buffer, int *best_motion_err, int recon_yoffset) { | 343 static void zz_motion_search(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *r
econ_buffer, int *best_motion_err, int recon_yoffset) { |
| 344 MACROBLOCKD *const xd = &x->e_mbd; | 344 MACROBLOCKD *const xd = &x->e_mbd; |
| 345 BLOCK *b = &x->block[0]; | 345 BLOCK *b = &x->block[0]; |
| 346 BLOCKD *d = &x->e_mbd.block[0]; | 346 BLOCKD *d = &x->e_mbd.block[0]; |
| 347 | 347 |
| 348 unsigned char *src_ptr = (*(b->base_src) + b->src); | 348 uint8_t *src_ptr = (*(b->base_src) + b->src); |
| 349 int src_stride = b->src_stride; | 349 int src_stride = b->src_stride; |
| 350 unsigned char *ref_ptr; | 350 uint8_t *ref_ptr; |
| 351 int ref_stride = d->pre_stride; | 351 int ref_stride = d->pre_stride; |
| 352 | 352 |
| 353 // Set up pointers for this macro block recon buffer | 353 // Set up pointers for this macro block recon buffer |
| 354 xd->pre.y_buffer = recon_buffer->y_buffer + recon_yoffset; | 354 xd->pre.y_buffer = recon_buffer->y_buffer + recon_yoffset; |
| 355 | 355 |
| 356 ref_ptr = (unsigned char *)(*(d->base_pre) + d->pre); | 356 ref_ptr = (uint8_t *)(*(d->base_pre) + d->pre); |
| 357 | 357 |
| 358 vp9_mse16x16(src_ptr, src_stride, ref_ptr, ref_stride, | 358 vp9_mse16x16(src_ptr, src_stride, ref_ptr, ref_stride, |
| 359 (unsigned int *)(best_motion_err)); | 359 (unsigned int *)(best_motion_err)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 362 static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 363 int_mv *ref_mv, MV *best_mv, | 363 int_mv *ref_mv, MV *best_mv, |
| 364 YV12_BUFFER_CONFIG *recon_buffer, | 364 YV12_BUFFER_CONFIG *recon_buffer, |
| 365 int *best_motion_err, int recon_yoffset) { | 365 int *best_motion_err, int recon_yoffset) { |
| 366 MACROBLOCKD *const xd = &x->e_mbd; | 366 MACROBLOCKD *const xd = &x->e_mbd; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 509 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
| 510 int this_error; | 510 int this_error; |
| 511 int gf_motion_error = INT_MAX; | 511 int gf_motion_error = INT_MAX; |
| 512 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); | 512 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); |
| 513 | 513 |
| 514 xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset; | 514 xd->dst.y_buffer = new_yv12->y_buffer + recon_yoffset; |
| 515 xd->dst.u_buffer = new_yv12->u_buffer + recon_uvoffset; | 515 xd->dst.u_buffer = new_yv12->u_buffer + recon_uvoffset; |
| 516 xd->dst.v_buffer = new_yv12->v_buffer + recon_uvoffset; | 516 xd->dst.v_buffer = new_yv12->v_buffer + recon_uvoffset; |
| 517 xd->left_available = (mb_col != 0); | 517 xd->left_available = (mb_col != 0); |
| 518 | 518 |
| 519 #if !CONFIG_SUPERBLOCKS | |
| 520 // Copy current mb to a buffer | |
| 521 vp9_copy_mem16x16(x->src.y_buffer, x->src.y_stride, x->thismb, 16); | |
| 522 #endif | |
| 523 | |
| 524 // do intra 16x16 prediction | 519 // do intra 16x16 prediction |
| 525 this_error = vp9_encode_intra(cpi, x, use_dc_pred); | 520 this_error = vp9_encode_intra(cpi, x, use_dc_pred); |
| 526 | 521 |
| 527 // "intrapenalty" below deals with situations where the intra and inter er
ror scores are very low (eg a plain black frame) | 522 // "intrapenalty" below deals with situations where the intra and inter er
ror scores are very low (eg a plain black frame) |
| 528 // We do not have special cases in first pass for 0,0 and nearest etc so a
ll inter modes carry an overhead cost estimate fot the mv. | 523 // We do not have special cases in first pass for 0,0 and nearest etc so a
ll inter modes carry an overhead cost estimate fot the mv. |
| 529 // When the error score is very low this causes us to pick all or lots of
INTRA modes and throw lots of key frames. | 524 // When the error score is very low this causes us to pick all or lots of
INTRA modes and throw lots of key frames. |
| 530 // This penalty adds a cost matching that of a 0,0 mv to the intra case. | 525 // This penalty adds a cost matching that of a 0,0 mv to the intra case. |
| 531 this_error += intrapenalty; | 526 this_error += intrapenalty; |
| 532 | 527 |
| 533 // Cumulative intra error total | 528 // Cumulative intra error total |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 // Estimate a cost per mb attributable to overheads such as the coding of | 787 // Estimate a cost per mb attributable to overheads such as the coding of |
| 793 // modes and motion vectors. | 788 // modes and motion vectors. |
| 794 // Currently simplistic in its assumptions for testing. | 789 // Currently simplistic in its assumptions for testing. |
| 795 // | 790 // |
| 796 | 791 |
| 797 | 792 |
| 798 static double bitcost(double prob) { | 793 static double bitcost(double prob) { |
| 799 return -(log(prob) / log(2.0)); | 794 return -(log(prob) / log(2.0)); |
| 800 } | 795 } |
| 801 | 796 |
| 802 static long long estimate_modemvcost(VP9_COMP *cpi, | 797 static int64_t estimate_modemvcost(VP9_COMP *cpi, |
| 803 FIRSTPASS_STATS *fpstats) { | 798 FIRSTPASS_STATS *fpstats) { |
| 799 #if 0 |
| 804 int mv_cost; | 800 int mv_cost; |
| 805 int mode_cost; | 801 int mode_cost; |
| 806 | 802 |
| 807 double av_pct_inter = fpstats->pcnt_inter / fpstats->count; | 803 double av_pct_inter = fpstats->pcnt_inter / fpstats->count; |
| 808 double av_pct_motion = fpstats->pcnt_motion / fpstats->count; | 804 double av_pct_motion = fpstats->pcnt_motion / fpstats->count; |
| 809 double av_intra = (1.0 - av_pct_inter); | 805 double av_intra = (1.0 - av_pct_inter); |
| 810 | 806 |
| 811 double zz_cost; | 807 double zz_cost; |
| 812 double motion_cost; | 808 double motion_cost; |
| 813 double intra_cost; | 809 double intra_cost; |
| 814 | 810 |
| 815 zz_cost = bitcost(av_pct_inter - av_pct_motion); | 811 zz_cost = bitcost(av_pct_inter - av_pct_motion); |
| 816 motion_cost = bitcost(av_pct_motion); | 812 motion_cost = bitcost(av_pct_motion); |
| 817 intra_cost = bitcost(av_intra); | 813 intra_cost = bitcost(av_intra); |
| 818 | 814 |
| 819 // Estimate of extra bits per mv overhead for mbs | 815 // Estimate of extra bits per mv overhead for mbs |
| 820 // << 9 is the normalization to the (bits * 512) used in vp9_bits_per_mb | 816 // << 9 is the normalization to the (bits * 512) used in vp9_bits_per_mb |
| 821 mv_cost = ((int)(fpstats->new_mv_count / fpstats->count) * 8) << 9; | 817 mv_cost = ((int)(fpstats->new_mv_count / fpstats->count) * 8) << 9; |
| 822 | 818 |
| 823 // Crude estimate of overhead cost from modes | 819 // Crude estimate of overhead cost from modes |
| 824 // << 9 is the normalization to (bits * 512) used in vp9_bits_per_mb | 820 // << 9 is the normalization to (bits * 512) used in vp9_bits_per_mb |
| 825 mode_cost = | 821 mode_cost = |
| 826 (int)((((av_pct_inter - av_pct_motion) * zz_cost) + | 822 (int)((((av_pct_inter - av_pct_motion) * zz_cost) + |
| 827 (av_pct_motion * motion_cost) + | 823 (av_pct_motion * motion_cost) + |
| 828 (av_intra * intra_cost)) * cpi->common.MBs) << 9; | 824 (av_intra * intra_cost)) * cpi->common.MBs) << 9; |
| 829 | 825 |
| 830 // return mv_cost + mode_cost; | 826 // return mv_cost + mode_cost; |
| 831 // TODO PGW Fix overhead costs for extended Q range | 827 // TODO PGW Fix overhead costs for extended Q range |
| 828 #endif |
| 832 return 0; | 829 return 0; |
| 833 } | 830 } |
| 834 | 831 |
| 835 static double calc_correction_factor(double err_per_mb, | 832 static double calc_correction_factor(double err_per_mb, |
| 836 double err_divisor, | 833 double err_divisor, |
| 837 double pt_low, | 834 double pt_low, |
| 838 double pt_high, | 835 double pt_high, |
| 839 int Q) { | 836 int Q) { |
| 840 double power_term; | 837 double power_term; |
| 841 double error_term = err_per_mb / err_divisor; | 838 double error_term = err_per_mb / err_divisor; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 | 1223 |
| 1227 // Function to test for a condition where a complex transition is followed | 1224 // Function to test for a condition where a complex transition is followed |
| 1228 // by a static section. For example in slide shows where there is a fade | 1225 // by a static section. For example in slide shows where there is a fade |
| 1229 // between slides. This is to help with more optimal kf and gf positioning. | 1226 // between slides. This is to help with more optimal kf and gf positioning. |
| 1230 static int detect_transition_to_still( | 1227 static int detect_transition_to_still( |
| 1231 VP9_COMP *cpi, | 1228 VP9_COMP *cpi, |
| 1232 int frame_interval, | 1229 int frame_interval, |
| 1233 int still_interval, | 1230 int still_interval, |
| 1234 double loop_decay_rate, | 1231 double loop_decay_rate, |
| 1235 double last_decay_rate) { | 1232 double last_decay_rate) { |
| 1236 BOOL trans_to_still = FALSE; | 1233 int trans_to_still = FALSE; |
| 1237 | 1234 |
| 1238 // Break clause to detect very still sections after motion | 1235 // Break clause to detect very still sections after motion |
| 1239 // For example a static image after a fade or other transition | 1236 // For example a static image after a fade or other transition |
| 1240 // instead of a clean scene cut. | 1237 // instead of a clean scene cut. |
| 1241 if ((frame_interval > MIN_GF_INTERVAL) && | 1238 if ((frame_interval > MIN_GF_INTERVAL) && |
| 1242 (loop_decay_rate >= 0.999) && | 1239 (loop_decay_rate >= 0.999) && |
| 1243 (last_decay_rate < 0.9)) { | 1240 (last_decay_rate < 0.9)) { |
| 1244 int j; | 1241 int j; |
| 1245 FIRSTPASS_STATS *position = cpi->twopass.stats_in; | 1242 FIRSTPASS_STATS *position = cpi->twopass.stats_in; |
| 1246 FIRSTPASS_STATS tmp_next_frame; | 1243 FIRSTPASS_STATS tmp_next_frame; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1264 if (j == still_interval) | 1261 if (j == still_interval) |
| 1265 trans_to_still = TRUE; | 1262 trans_to_still = TRUE; |
| 1266 } | 1263 } |
| 1267 | 1264 |
| 1268 return trans_to_still; | 1265 return trans_to_still; |
| 1269 } | 1266 } |
| 1270 | 1267 |
| 1271 // This function detects a flash through the high relative pcnt_second_ref | 1268 // This function detects a flash through the high relative pcnt_second_ref |
| 1272 // score in the frame following a flash frame. The offset passed in should | 1269 // score in the frame following a flash frame. The offset passed in should |
| 1273 // reflect this | 1270 // reflect this |
| 1274 static BOOL detect_flash(VP9_COMP *cpi, int offset) { | 1271 static int detect_flash(VP9_COMP *cpi, int offset) { |
| 1275 FIRSTPASS_STATS next_frame; | 1272 FIRSTPASS_STATS next_frame; |
| 1276 | 1273 |
| 1277 BOOL flash_detected = FALSE; | 1274 int flash_detected = FALSE; |
| 1278 | 1275 |
| 1279 // Read the frame data. | 1276 // Read the frame data. |
| 1280 // The return is FALSE (no flash detected) if not a valid frame | 1277 // The return is FALSE (no flash detected) if not a valid frame |
| 1281 if (read_frame_stats(cpi, &next_frame, offset) != EOF) { | 1278 if (read_frame_stats(cpi, &next_frame, offset) != EOF) { |
| 1282 // What we are looking for here is a situation where there is a | 1279 // What we are looking for here is a situation where there is a |
| 1283 // brief break in prediction (such as a flash) but subsequent frames | 1280 // brief break in prediction (such as a flash) but subsequent frames |
| 1284 // are reasonably well predicted by an earlier (pre flash) frame. | 1281 // are reasonably well predicted by an earlier (pre flash) frame. |
| 1285 // The recovery after a flash is indicated by a high pcnt_second_ref | 1282 // The recovery after a flash is indicated by a high pcnt_second_ref |
| 1286 // comapred to pcnt_inter. | 1283 // comapred to pcnt_inter. |
| 1287 if ((next_frame.pcnt_second_ref > next_frame.pcnt_inter) && | 1284 if ((next_frame.pcnt_second_ref > next_frame.pcnt_inter) && |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 FIRSTPASS_STATS this_frame; | 1376 FIRSTPASS_STATS this_frame; |
| 1380 | 1377 |
| 1381 int i; | 1378 int i; |
| 1382 double boost_score = 0.0; | 1379 double boost_score = 0.0; |
| 1383 double mv_ratio_accumulator = 0.0; | 1380 double mv_ratio_accumulator = 0.0; |
| 1384 double decay_accumulator = 1.0; | 1381 double decay_accumulator = 1.0; |
| 1385 double this_frame_mv_in_out = 0.0; | 1382 double this_frame_mv_in_out = 0.0; |
| 1386 double mv_in_out_accumulator = 0.0; | 1383 double mv_in_out_accumulator = 0.0; |
| 1387 double abs_mv_in_out_accumulator = 0.0; | 1384 double abs_mv_in_out_accumulator = 0.0; |
| 1388 int arf_boost; | 1385 int arf_boost; |
| 1389 BOOL flash_detected = FALSE; | 1386 int flash_detected = FALSE; |
| 1390 | 1387 |
| 1391 // Search forward from the proposed arf/next gf position | 1388 // Search forward from the proposed arf/next gf position |
| 1392 for (i = 0; i < f_frames; i++) { | 1389 for (i = 0; i < f_frames; i++) { |
| 1393 if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF) | 1390 if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF) |
| 1394 break; | 1391 break; |
| 1395 | 1392 |
| 1396 // Update the motion related elements to the boost calculation | 1393 // Update the motion related elements to the boost calculation |
| 1397 accumulate_frame_motion_stats(cpi, &this_frame, | 1394 accumulate_frame_motion_stats(cpi, &this_frame, |
| 1398 &this_frame_mv_in_out, &mv_in_out_accumulator, | 1395 &this_frame_mv_in_out, &mv_in_out_accumulator, |
| 1399 &abs_mv_in_out_accumulator, &mv_ratio_accumula
tor); | 1396 &abs_mv_in_out_accumulator, &mv_ratio_accumula
tor); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 double mv_in_out_accumulator = 0.0; | 1531 double mv_in_out_accumulator = 0.0; |
| 1535 double abs_mv_in_out_accumulator = 0.0; | 1532 double abs_mv_in_out_accumulator = 0.0; |
| 1536 | 1533 |
| 1537 int max_bits = frame_max_bits(cpi); // Max for a single frame | 1534 int max_bits = frame_max_bits(cpi); // Max for a single frame |
| 1538 | 1535 |
| 1539 unsigned int allow_alt_ref = | 1536 unsigned int allow_alt_ref = |
| 1540 cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames; | 1537 cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames; |
| 1541 | 1538 |
| 1542 int f_boost = 0; | 1539 int f_boost = 0; |
| 1543 int b_boost = 0; | 1540 int b_boost = 0; |
| 1544 BOOL flash_detected; | 1541 int flash_detected; |
| 1545 | 1542 |
| 1546 cpi->twopass.gf_group_bits = 0; | 1543 cpi->twopass.gf_group_bits = 0; |
| 1547 | 1544 |
| 1548 vp9_clear_system_state(); // __asm emms; | 1545 vp9_clear_system_state(); // __asm emms; |
| 1549 | 1546 |
| 1550 start_pos = cpi->twopass.stats_in; | 1547 start_pos = cpi->twopass.stats_in; |
| 1551 | 1548 |
| 1552 vpx_memset(&next_frame, 0, sizeof(next_frame)); // assure clean | 1549 vpx_memset(&next_frame, 0, sizeof(next_frame)); // assure clean |
| 1553 | 1550 |
| 1554 // Load stats for the current frame. | 1551 // Load stats for the current frame. |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 return ret_val; | 1941 return ret_val; |
| 1945 } | 1942 } |
| 1946 | 1943 |
| 1947 void vp9_second_pass(VP9_COMP *cpi) { | 1944 void vp9_second_pass(VP9_COMP *cpi) { |
| 1948 int tmp_q; | 1945 int tmp_q; |
| 1949 int frames_left = (int)(cpi->twopass.total_stats->count - cpi->common.current_
video_frame); | 1946 int frames_left = (int)(cpi->twopass.total_stats->count - cpi->common.current_
video_frame); |
| 1950 | 1947 |
| 1951 FIRSTPASS_STATS this_frame; | 1948 FIRSTPASS_STATS this_frame; |
| 1952 FIRSTPASS_STATS this_frame_copy; | 1949 FIRSTPASS_STATS this_frame_copy; |
| 1953 | 1950 |
| 1954 double this_frame_error; | |
| 1955 double this_frame_intra_error; | 1951 double this_frame_intra_error; |
| 1956 double this_frame_coded_error; | 1952 double this_frame_coded_error; |
| 1957 | 1953 |
| 1958 FIRSTPASS_STATS *start_pos; | |
| 1959 | |
| 1960 int overhead_bits; | 1954 int overhead_bits; |
| 1961 | 1955 |
| 1962 if (!cpi->twopass.stats_in) { | 1956 if (!cpi->twopass.stats_in) { |
| 1963 return; | 1957 return; |
| 1964 } | 1958 } |
| 1965 | 1959 |
| 1966 vp9_clear_system_state(); | 1960 vp9_clear_system_state(); |
| 1967 | 1961 |
| 1968 vpx_memset(&this_frame, 0, sizeof(FIRSTPASS_STATS)); | 1962 vpx_memset(&this_frame, 0, sizeof(FIRSTPASS_STATS)); |
| 1969 | 1963 |
| 1970 if (EOF == input_stats(cpi, &this_frame)) | 1964 if (EOF == input_stats(cpi, &this_frame)) |
| 1971 return; | 1965 return; |
| 1972 | 1966 |
| 1973 this_frame_error = this_frame.ssim_weighted_pred_err; | |
| 1974 this_frame_intra_error = this_frame.intra_error; | 1967 this_frame_intra_error = this_frame.intra_error; |
| 1975 this_frame_coded_error = this_frame.coded_error; | 1968 this_frame_coded_error = this_frame.coded_error; |
| 1976 | 1969 |
| 1977 start_pos = cpi->twopass.stats_in; | |
| 1978 | |
| 1979 // keyframe and section processing ! | 1970 // keyframe and section processing ! |
| 1980 if (cpi->twopass.frames_to_key == 0) { | 1971 if (cpi->twopass.frames_to_key == 0) { |
| 1981 // Define next KF group and assign bits to it | 1972 // Define next KF group and assign bits to it |
| 1982 vpx_memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); | 1973 vpx_memcpy(&this_frame_copy, &this_frame, sizeof(this_frame)); |
| 1983 find_next_key_frame(cpi, &this_frame_copy); | 1974 find_next_key_frame(cpi, &this_frame_copy); |
| 1984 } | 1975 } |
| 1985 | 1976 |
| 1986 // Is this a GF / ARF (Note that a KF is always also a GF) | 1977 // Is this a GF / ARF (Note that a KF is always also a GF) |
| 1987 if (cpi->frames_till_gf_update_due == 0) { | 1978 if (cpi->frames_till_gf_update_due == 0) { |
| 1988 // Define next gf group and assign bits to it | 1979 // Define next gf group and assign bits to it |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 adjust_active_maxq(cpi->active_worst_quality, tmp_q); | 2084 adjust_active_maxq(cpi->active_worst_quality, tmp_q); |
| 2094 } | 2085 } |
| 2095 | 2086 |
| 2096 cpi->twopass.frames_to_key--; | 2087 cpi->twopass.frames_to_key--; |
| 2097 | 2088 |
| 2098 // Update the total stats remaining sturcture | 2089 // Update the total stats remaining sturcture |
| 2099 subtract_stats(cpi->twopass.total_left_stats, &this_frame); | 2090 subtract_stats(cpi->twopass.total_left_stats, &this_frame); |
| 2100 } | 2091 } |
| 2101 | 2092 |
| 2102 | 2093 |
| 2103 static BOOL test_candidate_kf(VP9_COMP *cpi, FIRSTPASS_STATS *last_frame, FIRST
PASS_STATS *this_frame, FIRSTPASS_STATS *next_frame) { | 2094 static int test_candidate_kf(VP9_COMP *cpi, |
| 2104 BOOL is_viable_kf = FALSE; | 2095 FIRSTPASS_STATS *last_frame, |
| 2096 FIRSTPASS_STATS *this_frame, |
| 2097 FIRSTPASS_STATS *next_frame) { |
| 2098 int is_viable_kf = FALSE; |
| 2105 | 2099 |
| 2106 // Does the frame satisfy the primary criteria of a key frame | 2100 // Does the frame satisfy the primary criteria of a key frame |
| 2107 // If so, then examine how well it predicts subsequent frames | 2101 // If so, then examine how well it predicts subsequent frames |
| 2108 if ((this_frame->pcnt_second_ref < 0.10) && | 2102 if ((this_frame->pcnt_second_ref < 0.10) && |
| 2109 (next_frame->pcnt_second_ref < 0.10) && | 2103 (next_frame->pcnt_second_ref < 0.10) && |
| 2110 ((this_frame->pcnt_inter < 0.05) || | 2104 ((this_frame->pcnt_inter < 0.05) || |
| 2111 ( | 2105 ( |
| 2112 ((this_frame->pcnt_inter - this_frame->pcnt_neutral) < .35) && | 2106 ((this_frame->pcnt_inter - this_frame->pcnt_neutral) < .35) && |
| 2113 ((this_frame->intra_error / DOUBLE_DIVIDE_CHECK(this_frame->coded_error
)) < 2.5) && | 2107 ((this_frame->intra_error / DOUBLE_DIVIDE_CHECK(this_frame->coded_error
)) < 2.5) && |
| 2114 ((fabs(last_frame->coded_error - this_frame->coded_error) / DOUBLE_DIVI
DE_CHECK(this_frame->coded_error) > .40) || | 2108 ((fabs(last_frame->coded_error - this_frame->coded_error) / DOUBLE_DIVI
DE_CHECK(this_frame->coded_error) > .40) || |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2518 cpi->output_frame_rate); | 2512 cpi->output_frame_rate); |
| 2519 } | 2513 } |
| 2520 | 2514 |
| 2521 // Note the total error score of the kf group minus the key frame itself | 2515 // Note the total error score of the kf group minus the key frame itself |
| 2522 cpi->twopass.kf_group_error_left = (int)(kf_group_err - kf_mod_err); | 2516 cpi->twopass.kf_group_error_left = (int)(kf_group_err - kf_mod_err); |
| 2523 | 2517 |
| 2524 // Adjust the count of total modified error left. | 2518 // Adjust the count of total modified error left. |
| 2525 // The count of bits left is adjusted elsewhere based on real coded frame size
s | 2519 // The count of bits left is adjusted elsewhere based on real coded frame size
s |
| 2526 cpi->twopass.modified_error_left -= kf_group_err; | 2520 cpi->twopass.modified_error_left -= kf_group_err; |
| 2527 } | 2521 } |
| OLD | NEW |