[cvs] / xvidcore / src / plugins / plugin_2pass2.c Repository:
ViewVC logotype

Diff of /xvidcore/src/plugins/plugin_2pass2.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7, Sun Mar 27 03:59:42 2005 UTC revision 1.10.2.1, Tue Dec 28 19:19:57 2010 UTC
# Line 1  Line 1 
1  /******************************************************************************  /******************************************************************************
2   *   *
3   *  XviD Bit Rate Controller Library   *  Xvid Bit Rate Controller Library
4   *  - VBR 2 pass bitrate controller implementation -   *  - VBR 2 pass bitrate controller implementation -
5   *   *
6   *  Copyright (C)      2002 Foxer <email?>   *  Copyright (C)      2002 Benjamin Lambert <foxer@hotmail.com>
7   *                     2002 Dirk Knop <dknop@gwdg.de>   *                     2002 Dirk Knop <dknop@gwdg.de>
8   *                2002-2003 Edouard Gomez <ed.gomez@free.fr>   *                2002-2003 Edouard Gomez <ed.gomez@free.fr>
9   *                     2003 Pete Ross <pross@xvid.org>   *                     2003 Pete Ross <pross@xvid.org>
10   *   *
11   *  This curve treatment algorithm is the one originally implemented by Foxer   *  This curve treatment algorithm is the one originally implemented by Foxer
12   *  and tuned by Dirk Knop for the XviD vfw frontend.   *  and tuned by Dirk Knop for the Xvid vfw frontend.
13   *   *
14   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
15   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 219  Line 219 
219           *--------------------------------*/           *--------------------------------*/
220          double desired_total;          double desired_total;
221          double real_total;          double real_total;
222    
223            int scaled_frames;
224  } rc_2pass2_t;  } rc_2pass2_t;
225    
226    
# Line 344  Line 346 
346    
347          rc->fq_error = 0;          rc->fq_error = 0;
348          rc->min_quant = 1;          rc->min_quant = 1;
349            rc->scaled_frames = 0;
350    
351          /* 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
352           * the rc structure */           * the rc structure */
# Line 464  Line 467 
467    
468          /* vbv_size==0 switches VBV check off */          /* vbv_size==0 switches VBV check off */
469          if (rc->param.vbv_size > 0)  {          if (rc->param.vbv_size > 0)  {
470                  const double fps = (double)create->fbase/(double)create->fincr;                  const float fps = (float)((double)create->fbase/(double)create->fincr);
471                  int status = check_curve_for_vbv_compliancy(rc, fps);                  int status = check_curve_for_vbv_compliancy(rc, fps);
472    
473                  if (status) {                  if (status) {
# Line 794  Line 797 
797                  rc->last_quant[s->type-1] = data->quant;                  rc->last_quant[s->type-1] = data->quant;
798    
799          /* Don't forget to force 1st pass frame type ;-) */          /* Don't forget to force 1st pass frame type ;-) */
800            if (rc->scaled_frames)
801          data->type = s->type;          data->type = s->type;
802    
803            rc->scaled_frames++;
804          return 0;          return 0;
805  }  }
806    
# Line 954  Line 959 
959          /* We are done with the file */          /* We are done with the file */
960          fclose(f);          fclose(f);
961    
962          return(0);          if (!rc->num_keyframes) return (-1); /* No keyframes? Then something is wrong */
963            else return(0);
964  }  }
965    
966  /* open stats file(s) and read into rc->stats array */  /* open stats file(s) and read into rc->stats array */
# Line 1355  Line 1361 
1361                  if (rc->count[i] == 0 || rc->pb_iboost_tax_ratio == 0) {                  if (rc->count[i] == 0 || rc->pb_iboost_tax_ratio == 0) {
1362                          rc->avg_length[i] = 1;                          rc->avg_length[i] = 1;
1363                  } else {                  } else {
1364                          rc->avg_length[i] = rc->tot_scaled_length[i];                          rc->avg_length[i] = (double)rc->tot_scaled_length[i];
1365    
1366                          if (i == (XVID_TYPE_IVOP-1)) {                          if (i == (XVID_TYPE_IVOP-1)) {
1367                                  /* I Frames total has to be added the boost total */                                  /* I Frames total has to be added the boost total */
# Line 1440  Line 1446 
1446   * aren't...)   * aren't...)
1447   *   *
1448   * DivX profiles have 2 criteria: VBV as in MPEG standard   * DivX profiles have 2 criteria: VBV as in MPEG standard
1449   *                                a limit on peak bitrate for any 3 seconds   *                                a limit on peak bitrate for any 1 second
1450   *   *
1451   * But if VBV is fulfilled, peakrate is automatically fulfilled in any profile   * But if VBV is fulfilled, peakrate is automatically fulfilled in any profile
1452   * define so far, so we check for it (for completeness) but correct only VBV   * defined so far, so we check for it (for completeness) but correct only VBV
1453   *   *
1454   *****************************************************************************/   *****************************************************************************/
1455    
1456  #define VBV_COMPLIANT 0  #define VBV_COMPLIANT 0
1457  #define VBV_UNDERFLOW 1 /* video buffer runs empty */  #define VBV_UNDERFLOW 1 /* video buffer runs empty */
1458  #define VBV_OVERFLOW 2  /* doesn't exist for VBR encoding */  #define VBV_OVERFLOW 2  /* doesn't exist for VBR encoding */
1459  #define VBV_PEAKRATE 4  /* peak bitrate (within 3s) violated */  #define VBV_PEAKRATE  4  /* peak bitrate (within 1s) violated */
1460    
1461  static int  static int
1462  check_curve_for_vbv_compliancy(rc_2pass2_t * rc, const float fps)  check_curve_for_vbv_compliancy(rc_2pass2_t * rc, const float fps)
# Line 1458  Line 1464 
1464          /* We do all calculations in float, for higher accuracy,          /* We do all calculations in float, for higher accuracy,
1465           * and in bytes for convenience.           * and in bytes for convenience.
1466           *           *
1467           * typical values from DivX Home Theater profile:           * typical values from e.g. Home profile:
1468           *  vbv_size= 384*1024 (384kB)           *  vbv_size= 384*1024 (384kB)
1469           *  vbv_initial= 288*1024 (75% fill)           *  vbv_initial= 288*1024 (75% fill)
1470           *  maxrate= 4854000 (4.854MBps)           *  maxrate= 4854000 (4.854MBps)
1471           *  peakrate= 8000000 (8MBps)           *  peakrate= 8000000 (8MBps)
1472           *           *
1473           *  PAL: offset3s = 75 (3 seconds of 25fps)           *  PAL: offset1s = 25 (1 second of 25fps)
1474           *  NTSC: offset3s = 90 (3 seconds of 29.97fps) or 72 (3 seconds of 23.976fps)           *  NTSC: offset1s = 30 (1 second of 29.97fps) or 24 (1 second of 23.976fps)
1475           */           */
1476    
1477          const float vbv_size = (float)rc->param.vbv_size/8.f;          const float vbv_size = (float)rc->param.vbv_size/8.f;
# Line 1476  Line 1482 
1482          const float peakrate = (float)rc->param.vbv_peakrate;          const float peakrate = (float)rc->param.vbv_peakrate;
1483          const float r0 = (int)(maxrate/fps+0.5)/8.f;          const float r0 = (int)(maxrate/fps+0.5)/8.f;
1484    
1485          int bytes3s = 0;          int bytes1s = 0;
1486          int offset3s = (int)(3.f*fps+0.5);          int offset1s = (int)(1.f*fps+0.5);
1487          int i;          int i;
1488    
1489          /* 1Gbit should be enough to inuitialize the vbvmin          /* 1Gbit should be enough to inuitialize the vbvmin
# Line 1485  Line 1491 
1491          vbvmin = 1000*1000*1000;          vbvmin = 1000*1000*1000;
1492    
1493          for (i=0; i<rc->num_frames; i++) {          for (i=0; i<rc->num_frames; i++) {
1494                  /* DivX 3s peak bitrate check  */                  /* DivX 1s peak bitrate check  */
1495                  bytes3s += rc->stats[i].scaled_length;                  bytes1s += rc->stats[i].scaled_length;
1496                  if (i>=offset3s)                  if (i>=offset1s)
1497                          bytes3s -= rc->stats[i-offset3s].scaled_length;                          bytes1s -= rc->stats[i-offset1s].scaled_length;
1498    
1499      /* ignore peakrate constraint if peakrate is <= 0.f */      /* ignore peakrate constraint if peakrate is <= 0.f */
1500                  if (peakrate>0.f && 8.f*bytes3s > 3*peakrate)                  if (peakrate>0.f && 8.f*bytes1s > peakrate)
1501                          return(VBV_PEAKRATE);                          return(VBV_PEAKRATE);
1502    
1503                  /* update vbv fill level */                  /* update vbv fill level */
# Line 1538  Line 1544 
1544          const float vbv_size = (float)rc->param.vbv_size/8.f;          const float vbv_size = (float)rc->param.vbv_size/8.f;
1545          const float vbv_initial = (float)rc->param.vbv_initial/8.f;          const float vbv_initial = (float)rc->param.vbv_initial/8.f;
1546    
1547          const float maxrate = 0.9*rc->param.vbv_maxrate;          const float maxrate = 0.9f*rc->param.vbv_maxrate;
1548          const float vbv_low = 0.10f*vbv_size;          const float vbv_low = 0.10f*vbv_size;
1549          const float r0 = (int)(maxrate/fps+0.5)/8.f;          const float r0 = (int)(maxrate/fps+0.5)/8.f;
1550    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.10.2.1

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4