--- plugin_2pass2.c 2003/11/09 20:49:21 1.1.2.24 +++ plugin_2pass2.c 2003/12/05 14:44:35 1.1.2.28 @@ -25,7 +25,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: plugin_2pass2.c,v 1.1.2.24 2003/11/09 20:49:21 edgomez Exp $ + * $Id: plugin_2pass2.c,v 1.1.2.28 2003/12/05 14:44:35 edgomez Exp $ * *****************************************************************************/ @@ -51,7 +51,7 @@ /* Keyframe settings */ #define DEFAULT_KFREDUCTION 20 -#define DEFAULT_MIN_KEY_INTERVAL 1 +#define DEFAULT_KFTHRESHOLD 1 /***************************************************************************** * Structures @@ -220,6 +220,7 @@ { switch(opt) { case XVID_PLG_INFO : + case XVID_PLG_FRAME : return 0; case XVID_PLG_CREATE : @@ -281,7 +282,7 @@ /* Keyframe settings */ _INIT(rc->param.kfreduction, DEFAULT_KFREDUCTION); - _INIT(rc->param.min_key_interval, DEFAULT_MIN_KEY_INTERVAL); + _INIT(rc->param.kfthreshold, DEFAULT_KFTHRESHOLD); #undef _INIT /* Initialize some stuff to zero */ @@ -466,23 +467,11 @@ /* IFrame user settings*/ if (s->type == XVID_TYPE_IVOP) { - /* Keyframe boosting -- All keyframes benefit from it */ dbytes += dbytes*rc->param.keyframe_boost / 100; - /* Applies keyframe penalties, but not the first frame */ - if (rc->KF_idx) { - int penalty_distance; - - /* Minimum keyframe distance penalties */ - penalty_distance = rc->param.min_key_interval; - penalty_distance -= rc->keyframe_locations[rc->KF_idx]; - penalty_distance += rc->keyframe_locations[rc->KF_idx-1]; - - /* Ah ah ! guilty keyframe, you're under arrest ! */ - if (penalty_distance > 0) - dbytes -= dbytes*penalty_distance*rc->param.kfreduction/100; - } +#if 0 /* ToDo: decide how to apply kfthresholding */ +#endif } else { /* P/S/B frames must reserve some bits for iframe boosting */ @@ -616,7 +605,7 @@ b_ref--; /* Compute the original quant */ - s->quant = 100*s->quant - data->bquant_offset; + s->quant = 2*(100*s->quant - data->bquant_offset); s->quant += data->bquant_ratio - 1; /* to avoid rouding issues */ s->quant = s->quant/data->bquant_ratio - b_ref->quant; } @@ -823,26 +812,24 @@ char *ptr; char type; - int fields, nouse; + int fields; lines++; /* We skip spaces */ ptr = skipspaces(line); - /* Skip coment lines */ - if(iscomment(ptr)) { + /* Skip coment lines or empty lines */ + if(iscomment(ptr) || *ptr == '\0') { free(line); continue; } /* Read the stat line from buffer */ - fields = sscanf(ptr, - "%c %d %d %d %d %d", - &type, &nouse, &nouse, &nouse, &nouse, &nouse); + fields = sscanf(ptr, "%c", &type); /* Valid stats files have at least 6 fields */ - if (fields == 6) { + if (fields == 1) { switch(type) { case 'i': case 'I': @@ -901,8 +888,8 @@ /* We skip spaces */ ptr = skipspaces(line); - /* Skip comment lines */ - if(iscomment(ptr)) { + /* Skip comment lines or empty lines */ + if(iscomment(ptr) || *ptr == '\0') { free(line); continue; } @@ -1192,7 +1179,7 @@ scaled_curve_apply_advanced_parameters(rc_2pass2_t * rc) { int i; - uint64_t ivop_boost_total; + int64_t ivop_boost_total; /* Reset the rate controller (per frame type) total byte counters */ for (i=0; i<3; i++) rc->tot_scaled_length[i] = 0; @@ -1215,23 +1202,13 @@ /* Some more work is needed for I frames */ if (s->type == XVID_TYPE_IVOP) { - int penalty_distance; int ivop_boost; /* Accumulate bytes needed for keyframe boosting */ ivop_boost = s->scaled_length*rc->param.keyframe_boost/100; - if (rc->KF_idx) { - /* Minimum keyframe distance penalties */ - penalty_distance = rc->param.min_key_interval; - penalty_distance -= rc->keyframe_locations[rc->KF_idx]; - penalty_distance += rc->keyframe_locations[rc->KF_idx-1]; - - /* Ah ah ! guilty keyframe, you're under arrest ! */ - if (penalty_distance > 0) - ivop_boost -= (s->scaled_length + ivop_boost)*penalty_distance*rc->param.kfreduction/100; - } - +#if 0 /* ToDo: decide how to apply kfthresholding */ +#endif /* If the frame size drops under the minimum length, then cap ivop_boost */ if (ivop_boost + s->scaled_length < rc->min_length[XVID_TYPE_IVOP-1]) ivop_boost = rc->min_length[XVID_TYPE_IVOP-1] - s->scaled_length; @@ -1261,7 +1238,7 @@ /* Compute the ratio described above * taxed_total = sum(0, n, tax*scaled_length) - * <=> taxed_total = tax.sum(0, n, tax*scaled_length) + * <=> taxed_total = tax.sum(0, n, scaled_length) * <=> tax = taxed_total / original_total */ rc->pb_iboost_tax_ratio = (rc->pb_iboost_tax_ratio - ivop_boost_total) / @@ -1278,7 +1255,7 @@ } else { rc->avg_length[i] = rc->tot_scaled_length[i]; - if (i == XVID_TYPE_IVOP) { + if (i == (XVID_TYPE_IVOP-1)) { /* I Frames total has to be added the boost total */ rc->avg_length[i] += ivop_boost_total; } else {