Merge remote branch 'internal/upstream' into HEAD

This commit is contained in:
John Koleszar 2010-11-23 00:05:05 -05:00
commit 849763d05f
3 changed files with 73 additions and 43 deletions

View File

@ -1145,6 +1145,7 @@ void vp8_init_second_pass(VP8_COMP *cpi)
cpi->output_frame_rate = cpi->oxcf.frame_rate;
cpi->bits_left = (long long)(cpi->total_stats->duration * cpi->oxcf.target_bandwidth / 10000000.0) ;
cpi->bits_left -= (long long)(cpi->total_stats->duration * two_pass_min_rate / 10000000.0);
cpi->clip_bits_total = cpi->bits_left;
vp8_avg_stats(cpi->total_stats);
@ -1173,17 +1174,25 @@ void vp8_init_second_pass(VP8_COMP *cpi)
{
start_pos = cpi->stats_in; // Note starting "file" position
cpi->modified_total_error_left = 0.0;
cpi->modified_error_total = 0.0;
cpi->modified_error_used = 0.0;
while (vp8_input_stats(cpi, &this_frame) != EOF)
{
cpi->modified_total_error_left += calculate_modified_err(cpi, &this_frame);
cpi->modified_error_total += calculate_modified_err(cpi, &this_frame);
}
cpi->modified_error_left = cpi->modified_error_total;
reset_fpf_position(cpi, start_pos); // Reset file position
}
// Calculate the clip target modified bits per error
// The observed bpe starts as the same number.
cpi->clip_bpe = cpi->bits_left /
DOUBLE_DIVIDE_CHECK(cpi->modified_error_total);
cpi->observed_bpe = cpi->clip_bpe;
cpi->fp_motion_map_stats = (unsigned char *)cpi->stats_in;
}
@ -1585,6 +1594,9 @@ static void define_gf_group(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
// Reset the file position
reset_fpf_position(cpi, start_pos);
// Update the record of error used so far (only done once per gf group)
cpi->modified_error_used += gf_group_err;
// Assign bits to the arf or gf.
{
int Boost;
@ -1882,6 +1894,16 @@ void vp8_second_pass(VP8_COMP *cpi)
// Is this a GF / ARF (Note that a KF is always also a GF)
if (cpi->frames_till_gf_update_due == 0)
{
// Update monitor of the bits per error observed so far.
// Done once per gf group based on what has gone before
// so do nothing if this is the first frame.
if (cpi->common.current_video_frame > 0)
{
cpi->observed_bpe =
(double)(cpi->clip_bits_total - cpi->bits_left) /
cpi->modified_error_used;
}
// Define next gf group and assign bits to it
vpx_memcpy(&this_frame_copy, &this_frame, sizeof(this_frame));
define_gf_group(cpi, &this_frame_copy);
@ -2196,7 +2218,7 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
}
// Calculate the number of bits that should be assigned to the kf group.
if ((cpi->bits_left > 0) && ((int)cpi->modified_total_error_left > 0))
if ((cpi->bits_left > 0) && ((int)cpi->modified_error_left > 0))
{
// Max for a single normal frame (not key frame)
int max_bits = frame_max_bits(cpi);
@ -2208,7 +2230,7 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
// complexity of the section
cpi->kf_group_bits = (long long)( cpi->bits_left *
( kf_group_err /
cpi->modified_total_error_left ));
cpi->modified_error_left ));
// Clip based on maximum per frame rate defined by the user.
max_grp_bits = (long long)max_bits * (long long)cpi->frames_to_key;
@ -2461,7 +2483,7 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
double alt_kf_grp_bits =
((double)cpi->bits_left *
(kf_mod_err * (double)cpi->frames_to_key) /
DOUBLE_DIVIDE_CHECK(cpi->modified_total_error_left));
DOUBLE_DIVIDE_CHECK(cpi->modified_error_left));
alt_kf_bits = (int)((double)kf_boost *
(alt_kf_grp_bits / (double)allocation_chunks));
@ -2479,7 +2501,7 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
alt_kf_bits =
(int)((double)cpi->bits_left *
(kf_mod_err /
DOUBLE_DIVIDE_CHECK(cpi->modified_total_error_left)));
DOUBLE_DIVIDE_CHECK(cpi->modified_error_left)));
if (alt_kf_bits > cpi->kf_bits)
{
@ -2499,7 +2521,7 @@ void vp8_find_next_key_frame(VP8_COMP *cpi, FIRSTPASS_STATS *this_frame)
// Adjust the count of total modified error left.
// The count of bits left is adjusted elsewhere based on real coded frame sizes
cpi->modified_total_error_left -= kf_group_err;
cpi->modified_error_left -= kf_group_err;
if (cpi->oxcf.allow_spatial_resampling)
{

View File

@ -473,11 +473,17 @@ typedef struct
double start_tot_err_left;
double min_error;
double modified_total_error_left;
double modified_error_total;
double modified_error_used;
double modified_error_left;
double clip_bpe;
double observed_bpe;
double avg_iiratio;
int target_bandwidth;
long long bits_left;
long long clip_bits_total;
FIRSTPASS_STATS *total_stats;
FIRSTPASS_STATS *this_frame_stats;
FIRSTPASS_STATS *stats_in, *stats_in_end;

View File

@ -45,46 +45,48 @@ extern int inter_b_modes[10];
// Bits Per MB at different Q (Multiplied by 512)
#define BPER_MB_NORMBITS 9
// Work in progress recalibration of baseline rate tables based on
// the assumption that bits per mb is inversely proportional to the
// quantizer value.
const int vp8_bits_per_mb[2][QINDEX_RANGE] =
{
// (Updated 19 March 08) Baseline estimate of INTRA-frame Bits Per MB at each Q:
// Intra case 450000/Qintra
{
674781, 606845, 553905, 524293, 500428, 452540, 435379, 414719,
390970, 371082, 359416, 341807, 336957, 317263, 303724, 298402,
285688, 275237, 268455, 262560, 256038, 248734, 241087, 237615,
229247, 225211, 219112, 213920, 211559, 202714, 198482, 193401,
187866, 183453, 179212, 175965, 171852, 167235, 163972, 160560,
156032, 154349, 151390, 148725, 145708, 142311, 139981, 137700,
134084, 131863, 129746, 128498, 126077, 123461, 121290, 117782,
114883, 112332, 108410, 105685, 103434, 101192, 98587, 95959,
94059, 92017, 89970, 87936, 86142, 84801, 82736, 81106,
79668, 78135, 76641, 75103, 73943, 72693, 71401, 70098,
69165, 67901, 67170, 65987, 64923, 63534, 62378, 61302,
59921, 58941, 57844, 56782, 55960, 54973, 54257, 53454,
52230, 50938, 49962, 49190, 48288, 47270, 46738, 46037,
45020, 44027, 43216, 42287, 41594, 40702, 40081, 39414,
38282, 37627, 36987, 36375, 35808, 35236, 34710, 34162,
33659, 33327, 32751, 32384, 31936, 31461, 30982, 30582,
1125000,900000, 750000, 642857, 562500, 500000, 450000, 450000,
409090, 375000, 346153, 321428, 300000, 281250, 264705, 264705,
250000, 236842, 225000, 225000, 214285, 214285, 204545, 204545,
195652, 195652, 187500, 180000, 180000, 173076, 166666, 160714,
155172, 150000, 145161, 140625, 136363, 132352, 128571, 125000,
121621, 121621, 118421, 115384, 112500, 109756, 107142, 104651,
102272, 100000, 97826, 97826, 95744, 93750, 91836, 90000,
88235, 86538, 84905, 83333, 81818, 80357, 78947, 77586,
76271, 75000, 73770, 72580, 71428, 70312, 69230, 68181,
67164, 66176, 65217, 64285, 63380, 62500, 61643, 60810,
60000, 59210, 59210, 58441, 57692, 56962, 56250, 55555,
54878, 54216, 53571, 52941, 52325, 51724, 51136, 50561,
49450, 48387, 47368, 46875, 45918, 45000, 44554, 44117,
43269, 42452, 41666, 40909, 40178, 39473, 38793, 38135,
36885, 36290, 35714, 35156, 34615, 34090, 33582, 33088,
32608, 32142, 31468, 31034, 30405, 29801, 29220, 28662,
},
// (Updated 19 March 08) Baseline estimate of INTER-frame Bits Per MB at each Q:
// Inter case 285000/Qinter
{
497401, 426316, 372064, 352732, 335763, 283921, 273848, 253321,
233181, 217727, 210030, 196685, 194836, 178396, 167753, 164116,
154119, 146929, 142254, 138488, 133591, 127741, 123166, 120226,
114188, 111756, 107882, 104749, 102522, 96451, 94424, 90905,
87286, 84931, 82111, 80534, 77610, 74700, 73037, 70715,
68006, 67235, 65374, 64009, 62134, 60180, 59105, 57691,
55509, 54512, 53318, 52693, 51194, 49840, 48944, 46980,
45668, 44177, 42348, 40994, 39859, 38889, 37717, 36391,
35482, 34622, 33795, 32756, 32002, 31492, 30573, 29737,
29152, 28514, 27941, 27356, 26859, 26329, 25874, 25364,
24957, 24510, 24290, 23689, 23380, 22845, 22481, 22066,
21587, 21219, 20880, 20452, 20260, 19926, 19661, 19334,
18915, 18391, 18046, 17833, 17441, 17105, 16888, 16729,
16383, 16023, 15706, 15442, 15222, 14938, 14673, 14452,
14005, 13807, 13611, 13447, 13223, 13102, 12963, 12801,
12627, 12534, 12356, 12228, 12056, 11907, 11746, 11643,
712500, 570000, 475000, 407142, 356250, 316666, 285000, 259090,
237500, 219230, 203571, 190000, 178125, 167647, 158333, 150000,
142500, 135714, 129545, 123913, 118750, 114000, 109615, 105555,
101785, 98275, 95000, 91935, 89062, 86363, 83823, 81428,
79166, 77027, 75000, 73076, 71250, 69512, 67857, 66279,
64772, 63333, 61956, 60638, 59375, 58163, 57000, 55882,
54807, 53773, 52777, 51818, 50892, 50000, 49137, 47500,
45967, 44531, 43181, 41911, 40714, 39583, 38513, 37500,
36538, 35625, 34756, 33928, 33139, 32386, 31666, 30978,
30319, 29687, 29081, 28500, 27941, 27403, 26886, 26388,
25909, 25446, 25000, 24568, 23949, 23360, 22800, 22265,
21755, 21268, 20802, 20357, 19930, 19520, 19127, 18750,
18387, 18037, 17701, 17378, 17065, 16764, 16473, 16101,
15745, 15405, 15079, 14766, 14467, 14179, 13902, 13636,
13380, 13133, 12895, 12666, 12445, 12179, 11924, 11632,
11445, 11220, 11003, 10795, 10594, 10401, 10215, 10035,
}
};