View Full Version : Changing default x264 setting before compile
P1TA
18th September 2009, 12:23
I'm linux user and often use ffmpeg but unfortunately I can't change some of x264 parameters like psy-rd or aq-strength .
My question is this is it possible to change default setting and how? please point me to right direction. and if I compile x264 with this new setting am I be able to convert my videos with this new setting using ffmpeg?
J_Darnley
18th September 2009, 12:39
Change them in common/common.c then compile x264.
Dark Shikari
18th September 2009, 14:22
Or set them in libavcodec/libx264.c, then you only have to recompile ffmpeg, not x264.
P1TA
19th September 2009, 00:58
Change them in common/common.c then compile x264.
Thanks for the tip.
I change the param->analyse.f_psy_trellis = 0; to param->analyse.f_psy_trellis = 0.15; and i get this :
# x264 --fullhelp | grep psy-rd
--psy-rd Strength of psychovisual optimization ["1.0:0.2"]
I encoded a video using ffmpeg and result contain the new setting :
/ psy_rd=1.0:0.2 /
but i also need to turn off the AQ and i don't know how :
I found two option for aq :
param->rc.i_aq_mode = X264_AQ_VARIANCE;
param->rc.f_aq_strength = 1.0;
what's X264_AQ_VARIANCE and how do i set it?
I could only set the rc.f_aq_strength to zero, is this equivalent to aq=0?
Or set them in libavcodec/libx264.c, then you only have to recompile ffmpeg, not x264.
I didn't find any of those setting in libx264.c:
$ grep analyse. libx264.c
x4->params.analyse.inter = 0;
x4->params.analyse.inter |= X264_ANALYSE_I4x4;
x4->params.analyse.inter |= X264_ANALYSE_I8x8;
x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
x4->params.analyse.i_direct_mv_pred = avctx->directpred;
x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
x4->params.analyse.i_me_method = X264_ME_DIA;
x4->params.analyse.i_me_method = X264_ME_HEX;
x4->params.analyse.i_me_method = X264_ME_UMH;
x4->params.analyse.i_me_method = X264_ME_ESA;
x4->params.analyse.i_me_method = X264_ME_TESA;
else x4->params.analyse.i_me_method = X264_ME_HEX;
x4->params.analyse.i_me_range = avctx->me_range;
x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
x4->params.analyse.b_mixed_references =
x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
x4->params.analyse.i_trellis = avctx->trellis;
x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
Dark Shikari
19th September 2009, 01:10
I didn't find any of those setting in libx264.cWell obviously you didn't, the entire point is that they're not there. Add strings to assign values to them; see x264.h for parameter documentation.
P1TA
21st September 2009, 16:19
Well obviously you didn't, the entire point is that they're not there. Add strings to assign values to them; see x264.h for parameter documentation.
Well I solved my previous problem for setting aq-mode=0 for default :
after i change the
param->rc.i_aq_mode = X264_AQ_VARIANCE;
to
param->rc.i_aq_mode = X264_AQ_NONE;
It seems done :
# x264 --fullhelp | grep aq
--aq-mode <integer> AQ method [0]
but when I convert my videos with ffmpeg still I get this setting :
/ qblur=0.5 / ip_ratio=1.40 / aq=1:0.00
I there any file beside libavcodec/libx264.c for x264 setting in ffmpeg?
by the way is this right code to put in libavcodec/libx264.c ?
x4->param->rc.i_aq_mode = X264_AQ_NONE;
x4->param->analyse.f_psy_trellis = 0.15;
LoRd_MuldeR
21st September 2009, 17:42
Well, usually applications that call libx264 do the following:
1. Initialize the x264_param_t struct with default values by calling x264_param_default()
2. Explicitly set (overwrite) at least some of those values with application specific settings
3. Open the encoder by calling x264_encoder_open()
So if ffmpeg explicitly sets (overwrites) the AQ mode to "1" in step 2, then you can change the defaults, but it won't have any effect :(
In that case you will have to hack x264_encoder_open() in "encoder\encoder.c", for example like this:
/****************************************************************************
* x264_encoder_open:
****************************************************************************/
x264_t *x264_encoder_open( x264_param_t *param )
{
x264_t *h;
char buf[1000], *p;
int i, qp, i_slicetype_length;
CHECKED_MALLOCZERO( h, sizeof(x264_t) );
/* Create a copy of param */
memcpy( &h->param, param, sizeof(x264_param_t) );
/* Disable AQ, if enabled */
if( h->param.rc.i_aq_mode )
h->param.rc.i_aq_mode = X264_AQ_NONE;
if( param->param_free )
param->param_free( param );
if( x264_validate_parameters( h ) < 0 )
goto fail;
[...]
Note: In case ffmpeg ever calls x264_encoder_reconfig(), you need to hack that function too...
Dark Shikari
21st September 2009, 20:13
/ qblur=0.5 / ip_ratio=1.40 / aq=1:0.00This is perfectly normal.
LoRd_MuldeR
21st September 2009, 21:52
This is perfectly normal.
MB-Tree, eh? I see ;)
if( !h->param.rc.i_aq_mode && h->param.rc.b_mb_tree )
{
h->param.rc.i_aq_mode = 1;
h->param.rc.f_aq_strength = 0;
}
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.