--- branches/dev-api-4/xvidcore/src/plugins/plugin_2pass1.c 2003/04/08 14:01:35 977 +++ branches/dev-api-4/xvidcore/src/plugins/plugin_2pass1.c 2003/07/29 23:02:34 1105 @@ -1,28 +1,28 @@ /****************************************************************************** * - * XviD Bit Rate Controller Library - * - VBR 2 pass bitrate controler implementation - + * XviD Bit Rate Controller Library + * - VBR 2 pass bitrate controler implementation - * - * Copyright (C) 2002 Edouard Gomez + * Copyright (C) 2002-2003 Edouard Gomez * - * The curve treatment algorithm is the one implemented by Foxer and - * Dirk Knop for the XviD vfw dynamic library. + * The curve treatment algorithm is the one implemented by Foxer and + * Dirk Knop for the XviD vfw dynamic library. * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License + * 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_2pass1.c,v 1.1.2.2 2003-04-08 14:01:09 suxen_drol Exp $ + * $Id: plugin_2pass1.c,v 1.1.2.6 2003-07-29 23:02:34 edgomez Exp $ * *****************************************************************************/ @@ -36,6 +36,8 @@ typedef struct { FILE * stat_file; + + double fq_error; } rc_2pass1_t; @@ -46,7 +48,8 @@ rc_2pass1_t * rc; /* check filename */ - if (param->filename == NULL || param->filename[0] == '\0') + if ((param->filename == NULL) || + (param->filename != NULL && param->filename[0] == '\0')) return XVID_ERR_FAIL; /* allocate context struct */ @@ -63,10 +66,14 @@ /* * The File Header */ - /* fprintf(rc->stat_file, "# XviD 2pass stat file\n"); +#if 0 + fprintf(rc->stat_file, "# XviD 2pass stat file\n"); fprintf(rc->stat_file, "version %i.%i.%i\n",XVID_MAJOR(XVID_VERSION), XVID_MINOR(XVID_VERSION), XVID_PATCH(XVID_VERSION)); fprintf(rc->stat_file, "start\n"); - fprintf(rc->stat_file, "type quantizer length kblocks mblocks ublocks\n"); */ + fprintf(rc->stat_file, "type quantizer length kblocks mblocks ublocks\n"); +#endif + + rc->fq_error = 0; *handle = rc; return(0); @@ -75,7 +82,6 @@ static int rc_2pass1_destroy(rc_2pass1_t * rc, xvid_plg_destroy_t * destroy) { - //fprintf(rc->stat_file, "stop\n"); fclose(rc->stat_file); free(rc); @@ -85,8 +91,16 @@ static int rc_2pass1_before(rc_2pass1_t * rc, xvid_plg_data_t * data) { - data->quant = 2; - data->type = XVID_TYPE_AUTO; + if (data->quant <= 0) { + if (data->zone && data->zone->mode == XVID_ZONE_QUANT) { + rc->fq_error += (double)data->zone->increment / (double)data->zone->base; + data->quant = (int)rc->fq_error; + rc->fq_error -= data->quant; + + }else { + data->quant = 2; + } + } return 0; }