Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
x264
Commits
9ccd80fa
Commit
9ccd80fa
authored
Aug 20, 2008
by
Loren Merritt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hardcode the ratecontrol equation, and remove the rceq option
parent
79f4e3e2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
5 additions
and
334 deletions
+5
-334
Makefile
Makefile
+1
-1
common/common.c
common/common.c
+2
-6
encoder/encoder.c
encoder/encoder.c
+0
-4
encoder/eval.c
encoder/eval.c
+0
-253
encoder/ratecontrol.c
encoder/ratecontrol.c
+1
-66
x264.c
x264.c
+0
-2
x264.h
x264.h
+1
-2
No files found.
Makefile
View file @
9ccd80fa
...
...
@@ -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
...
...
common/common.c
View file @
9ccd80fa
...
...
@@ -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
);
...
...
encoder/encoder.c
View file @
9ccd80fa
...
...
@@ -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
);
...
...
encoder/eval.c
deleted
100644 → 0
View file @
79f4e3e2
/*****************************************************************************
* 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
);
}
encoder/ratecontrol.c
View file @
9ccd80fa
...
...
@@ -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
)
...
...
x264.c
View file @
9ccd80fa
...
...
@@ -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
},
...
...
x264.h
View file @
9ccd80fa
...
...
@@ -35,7 +35,7 @@
#include <stdarg.h>
#define X264_BUILD 6
0
#define X264_BUILD 6
1
/* 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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment