--- branches/dev-api-4/xvidcore/src/plugins/plugin_2pass2.c 2003/11/19 15:59:41 1219 +++ branches/dev-api-4/xvidcore/src/plugins/plugin_2pass2.c 2003/12/08 12:38:04 1247 @@ -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.27 2003-11-19 15:59:41 edgomez Exp $ + * $Id: plugin_2pass2.c,v 1.1.2.30 2003-12-08 12:38:04 syskin Exp $ * *****************************************************************************/ @@ -51,7 +51,7 @@ /* Keyframe settings */ #define DEFAULT_KFREDUCTION 20 -#define DEFAULT_MIN_KEY_INTERVAL 1 +#define DEFAULT_KFTHRESHOLD 1 /***************************************************************************** * Structures @@ -282,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 */ @@ -333,7 +333,7 @@ /* Compute the target filesize */ if (rc->param.bitrate<0) { /* if negative, bitrate equals the target (in kbytes) */ - rc->target = (-rc->param.bitrate) * 1024; + rc->target = ((uint64_t)(-rc->param.bitrate)) * 1024; } else if (rc->num_frames < create->fbase/create->fincr) { /* Source sequence is less than 1s long, we do as if it was 1s long */ rc->target = rc->param.bitrate / 8; @@ -436,7 +436,14 @@ if (data->quant > 0) return(0); - /* Second case: We are in a Quant zone */ + /* Second case: insufficent stats data */ + if (data->frame_num >= rc->num_frames) { + DPRINTF(XVID_DEBUG_RC,"[xvid rc] -- stats file too short (now processing frame %d)", + data->frame_num); + return(0); + } + + /* Third case: We are in a Quant zone */ if (s->zone_mode == XVID_ZONE_QUANT) { rc->fq_error += s->weight; data->quant = (int)rc->fq_error; @@ -447,9 +454,6 @@ return(0); } - /* Third case: insufficent stats data */ - if (data->frame_num >= rc->num_frames) - return(0); /*************************************************************************/ /*************************************************************************/ @@ -467,23 +471,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 */ @@ -1191,7 +1183,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; @@ -1214,23 +1206,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; @@ -1260,7 +1242,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) /