[svn] / branches / dev-api-4 / xvidcore / src / plugins / plugin_2pass2.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/plugins/plugin_2pass2.c

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

revision 1038, Thu May 22 16:36:07 2003 UTC revision 1040, Thu May 22 22:17:44 2003 UTC
# Line 25  Line 25 
25   * along with this program; if not, write to the Free Software   * along with this program; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *   *
28   * $Id: plugin_2pass2.c,v 1.1.2.8 2003-05-22 16:36:07 edgomez Exp $   * $Id: plugin_2pass2.c,v 1.1.2.9 2003-05-22 22:17:44 edgomez Exp $
29   *   *
30   *****************************************************************************/   *****************************************************************************/
31    
32  #include <stdio.h>  #include <stdio.h>
33  #include <math.h>  #include <math.h>
34    #include <limits.h>
35    
36  #define RAD2DEG 57.295779513082320876798154814105  #define RAD2DEG 57.295779513082320876798154814105
37  #define DEG2RAD 0.017453292519943295769236907684886  #define DEG2RAD 0.017453292519943295769236907684886
# Line 194  Line 195 
195  static void print_stats(rc_2pass2_t * rc)  static void print_stats(rc_2pass2_t * rc)
196  {  {
197      int i;      int i;
198        DPRINTF(XVID_DEBUG_RC, "type quant length scaled_length\n");
199      for (i = 0; i < rc->num_frames; i++) {      for (i = 0; i < rc->num_frames; i++) {
200          stat_t * s = &rc->stats[i];          stat_t * s = &rc->stats[i];
201          DPRINTF(XVID_DEBUG_RC, "%i %i %i %i\n", s->type, s->quant, s->length, s->scaled_length);          DPRINTF(XVID_DEBUG_RC, "%d %d %d %d\n", s->type, s->quant, s->length, s->scaled_length);
202      }      }
203  }  }
204  #endif  #endif
# Line 206  Line 208 
208      - set keyframes_locations      - set keyframes_locations
209  */  */
210    
211  void pre_process0(rc_2pass2_t * rc)  static void
212    pre_process0(rc_2pass2_t * rc)
213  {  {
214      int i,j;      int i,j;
215    
# Line 214  Line 217 
217          rc->count[i]=0;          rc->count[i]=0;
218          rc->tot_length[i] = 0;          rc->tot_length[i] = 0;
219          rc->last_quant[i] = 0;          rc->last_quant[i] = 0;
220                    rc->min_length[i] = INT_MAX;
221      }      }
222    
223            rc->max_length = INT_MIN;
224    
225      for (i=j=0; i<rc->num_frames; i++) {      for (i=j=0; i<rc->num_frames; i++) {
226          stat_t * s = &rc->stats[i];          stat_t * s = &rc->stats[i];
227    
228          rc->count[s->type-1]++;          rc->count[s->type-1]++;
229          rc->tot_length[s->type-1] += s->length;          rc->tot_length[s->type-1] += s->length;
230    
231          if (i == 0 || s->length < rc->min_length[s->type-1]) {          if (s->length < rc->min_length[s->type-1]) {
232              rc->min_length[s->type-1] = s->length;              rc->min_length[s->type-1] = s->length;
233          }          }
234    
235          if (i == 0 || s->length > rc->max_length) {          if (s->length > rc->max_length) {
236              rc->max_length = s->length;              rc->max_length = s->length;
237          }          }
238    
# Line 243  Line 249 
249           * frame to appear in the keyframe locations array.           * frame to appear in the keyframe locations array.
250           */           */
251      rc->keyframe_locations[j] = i;      rc->keyframe_locations[j] = i;
252    
253            DPRINTF(XVID_DEBUG_RC, "Min 1st pass IFrame length: %d\n", rc->min_length[0]);
254            DPRINTF(XVID_DEBUG_RC, "Min 1st pass PFrame length: %d\n", rc->min_length[1]);
255            DPRINTF(XVID_DEBUG_RC, "Min 1st pass BFrame length: %d\n", rc->min_length[2]);
256  }  }
257    
258    
259  /* calculate zone weight "center" */  /* calculate zone weight "center" */
260    
261  static void zone_process(rc_2pass2_t *rc, const xvid_plg_create_t * create)  static void
262    zone_process(rc_2pass2_t *rc, const xvid_plg_create_t * create)
263  {  {
264      int i,j;      int i,j;
265      int n = 0;      int n = 0;
# Line 304  Line 315 
315    
316  /* scale the curve */  /* scale the curve */
317    
318  static void internal_scale(rc_2pass2_t *rc)  static void
319    internal_scale(rc_2pass2_t *rc)
320  {  {
321          int64_t target  = rc->target - rc->tot_quant;          int64_t target  = rc->target - rc->tot_quant;
322          int64_t pass1_length = rc->tot_length[0] + rc->tot_length[1] + rc->tot_length[2] - rc->tot_quant;          int64_t pass1_length = rc->tot_length[0] + rc->tot_length[1] + rc->tot_length[2] - rc->tot_quant;
# Line 313  Line 325 
325          int i;          int i;
326    
327    
328          /* perform an initial scale pass.          /*
329             if a frame size is scaled underneath our hardcoded minimums, then we force the           * Perform an initial scale pass.
330             frame size to the minimum, and deduct the original & scaled frmae length from the           * if a frame size is scaled underneath our hardcoded minimums, then we
331             original and target total lengths */           * force the frame size to the minimum, and deduct the original & scaled
332             * frame length from the original and target total lengths
333             */
334    
335          min_size[0] = ((rc->stats[0].blks[0]*22) + 240) / 8;          min_size[0] = ((rc->stats[0].blks[0]*22) + 240) / 8;
336          min_size[1] = (rc->stats[0].blks[0] + 88) / 8;          min_size[1] = (rc->stats[0].blks[0] + 88) / 8;
# Line 329  Line 343 
343          scaler = 1.0;          scaler = 1.0;
344          }          }
345    
346      DPRINTF(XVID_DEBUG_RC, "target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)pass1_length, scaler);      DPRINTF(XVID_DEBUG_RC,
347                            "Before any correction: target=%i, tot_length=%i, scaler=%f\n",
348                            (int)target, (int)pass1_length, scaler);
349    
350          for (i=0; i<rc->num_frames; i++) {          for (i=0; i<rc->num_frames; i++) {
351                  stat_t * s = &rc->stats[i];                  stat_t * s = &rc->stats[i];
# Line 355  Line 371 
371                  scaler = 1.0;                  scaler = 1.0;
372          }          }
373    
374          DPRINTF(XVID_DEBUG_RC, "target=%i, tot_length=%i, scaler=%f\n", (int)target, (int)pass1_length, scaler);          DPRINTF(XVID_DEBUG_RC,
375                            "After correction: target=%i, tot_length=%i, scaler=%f\n",
376                            (int)target, (int)pass1_length, scaler);
377    
378          for (i=0; i<rc->num_frames; i++) {          for (i=0; i<rc->num_frames; i++) {
379                  stat_t * s = &rc->stats[i];                  stat_t * s = &rc->stats[i];
# Line 369  Line 387 
387    
388    
389    
390  void pre_process1(rc_2pass2_t * rc)  static void
391    pre_process1(rc_2pass2_t * rc)
392  {  {
393      int i;      int i;
394      double total1, total2;      double total1, total2;
# Line 675  Line 694 
694          if (rc->num_frames  < create->fbase/create->fincr) {          if (rc->num_frames  < create->fbase/create->fincr) {
695                  rc->target = rc->param.bitrate / 8;     /* one second */                  rc->target = rc->param.bitrate / 8;     /* one second */
696          }else{          }else{
697                  rc->target = (rc->param.bitrate * rc->num_frames * create->fincr) / (create->fbase * 8);                  rc->target =
698                            ((uint64_t)rc->param.bitrate * (uint64_t)rc->num_frames * (uint64_t)create->fincr) / \
699                            ((uint64_t)create->fbase * 8);
700          }          }
701    
702      DPRINTF(XVID_DEBUG_RC, "rc->target : %i\n", rc->target);      DPRINTF(XVID_DEBUG_RC, "Number of frames: %d\n", rc->num_frames);
703            DPRINTF(XVID_DEBUG_RC, "Frame rate: %d/%d\n", create->fbase, create->fincr);
704            DPRINTF(XVID_DEBUG_RC, "Target bitrate: %ld\n", rc->param.bitrate);
705            DPRINTF(XVID_DEBUG_RC, "Target filesize: %lld\n", rc->target);
706    
707  #if 0  #if 0
708          rc->target -= rc->num_frames*24;        /* avi file header */          rc->target -= rc->num_frames*24;        /* avi file header */
# Line 981  Line 1005 
1005          if (desired > rc->max_length) {          if (desired > rc->max_length) {
1006                  capped_to_max_framesize = 1;                  capped_to_max_framesize = 1;
1007                  desired = rc->max_length;                  desired = rc->max_length;
1008                    DPRINTF(XVID_DEBUG_RC,"[%i] Capped to maximum frame size\n",
1009                                    data->frame_num);
1010          }          }
1011    
1012          /* Make sure to not scale below the minimum framesize */          /* Make sure to not scale below the minimum framesize */
1013          if (desired < rc->min_length[s->type-1])          if (desired < rc->min_length[s->type-1]) {
1014                  desired = rc->min_length[s->type-1];                  desired = rc->min_length[s->type-1];
1015                    DPRINTF(XVID_DEBUG_RC,"[%i] Capped to minimum frame size\n",
1016                                    data->frame_num);
1017            }
1018    
1019          /*          /*
1020           * Don't laugh at this very 'simple' quant<->filesize relationship, it           * Don't laugh at this very 'simple' quant<->filesize relationship, it
# Line 1047  Line 1076 
1076    
1077                  if (data->quant > rc->last_quant[s->type-1] + 2) {                  if (data->quant > rc->last_quant[s->type-1] + 2) {
1078                          data->quant = rc->last_quant[s->type-1] + 2;                          data->quant = rc->last_quant[s->type-1] + 2;
1079                          DPRINTF(XVID_DEBUG_RC, "p/b-frame quantizer prevented from rising too steeply\n");                          DPRINTF(XVID_DEBUG_RC,
1080                                            "[%i] p/b-frame quantizer prevented from rising too steeply\n",
1081                                            data->frame_num);
1082                  }                  }
1083                  if (data->quant < rc->last_quant[s->type-1] - 2) {                  if (data->quant < rc->last_quant[s->type-1] - 2) {
1084                          data->quant = rc->last_quant[s->type-1] - 2;                          data->quant = rc->last_quant[s->type-1] - 2;
1085                          DPRINTF(XVID_DEBUG_RC, "p/b-frame quantizer prevented from falling too steeply\n");                          DPRINTF(XVID_DEBUG_RC,
1086                                            "[%i] p/b-frame quantizer prevented from falling too steeply\n",
1087                                            data->frame_num);
1088                  }                  }
1089          }          }
1090    

Legend:
Removed from v.1038  
changed lines
  Added in v.1040

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