--- plugin_2pass2.c 2004/06/12 13:53:19 1.5 +++ plugin_2pass2.c 2010/03/09 10:00:14 1.9 @@ -1,15 +1,15 @@ /****************************************************************************** * - * XviD Bit Rate Controller Library + * Xvid Bit Rate Controller Library * - VBR 2 pass bitrate controller implementation - * - * Copyright (C) 2002 Foxer + * Copyright (C) 2002 Benjamin Lambert * 2002 Dirk Knop * 2002-2003 Edouard Gomez * 2003 Pete Ross * * This curve treatment algorithm is the one originally implemented by Foxer - * and tuned by Dirk Knop for the XviD vfw frontend. + * and tuned by Dirk Knop for the Xvid vfw frontend. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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.5 2004/06/12 13:53:19 edgomez Exp $ + * $Id: plugin_2pass2.c,v 1.9 2010/03/09 10:00:14 Isibaar Exp $ * *****************************************************************************/ @@ -219,6 +219,8 @@ *--------------------------------*/ double desired_total; double real_total; + + int scaled_frames; } rc_2pass2_t; @@ -344,6 +346,7 @@ rc->fq_error = 0; rc->min_quant = 1; + rc->scaled_frames = 0; /* Count frames (and intra frames) in the stats file, store the result into * the rc structure */ @@ -457,8 +460,8 @@ if (rc->param.vbv_size==0) { rc->param.vbv_size = 3145728; rc->param.vbv_initial = 2359296; - rc->param.vbv_maxrate = 4000000; - rc->param.vbv_peakrate = 10000000; + rc->param.vbv_maxrate = 4854000; + rc->param.vbv_peakrate = 8000000; } #endif @@ -794,8 +797,10 @@ rc->last_quant[s->type-1] = data->quant; /* Don't forget to force 1st pass frame type ;-) */ - data->type = s->type; + if (rc->scaled_frames) + data->type = s->type; + rc->scaled_frames++; return 0; } @@ -857,7 +862,7 @@ rc->KFoverflow -= rc->KFoverflow_partial; } - rc->overflow += (s->error = s->desired_length - data->length); + s->error = s->desired_length - data->length; rc->real_total += data->length; DPRINTF(XVID_DEBUG_RC, "[xvid rc] -- frame:%d type:%c quant:%d stats:%d scaled:%d desired:%d actual:%d error:%d overflow:%.2f\n", @@ -954,7 +959,8 @@ /* We are done with the file */ fclose(f); - return(0); + if (!rc->num_keyframes) return (-1); /* No keyframes? Then something is wrong */ + else return(0); } /* open stats file(s) and read into rc->stats array */ @@ -1461,8 +1467,8 @@ * typical values from DivX Home Theater profile: * vbv_size= 384*1024 (384kB) * vbv_initial= 288*1024 (75% fill) - * maxrate= 4000000 (4MBps) - * peakrate= 10000000 (10MBps) + * maxrate= 4854000 (4.854MBps) + * peakrate= 8000000 (8MBps) * * PAL: offset3s = 75 (3 seconds of 25fps) * NTSC: offset3s = 90 (3 seconds of 29.97fps) or 72 (3 seconds of 23.976fps) @@ -1490,7 +1496,8 @@ if (i>=offset3s) bytes3s -= rc->stats[i-offset3s].scaled_length; - if (8.f*bytes3s > 3*peakrate) + /* ignore peakrate constraint if peakrate is <= 0.f */ + if (peakrate>0.f && 8.f*bytes3s > 3*peakrate) return(VBV_PEAKRATE); /* update vbv fill level */