Discussion:
Change default QP parameters initialization
(too old to reply)
Vittorio Giovara
2017-12-25 19:39:44 UTC
Permalink
x264 | branch: master | Vittorio Giovara <***@gmail.com> | Fri Jan 6 17:50:40 2017 +0100| [2451a7282463f68e532f2eee090a70ab139bb3e7] | committer: Anton Mitrofanov

Change default QP parameters initialization

qp is modified to require a valid value before use, while qp_max is set
to maximum allowable value (and clipped later on).

This is needed so that param functions do not depend on bit depth size.
http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=2451a7282463f68e532f2eee090a70ab139bb3e7
---

common/common.c | 4 ++--
encoder/encoder.c | 8 +++++++-
x264.h | 2 +-
3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/common.c b/common/common.c
index 5018cf2f..e4a7e3a8 100644
--- a/common/common.c
+++ b/common/common.c
@@ -101,10 +101,10 @@ void x264_param_default( x264_param_t *param )
param->rc.i_vbv_max_bitrate = 0;
param->rc.i_vbv_buffer_size = 0;
param->rc.f_vbv_buffer_init = 0.9;
- param->rc.i_qp_constant = 23 + QP_BD_OFFSET;
+ param->rc.i_qp_constant = -1;
param->rc.f_rf_constant = 23;
param->rc.i_qp_min = 0;
- param->rc.i_qp_max = QP_MAX;
+ param->rc.i_qp_max = INT_MAX;
param->rc.i_qp_step = 4;
param->rc.f_ip_factor = 1.4;
param->rc.f_pb_factor = 1.3;
diff --git a/encoder/encoder.c b/encoder/encoder.c
index fef3436e..3ddf89ca 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -823,7 +823,7 @@ static int validate_parameters( x264_t *h, int b_open )

h->param.rc.f_rf_constant = x264_clip3f( h->param.rc.f_rf_constant, -QP_BD_OFFSET, 51 );
h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
- h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, 0, QP_MAX );
+ h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, -1, QP_MAX );
h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
@@ -865,6 +865,12 @@ static int validate_parameters( x264_t *h, int b_open )
float qp_p = h->param.rc.i_qp_constant;
float qp_i = qp_p - 6*log2f( h->param.rc.f_ip_factor );
float qp_b = qp_p + 6*log2f( h->param.rc.f_pb_factor );
+ if( qp_p < 0 )
+ {
+ x264_log( h, X264_LOG_ERROR, "qp not specified\n" );
+ return -1;
+ }
+
h->param.rc.i_qp_min = x264_clip3( (int)(X264_MIN3( qp_p, qp_i, qp_b )), 0, QP_MAX );
h->param.rc.i_qp_max = x264_clip3( (int)(X264_MAX3( qp_p, qp_i, qp_b ) + .999), 0, QP_MAX );
h->param.rc.i_aq_mode = 0;
diff --git a/x264.h b/x264.h
index 0f340672..039a618b 100644
--- a/x264.h
+++ b/x264.h
@@ -407,7 +407,7 @@ typedef struct x264_param_t
{
int i_rc_method; /* X264_RC_* */

- int i_qp_constant; /* 0 to (51 + 6*(x264_bit_depth-8)). 0=lossless */
+ int i_qp_constant; /* 0=lossless */
int i_qp_min; /* min allowed QP value */
int i_qp_max; /* max allowed QP value */
int i_qp_step; /* max QP step between frames */

Loading...