25 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 |
* |
* |
28 |
* $Id: plugin_2pass2.c,v 1.1.2.36 2004-01-22 20:54:31 edgomez Exp $ |
* $Id: plugin_2pass2.c,v 1.1.2.37 2004-01-31 14:51:56 syskin Exp $ |
29 |
* |
* |
30 |
*****************************************************************************/ |
*****************************************************************************/ |
31 |
|
|
35 |
/* forces second pass not to be bigger than first */ |
/* forces second pass not to be bigger than first */ |
36 |
#undef PASS_SMALLER |
#undef PASS_SMALLER |
37 |
|
|
38 |
|
/* automtically alters overflow controls (strength and improvement/degradation) |
39 |
|
to fight most common problems without user's knowladge */ |
40 |
|
#define SMART_OVERFLOW_SETTING |
41 |
|
|
42 |
#include <stdio.h> |
#include <stdio.h> |
43 |
#include <math.h> |
#include <math.h> |
44 |
#include <limits.h> |
#include <limits.h> |
212 |
* ToDo: description */ |
* ToDo: description */ |
213 |
double fq_error; |
double fq_error; |
214 |
|
|
215 |
|
int min_quant; /* internal minimal quant, prevents wrong quants from being used */ |
216 |
|
|
217 |
/*---------------------------------- |
/*---------------------------------- |
218 |
* Debug |
* Debug |
219 |
*--------------------------------*/ |
*--------------------------------*/ |
317 |
for (i=0; i<3; i++) rc->last_quant[i] = 0; |
for (i=0; i<3; i++) rc->last_quant[i] = 0; |
318 |
|
|
319 |
rc->fq_error = 0; |
rc->fq_error = 0; |
320 |
|
rc->min_quant = 1; |
321 |
|
|
322 |
/* Count frames (and intra frames) in the stats file, store the result into |
/* Count frames (and intra frames) in the stats file, store the result into |
323 |
* the rc structure */ |
* the rc structure */ |
714 |
data->quant = data->max_quant[s->type-1]; |
data->quant = data->max_quant[s->type-1]; |
715 |
} |
} |
716 |
|
|
717 |
|
if (data->quant < rc->min_quant) data->quant = rc->min_quant; |
718 |
|
|
719 |
/* To avoid big quality jumps from frame to frame, we apply a "security" |
/* To avoid big quality jumps from frame to frame, we apply a "security" |
720 |
* rule that makes |last_quant - new_quant| <= 2. This rule only applies |
* rule that makes |last_quant - new_quant| <= 2. This rule only applies |
721 |
* to predicted frames (P and B) */ |
* to predicted frames (P and B) */ |
1128 |
/* Let's compute a linear scaler in order to perform curve scaling */ |
/* Let's compute a linear scaler in order to perform curve scaling */ |
1129 |
scaler = (double)(target - total_invariant) / (double)(rc->tot_weighted); |
scaler = (double)(target - total_invariant) / (double)(rc->tot_weighted); |
1130 |
|
|
1131 |
|
#ifdef SMART_OVERFLOW_SETTING |
1132 |
|
if (scaler > 0.9) { |
1133 |
|
rc->param.max_overflow_degradation *= 5; |
1134 |
|
rc->param.max_overflow_improvement *= 5; |
1135 |
|
rc->param.overflow_control_strength *= 3; |
1136 |
|
} else if (scaler > 0.6) { |
1137 |
|
rc->param.max_overflow_degradation *= 2; |
1138 |
|
rc->param.max_overflow_improvement *= 2; |
1139 |
|
rc->param.overflow_control_strength *= 2; |
1140 |
|
} else { |
1141 |
|
rc->min_quant = 2; |
1142 |
|
} |
1143 |
|
#endif |
1144 |
|
|
1145 |
/* Compute min frame lengths (for each frame type) according to the number |
/* Compute min frame lengths (for each frame type) according to the number |
1146 |
* of MBs. We sum all block type counters of frame 0, this gives us the |
* of MBs. We sum all block type counters of frame 0, this gives us the |
1147 |
* number of MBs. |
* number of MBs. |