]> git.sesse.net Git - x264/commitdiff
hardcode the ratecontrol equation, and remove the rceq option
authorLoren Merritt <pengvado@akuvian.org>
Thu, 21 Aug 2008 02:51:39 +0000 (20:51 -0600)
committerLoren Merritt <pengvado@akuvian.org>
Sat, 30 Aug 2008 01:02:30 +0000 (19:02 -0600)
Makefile
common/common.c
encoder/encoder.c
encoder/eval.c [deleted file]
encoder/ratecontrol.c
x264.c
x264.h

index 4e0d1c8252d97c8e9eb17efa7d1fa48578ba3db8..607d1c71926ab8060303185f72c0719519185be2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
        common/quant.c common/vlc.c \
        encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
        encoder/set.c encoder/macroblock.c encoder/cabac.c \
-       encoder/cavlc.c encoder/encoder.c encoder/eval.c
+       encoder/cavlc.c encoder/encoder.c
 
 SRCCLI = x264.c matroska.c muxers.c
 
index a6054bbc92a2c4532218d38bca0476c28fe4fc14..f628f8d247c29f20d05a9e4ff8792758b412429c 100644 (file)
@@ -100,7 +100,6 @@ void    x264_param_default( x264_param_t *param )
     param->rc.psz_stat_out = "x264_2pass.log";
     param->rc.b_stat_read = 0;
     param->rc.psz_stat_in = "x264_2pass.log";
-    param->rc.psz_rc_eq = "blurCplx^(1-qComp)";
     param->rc.f_qcompress = 0.6;
     param->rc.f_qblur = 0.5;
     param->rc.f_complexity_blur = 20;
@@ -532,8 +531,6 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->rc.psz_stat_in = strdup(value);
         p->rc.psz_stat_out = strdup(value);
     }
-    OPT("rceq")
-        p->rc.psz_rc_eq = strdup(value);
     OPT("qcomp")
         p->rc.f_qcompress = atof(value);
     OPT("qblur")
@@ -893,9 +890,8 @@ char *x264_param2string( x264_param_t *p, int b_res )
         else
             s += sprintf( s, " bitrate=%d ratetol=%.1f",
                           p->rc.i_bitrate, p->rc.f_rate_tolerance );
-        s += sprintf( s, " rceq='%s' qcomp=%.2f qpmin=%d qpmax=%d qpstep=%d",
-                      p->rc.psz_rc_eq, p->rc.f_qcompress,
-                      p->rc.i_qp_min, p->rc.i_qp_max, p->rc.i_qp_step );
+        s += sprintf( s, " qcomp=%.2f qpmin=%d qpmax=%d qpstep=%d",
+                      p->rc.f_qcompress, p->rc.i_qp_min, p->rc.i_qp_max, p->rc.i_qp_step );
         if( p->rc.b_stat_read )
             s += sprintf( s, " cplxblur=%.1f qblur=%.1f",
                           p->rc.f_complexity_blur, p->rc.f_qblur );
index ad7151c29f559792ce4dcc174ed7e4753628d9e4..1c114324d4d5c8d8583d9dd654713345179f58a4 100644 (file)
@@ -621,8 +621,6 @@ x264_t *x264_encoder_open   ( x264_param_t *param )
         h->param.rc.psz_stat_out = strdup( h->param.rc.psz_stat_out );
     if( h->param.rc.psz_stat_in )
         h->param.rc.psz_stat_in = strdup( h->param.rc.psz_stat_in );
-    if( h->param.rc.psz_rc_eq )
-        h->param.rc.psz_rc_eq = strdup( h->param.rc.psz_rc_eq );
 
     /* VUI */
     if( h->param.vui.i_sar_width > 0 && h->param.vui.i_sar_height > 0 )
@@ -2029,8 +2027,6 @@ void    x264_encoder_close  ( x264_t *h )
         free( h->param.rc.psz_stat_out );
     if( h->param.rc.psz_stat_in )
         free( h->param.rc.psz_stat_in );
-    if( h->param.rc.psz_rc_eq )
-        free( h->param.rc.psz_rc_eq );
 
     x264_cqm_delete( h );
 
diff --git a/encoder/eval.c b/encoder/eval.c
deleted file mode 100644 (file)
index 6608548..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/*****************************************************************************
- * simple arithmetic expression evaluator
- *****************************************************************************
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *****************************************************************************/
-
-/**
- * @file eval.c
- * simple arithmetic expression evaluator.
- *
- * see http://joe.hotchkiss.com/programming/eval/eval.html
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#ifndef NAN
-  #define NAN 0
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#define STACK_SIZE 100
-
-typedef struct Parser{
-    double stack[STACK_SIZE];
-    int stack_index;
-    char *s;
-    double *const_value;
-    const char **const_name;          // NULL terminated
-    double (**func1)(void *, double a); // NULL terminated
-    const char **func1_name;          // NULL terminated
-    double (**func2)(void *, double a, double b); // NULL terminated
-    char **func2_name;          // NULL terminated
-    void *opaque;
-} Parser;
-
-static void evalExpression(Parser *p);
-
-static void push(Parser *p, double d){
-    if(p->stack_index+1>= STACK_SIZE){
-        fprintf(stderr, "stack overflow in the parser\n");
-        return;
-    }
-    p->stack[ p->stack_index++ ]= d;
-//printf("push %f\n", d); fflush(stdout);
-}
-
-static double pop(Parser *p){
-    if(p->stack_index<=0){
-        fprintf(stderr, "stack underflow in the parser\n");
-        return NAN;
-    }
-//printf("pop\n"); fflush(stdout);
-    return p->stack[ --p->stack_index ];
-}
-
-static int strmatch(const char *s, const char *prefix){
-    int i;
-    for(i=0; prefix[i]; i++){
-        if(prefix[i] != s[i]) return 0;
-    }
-    return 1;
-}
-
-static void evalPrimary(Parser *p){
-    double d, d2=NAN;
-    char *next= p->s;
-    int i;
-
-    /* number */
-    d= strtod(p->s, &next);
-    if(next != p->s){
-        push(p, d);
-        p->s= next;
-        return;
-    }
-
-    /* named constants */
-    for(i=0; p->const_name[i]; i++){
-        if(strmatch(p->s, p->const_name[i])){
-            push(p, p->const_value[i]);
-            p->s+= strlen(p->const_name[i]);
-            return;
-        }
-    }
-
-    p->s= strchr(p->s, '(');
-    if(p->s==NULL){
-        fprintf(stderr, "Parser: missing ( in \"%s\"\n", next);
-        return;
-    }
-    p->s++; // "("
-    evalExpression(p);
-    d= pop(p);
-    if(p->s[0]== ','){
-        p->s++; // ","
-        evalExpression(p);
-        d2= pop(p);
-    }
-    if(p->s[0] != ')'){
-        fprintf(stderr, "Parser: missing ) in \"%s\"\n", next);
-        return;
-    }
-    p->s++; // ")"
-
-         if( strmatch(next, "sinh"  ) ) d= sinh(d);
-    else if( strmatch(next, "cosh"  ) ) d= cosh(d);
-    else if( strmatch(next, "tanh"  ) ) d= tanh(d);
-    else if( strmatch(next, "sin"   ) ) d= sin(d);
-    else if( strmatch(next, "cos"   ) ) d= cos(d);
-    else if( strmatch(next, "tan"   ) ) d= tan(d);
-    else if( strmatch(next, "exp"   ) ) d= exp(d);
-    else if( strmatch(next, "log"   ) ) d= log(d);
-    else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
-    else if( strmatch(next, "gauss" ) ) d= exp(-d*d/2)/sqrt(2*M_PI);
-    else if( strmatch(next, "abs"   ) ) d= fabs(d);
-    else if( strmatch(next, "max"   ) ) d= d > d2 ? d : d2;
-    else if( strmatch(next, "min"   ) ) d= d < d2 ? d : d2;
-    else if( strmatch(next, "gt"    ) ) d= d > d2 ? 1.0 : 0.0;
-    else if( strmatch(next, "gte"    ) ) d= d >= d2 ? 1.0 : 0.0;
-    else if( strmatch(next, "lt"    ) ) d= d > d2 ? 0.0 : 1.0;
-    else if( strmatch(next, "lte"    ) ) d= d >= d2 ? 0.0 : 1.0;
-    else if( strmatch(next, "eq"    ) ) d= d == d2 ? 1.0 : 0.0;
-//    else if( strmatch(next, "l1"    ) ) d= 1 + d2*(d - 1);
-//    else if( strmatch(next, "sq01"  ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
-    else{
-        int error=1;
-        for(i=0; p->func1_name && p->func1_name[i]; i++){
-            if(strmatch(next, p->func1_name[i])){
-                d= p->func1[i](p->opaque, d);
-                error=0;
-                break;
-            }
-        }
-
-        for(i=0; p->func2_name && p->func2_name[i]; i++){
-            if(strmatch(next, p->func2_name[i])){
-                d= p->func2[i](p->opaque, d, d2);
-                error=0;
-                break;
-            }
-        }
-
-        if(error){
-            fprintf(stderr, "Parser: unknown function in \"%s\"\n", next);
-            return;
-        }
-    }
-
-    push(p, d);
-}
-
-static void evalPow(Parser *p){
-    int neg= 0;
-    if(p->s[0]=='+') p->s++;
-
-    if(p->s[0]=='-'){
-        neg= 1;
-        p->s++;
-    }
-
-    if(p->s[0]=='('){
-        p->s++;;
-        evalExpression(p);
-
-        if(p->s[0]!=')')
-            fprintf(stderr, "Parser: missing )\n");
-        p->s++;
-    }else{
-        evalPrimary(p);
-    }
-
-    if(neg) push(p, -pop(p));
-}
-
-static void evalFactor(Parser *p){
-    evalPow(p);
-    while(p->s[0]=='^'){
-        double d;
-
-        p->s++;
-        evalPow(p);
-        d= pop(p);
-        push(p, pow(pop(p), d));
-    }
-}
-
-static void evalTerm(Parser *p){
-    evalFactor(p);
-    while(p->s[0]=='*' || p->s[0]=='/'){
-        int inv= p->s[0]=='/';
-        double d;
-
-        p->s++;
-        evalFactor(p);
-        d= pop(p);
-        if(inv) d= 1.0/d;
-        push(p, d * pop(p));
-    }
-}
-
-static void evalExpression(Parser *p){
-    evalTerm(p);
-    while(p->s[0]=='+' || p->s[0]=='-'){
-        int sign= p->s[0]=='-';
-        double d;
-
-        p->s++;
-        evalTerm(p);
-        d= pop(p);
-        if(sign) d= -d;
-        push(p, d + pop(p));
-    }
-}
-
-double x264_eval(char *s, double *const_value, const char **const_name,
-                 double (**func1)(void *, double), const char **func1_name,
-                 double (**func2)(void *, double, double), char **func2_name,
-                 void *opaque){
-    Parser p;
-
-    p.stack_index=0;
-    p.s= s;
-    p.const_value= const_value;
-    p.const_name = const_name;
-    p.func1      = func1;
-    p.func1_name = func1_name;
-    p.func2      = func2;
-    p.func2_name = func2_name;
-    p.opaque     = opaque;
-
-    evalExpression(&p);
-    return pop(&p);
-}
index c43e9aa08c2832478523cce95d3ec0181e35bf58..cb8f5c5693bdb6d1f4b7b22e3b928ba0ed144c90 100644 (file)
@@ -118,10 +118,6 @@ struct x264_ratecontrol_t
     double lmin[5];             /* min qscale by frame type */
     double lmax[5];
     double lstep;               /* max change (multiply) in qscale per frame */
-    double i_cplx_sum[5];       /* estimated total texture bits in intra MBs at qscale=1 */
-    double p_cplx_sum[5];
-    double mv_bits_sum[5];
-    int frame_count[5];         /* number of frames of each type */
 
     /* MBRC stuff */
     double frame_size_estimated;
@@ -1130,73 +1126,16 @@ void x264_ratecontrol_end( x264_t *h, int bits )
  * 2 pass functions
  ***************************************************************************/
 
-double x264_eval( char *s, double *const_value, const char **const_name,
-                  double (**func1)(void *, double), const char **func1_name,
-                  double (**func2)(void *, double, double), char **func2_name,
-                  void *opaque );
-
 /**
  * modify the bitrate curve from pass1 for one frame
  */
 static double get_qscale(x264_t *h, ratecontrol_entry_t *rce, double rate_factor, int frame_num)
 {
     x264_ratecontrol_t *rcc= h->rc;
-    const int pict_type = rce->pict_type;
     double q;
     x264_zone_t *zone = get_zone( h, frame_num );
 
-    double const_values[]={
-        rce->i_tex_bits * rce->qscale,
-        rce->p_tex_bits * rce->qscale,
-        (rce->i_tex_bits + rce->p_tex_bits) * rce->qscale,
-        rce->mv_bits * rce->qscale,
-        (double)rce->i_count / rcc->nmb,
-        (double)rce->p_count / rcc->nmb,
-        (double)rce->s_count / rcc->nmb,
-        rce->pict_type == SLICE_TYPE_I,
-        rce->pict_type == SLICE_TYPE_P,
-        rce->pict_type == SLICE_TYPE_B,
-        h->param.rc.f_qcompress,
-        rcc->i_cplx_sum[SLICE_TYPE_I] / rcc->frame_count[SLICE_TYPE_I],
-        rcc->i_cplx_sum[SLICE_TYPE_P] / rcc->frame_count[SLICE_TYPE_P],
-        rcc->p_cplx_sum[SLICE_TYPE_P] / rcc->frame_count[SLICE_TYPE_P],
-        rcc->p_cplx_sum[SLICE_TYPE_B] / rcc->frame_count[SLICE_TYPE_B],
-        (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / rcc->frame_count[pict_type],
-        rce->blurred_complexity,
-        0
-    };
-    static const char *const_names[]={
-        "iTex",
-        "pTex",
-        "tex",
-        "mv",
-        "iCount",
-        "pCount",
-        "sCount",
-        "isI",
-        "isP",
-        "isB",
-        "qComp",
-        "avgIITex",
-        "avgPITex",
-        "avgPPTex",
-        "avgBPTex",
-        "avgTex",
-        "blurCplx",
-        NULL
-    };
-    static double (*func1[])(void *, double)={
-//      (void *)bits2qscale,
-        (void *)qscale2bits,
-        NULL
-    };
-    static const char *func1_names[]={
-//      "bits2qp",
-        "qp2bits",
-        NULL
-    };
-
-    q = x264_eval((char*)h->param.rc.psz_rc_eq, const_values, const_names, func1, func1_names, NULL, NULL, rce);
+    q = pow( rce->blurred_complexity, 1 - h->param.rc.f_qcompress );
 
     // avoid NaN's in the rc_eq
     if(!isfinite(q) || rce->i_tex_bits + rce->p_tex_bits + rce->mv_bits == 0)
@@ -1787,10 +1726,6 @@ static int init_pass2( x264_t *h )
     {
         ratecontrol_entry_t *rce = &rcc->entry[i];
         all_const_bits += rce->misc_bits;
-        rcc->i_cplx_sum[rce->pict_type] += rce->i_tex_bits * rce->qscale;
-        rcc->p_cplx_sum[rce->pict_type] += rce->p_tex_bits * rce->qscale;
-        rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits * rce->qscale;
-        rcc->frame_count[rce->pict_type] ++;
     }
 
     if( all_available_bits < all_const_bits)
diff --git a/x264.c b/x264.c
index 591e2105cc8f0b17c718022f9f055d0445deace5..1f435f4a06021c58954ec9b324cf627577971e0a 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -202,7 +202,6 @@ static void Help( x264_param_t *defaults, int b_longhelp )
         "                                  - 2: Last pass, does not overwrite stats file\n"
         "                                  - 3: Nth pass, overwrites stats file\n" );
     H0( "      --stats <string>        Filename for 2 pass stats [\"%s\"]\n", defaults->rc.psz_stat_out );
-    H1( "      --rceq <string>         Ratecontrol equation [\"%s\"]\n", defaults->rc.psz_rc_eq );
     H0( "      --qcomp <float>         QP curve compression: 0.0 => CBR, 1.0 => CQP [%.2f]\n", defaults->rc.f_qcompress );
     H1( "      --cplxblur <float>      Reduce fluctuations in QP (before curve compression) [%.1f]\n", defaults->rc.f_complexity_blur );
     H1( "      --qblur <float>         Reduce fluctuations in QP (after curve compression) [%.1f]\n", defaults->rc.f_qblur );
@@ -433,7 +432,6 @@ static int  Parse( int argc, char **argv,
             { "chroma-qp-offset", required_argument, NULL, 0 },
             { "pass",    required_argument, NULL, 'p' },
             { "stats",   required_argument, NULL, 0 },
-            { "rceq",    required_argument, NULL, 0 },
             { "qcomp",   required_argument, NULL, 0 },
             { "qblur",   required_argument, NULL, 0 },
             { "cplxblur",required_argument, NULL, 0 },
diff --git a/x264.h b/x264.h
index 8b8ef86d0f49ef27d63656024d336509431bdafd..538e9a74e9f0dff340f559430076165daaed7408 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -35,7 +35,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 60
+#define X264_BUILD 61
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -276,7 +276,6 @@ typedef struct x264_param_t
         char        *psz_stat_in;
 
         /* 2pass params (same as ffmpeg ones) */
-        char        *psz_rc_eq;     /* 2 pass rate control equation */
         float       f_qcompress;    /* 0.0 => cbr, 1.0 => constant qp */
         float       f_qblur;        /* temporally blur quants */
         float       f_complexity_blur; /* temporally blur complexity */