87
88
param->rc.i_vbv_buffer_size = 0;
88
89
param->rc.f_vbv_buffer_init = 0.9;
89
90
param->rc.i_qp_constant = 26;
90
param->rc.i_rf_constant = 0;
91
param->rc.f_rf_constant = 0;
91
92
param->rc.i_qp_min = 10;
92
93
param->rc.i_qp_max = 51;
93
94
param->rc.i_qp_step = 4;
118
119
param->analyse.i_me_range = 16;
119
120
param->analyse.i_subpel_refine = 5;
120
121
param->analyse.b_chroma_me = 1;
122
param->analyse.i_mv_range_thread = -1;
121
123
param->analyse.i_mv_range = -1; // set from level_idc
124
param->analyse.i_direct_8x8_inference = -1; // set from level_idc
122
125
param->analyse.i_chroma_qp_offset = 0;
123
126
param->analyse.b_fast_pskip = 1;
124
127
param->analyse.b_dct_decimate = 1;
128
param->analyse.i_luma_deadzone[0] = 21;
129
param->analyse.i_luma_deadzone[1] = 11;
125
130
param->analyse.b_psnr = 1;
126
131
param->analyse.b_ssim = 1;
171
176
!strcmp(str, "false") ||
172
177
!strcmp(str, "no") )
177
#define atobool(str) ( (i = atobool(str)) < 0 ? (b_error = 1) : i )
183
static int x264_atoi( const char *str, int *b_error )
186
int v = strtol( str, &end, 0 );
187
if( end == str || *end != '\0' )
192
static double x264_atof( const char *str, int *b_error )
195
double v = strtod( str, &end );
196
if( end == str || *end != '\0' )
201
#define atobool(str) ( name_was_bool = 1, x264_atobool( str, &b_error ) )
202
#define atoi(str) x264_atoi( str, &b_error )
203
#define atof(str) x264_atof( str, &b_error )
179
205
int x264_param_parse( x264_param_t *p, const char *name, const char *value )
207
char *name_buf = NULL;
210
int value_was_null = !value;
185
214
return X264_PARAM_BAD_NAME;
187
return X264_PARAM_BAD_VALUE;
189
218
if( value[0] == '=' )
221
if( strchr( name, '_' ) ) // s/_/-/g
224
name_buf = strdup(name);
225
while( (p = strchr( name_buf, '_' )) )
192
230
if( (!strncmp( name, "no-", 3 ) && (i = 3)) ||
193
231
(!strncmp( name, "no", 2 ) && (i = 2)) )
196
234
value = atobool(value) ? "false" : "true";
199
238
#define OPT(STR) else if( !strcmp( name, STR ) )
239
#define OPT2(STR0, STR1) else if( !strcmp( name, STR0 ) || !strcmp( name, STR1 ) )
202
242
p->cpu = atobool(value) ? x264_cpu_detect() : 0;
208
248
p->i_threads = atoi(value);
250
OPT2("deterministic", "n-deterministic")
251
p->b_deterministic = atobool(value);
252
OPT2("level", "level-idc")
212
254
if( atof(value) < 6 )
213
255
p->i_level_idc = (int)(10*atof(value)+.5);
242
283
if( sscanf( value, "%d/%d", &p->i_fps_num, &p->i_fps_den ) == 2 )
244
else if( sscanf( value, "%f", &fps ) )
287
float fps = atof(value);
246
288
p->i_fps_num = (int)(fps * 1000 + .5);
247
289
p->i_fps_den = 1000;
292
OPT2("ref", "frameref")
253
293
p->i_frame_reference = atoi(value);
257
297
if( p->i_keyint_min > p->i_keyint_max )
258
298
p->i_keyint_min = p->i_keyint_max;
300
OPT2("min-keyint", "keyint-min")
262
302
p->i_keyint_min = atoi(value);
263
303
if( p->i_keyint_max < p->i_keyint_min )
275
317
p->b_bframe_pyramid = atobool(value);
277
p->b_deblocking_filter = 0;
319
p->b_deblocking_filter = !atobool(value);
320
OPT2("filter", "deblock")
281
if( 0 < (count = sscanf( value, "%d:%d", &p->i_deblocking_filter_alphac0, &p->i_deblocking_filter_beta )) ||
282
0 < (count = sscanf( value, "%d,%d", &p->i_deblocking_filter_alphac0, &p->i_deblocking_filter_beta )) )
284
p->b_deblocking_filter = 1;
286
p->i_deblocking_filter_beta = p->i_deblocking_filter_alphac0;
322
if( 2 == sscanf( value, "%d:%d", &p->i_deblocking_filter_alphac0, &p->i_deblocking_filter_beta ) ||
323
2 == sscanf( value, "%d,%d", &p->i_deblocking_filter_alphac0, &p->i_deblocking_filter_beta ) )
325
p->b_deblocking_filter = 1;
327
else if( sscanf( value, "%d", &p->i_deblocking_filter_alphac0 ) )
329
p->b_deblocking_filter = 1;
330
p->i_deblocking_filter_beta = p->i_deblocking_filter_alphac0;
289
333
p->b_deblocking_filter = atobool(value);
292
336
p->b_cabac = atobool(value);
294
338
p->i_cabac_init_idc = atoi(value);
340
p->b_interlaced = atobool(value);
297
343
if( strstr( value, "flat" ) )
299
345
else if( strstr( value, "jvt" ) )
300
346
p->i_cqm_preset = X264_CQM_JVT;
348
p->psz_cqm_file = strdup(value);
305
351
p->psz_cqm_file = strdup(value);
363
409
p->i_log_level = atoi(value);
412
p->b_visualize = atobool(value);
414
OPT2("analyse", "partitions")
366
416
p->analyse.inter = 0;
367
417
if( strstr( value, "none" ) ) p->analyse.inter = 0;
377
427
p->analyse.b_transform_8x8 = atobool(value);
428
OPT2("weightb", "weight-b")
379
429
p->analyse.b_weighted_bipred = atobool(value);
430
OPT2("direct", "direct-pred")
381
431
b_error |= parse_enum( value, x264_direct_pred_names, &p->analyse.i_direct_mv_pred );
433
p->analyse.i_direct_8x8_inference = atoi(value);
382
434
OPT("chroma-qp-offset")
383
435
p->analyse.i_chroma_qp_offset = atoi(value);
385
437
b_error |= parse_enum( value, x264_motion_est_names, &p->analyse.i_me_method );
438
OPT2("merange", "me-range")
387
439
p->analyse.i_me_range = atoi(value);
440
OPT2("mvrange", "mv-range")
389
441
p->analyse.i_mv_range = atoi(value);
442
OPT2("mvrange-thread", "mv-range-thread")
443
p->analyse.i_mv_range_thread = atoi(value);
444
OPT2("subme", "subq")
391
445
p->analyse.i_subpel_refine = atoi(value);
393
447
p->analyse.b_bidir_me = atobool(value);
395
449
p->analyse.b_chroma_me = atobool(value);
450
OPT2("b-rdo", "brdo")
397
451
p->analyse.b_bframe_rdo = atobool(value);
398
452
OPT("mixed-refs")
399
453
p->analyse.b_mixed_references = atobool(value);
403
457
p->analyse.b_fast_pskip = atobool(value);
404
458
OPT("dct-decimate")
405
459
p->analyse.b_dct_decimate = atobool(value);
460
OPT("deadzone-inter")
461
p->analyse.i_luma_deadzone[0] = atoi(value);
462
OPT("deadzone-intra")
463
p->analyse.i_luma_deadzone[1] = atoi(value);
407
465
p->analyse.i_noise_reduction = atoi(value);
410
468
p->rc.i_bitrate = atoi(value);
411
469
p->rc.i_rc_method = X264_RC_ABR;
471
OPT2("qp", "qp_constant")
415
473
p->rc.i_qp_constant = atoi(value);
416
474
p->rc.i_rc_method = X264_RC_CQP;
420
p->rc.i_rf_constant = atoi(value);
478
p->rc.f_rf_constant = atof(value);
421
479
p->rc.i_rc_method = X264_RC_CRF;
481
OPT2("qpmin", "qp-min")
424
482
p->rc.i_qp_min = atoi(value);
483
OPT2("qpmax", "qp-max")
426
484
p->rc.i_qp_max = atoi(value);
485
OPT2("qpstep", "qp-step")
428
486
p->rc.i_qp_step = atoi(value);
430
488
p->rc.f_rate_tolerance = !strncmp("inf", value, 3) ? 1e9 : atof(value);
434
492
p->rc.i_vbv_buffer_size = atoi(value);
436
494
p->rc.f_vbv_buffer_init = atof(value);
495
OPT2("ipratio", "ip-factor")
438
496
p->rc.f_ip_factor = atof(value);
497
OPT2("pbratio", "pb-factor")
440
498
p->rc.f_pb_factor = atof(value);
455
513
p->rc.f_qcompress = atof(value);
457
515
p->rc.f_qblur = atof(value);
516
OPT2("cplxblur", "cplx-blur")
459
517
p->rc.f_complexity_blur = atof(value);
461
519
p->rc.psz_zones = strdup(value);
467
525
p->b_aud = atobool(value);
469
527
p->i_sps_id = atoi(value);
529
p->b_repeat_headers = !atobool(value);
470
530
OPT("repeat-headers")
471
531
p->b_repeat_headers = atobool(value);
473
533
return X264_PARAM_BAD_NAME;
543
b_error |= value_was_null && !name_was_bool;
477
544
return b_error ? X264_PARAM_BAD_VALUE : 0;
818
885
s += sprintf( s, " trellis=%d", p->analyse.i_trellis );
819
886
s += sprintf( s, " 8x8dct=%d", p->analyse.b_transform_8x8 );
820
887
s += sprintf( s, " cqm=%d", p->i_cqm_preset );
888
s += sprintf( s, " deadzone=%d,%d", p->analyse.i_luma_deadzone[0], p->analyse.i_luma_deadzone[1] );
821
889
s += sprintf( s, " chroma_qp_offset=%d", p->analyse.i_chroma_qp_offset );
822
s += sprintf( s, " slices=%d", p->i_threads );
890
s += sprintf( s, " threads=%d", p->i_threads );
823
891
s += sprintf( s, " nr=%d", p->analyse.i_noise_reduction );
824
892
s += sprintf( s, " decimate=%d", p->analyse.b_dct_decimate );
893
s += sprintf( s, " mbaff=%d", p->b_interlaced );
826
895
s += sprintf( s, " bframes=%d", p->i_bframe );
827
896
if( p->i_bframe )
832
901
p->analyse.b_bidir_me );
835
s += sprintf( s, " keyint=%d keyint_min=%d scenecut=%d",
836
p->i_keyint_max, p->i_keyint_min, p->i_scenecut_threshold );
904
s += sprintf( s, " keyint=%d keyint_min=%d scenecut=%d%s",
905
p->i_keyint_max, p->i_keyint_min, p->i_scenecut_threshold,
906
p->b_pre_scenecut ? "(pre)" : "" );
838
908
s += sprintf( s, " rc=%s", p->rc.i_rc_method == X264_RC_ABR ?
839
909
( p->rc.b_stat_read ? "2pass" : p->rc.i_vbv_buffer_size ? "cbr" : "abr" )
841
911
if( p->rc.i_rc_method == X264_RC_ABR || p->rc.i_rc_method == X264_RC_CRF )
843
913
if( p->rc.i_rc_method == X264_RC_CRF )
844
s += sprintf( s, " crf=%d", p->rc.i_rf_constant );
914
s += sprintf( s, " crf=%.1f", p->rc.f_rf_constant );
846
916
s += sprintf( s, " bitrate=%d ratetol=%.1f",
847
917
p->rc.i_bitrate, p->rc.f_rate_tolerance );