~ubuntu-branches/ubuntu/saucy/x264/saucy-updates

« back to all changes in this revision

Viewing changes to common/common.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-17 22:00:05 UTC
  • mto: (12.1.1 sid) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20070117220005-4cesfv31lq3inbdp
Tags: upstream-0.cvs20070117
ImportĀ upstreamĀ versionĀ 0.cvs20070117

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    /* CPU autodetect */
46
46
    param->cpu = x264_cpu_detect();
47
47
    param->i_threads = 1;
 
48
    param->b_deterministic = 1;
48
49
 
49
50
    /* Video properties */
50
51
    param->i_csp           = X264_CSP_I420;
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;
127
132
 
161
166
    return (i == length) ? 0 : -1;
162
167
}
163
168
 
164
 
static int atobool( const char *str )
 
169
static int x264_atobool( const char *str, int *b_error )
165
170
{
166
171
    if( !strcmp(str, "1") || 
167
172
        !strcmp(str, "true") || 
171
176
        !strcmp(str, "false") || 
172
177
        !strcmp(str, "no") )
173
178
        return 0;
174
 
    return -1;
175
 
}
176
 
 
177
 
#define atobool(str) ( (i = atobool(str)) < 0 ? (b_error = 1) : i )
 
179
    *b_error = 1;
 
180
    return 0;
 
181
}
 
182
 
 
183
static int x264_atoi( const char *str, int *b_error )
 
184
{
 
185
    char *end;
 
186
    int v = strtol( str, &end, 0 );
 
187
    if( end == str || *end != '\0' )
 
188
        *b_error = 1;
 
189
    return v;
 
190
}
 
191
 
 
192
static double x264_atof( const char *str, int *b_error )
 
193
{
 
194
    char *end;
 
195
    double v = strtod( str, &end );
 
196
    if( end == str || *end != '\0' )
 
197
        *b_error = 1;
 
198
    return v;
 
199
}
 
200
 
 
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 )
178
204
 
179
205
int x264_param_parse( x264_param_t *p, const char *name, const char *value )
180
206
{
 
207
    char *name_buf = NULL;
181
208
    int b_error = 0;
 
209
    int name_was_bool;
 
210
    int value_was_null = !value;
182
211
    int i;
183
212
 
184
213
    if( !name )
185
214
        return X264_PARAM_BAD_NAME;
186
215
    if( !value )
187
 
        return X264_PARAM_BAD_VALUE;
 
216
        value = "true";
188
217
 
189
218
    if( value[0] == '=' )
190
219
        value++;
191
220
 
 
221
    if( strchr( name, '_' ) ) // s/_/-/g
 
222
    {
 
223
        char *p;
 
224
        name_buf = strdup(name);
 
225
        while( (p = strchr( name_buf, '_' )) )
 
226
            *p = '-';
 
227
        name = name_buf;
 
228
    }
 
229
 
192
230
    if( (!strncmp( name, "no-", 3 ) && (i = 3)) ||
193
231
        (!strncmp( name, "no", 2 ) && (i = 2)) )
194
232
    {
195
233
        name += i;
196
234
        value = atobool(value) ? "false" : "true";
197
235
    }
 
236
    name_was_bool = 0;
198
237
 
199
238
#define OPT(STR) else if( !strcmp( name, STR ) )
 
239
#define OPT2(STR0, STR1) else if( !strcmp( name, STR0 ) || !strcmp( name, STR1 ) )
200
240
    if(0);
201
241
    OPT("asm")
202
242
        p->cpu = atobool(value) ? x264_cpu_detect() : 0;
207
247
        else
208
248
            p->i_threads = atoi(value);
209
249
    }
210
 
    OPT("level")
 
250
    OPT2("deterministic", "n-deterministic")
 
251
        p->b_deterministic = atobool(value);
 
252
    OPT2("level", "level-idc")
211
253
    {
212
254
        if( atof(value) < 6 )
213
255
            p->i_level_idc = (int)(10*atof(value)+.5);
238
280
    }
239
281
    OPT("fps")
240
282
    {
241
 
        float fps;
242
283
        if( sscanf( value, "%d/%d", &p->i_fps_num, &p->i_fps_den ) == 2 )
243
284
            ;
244
 
        else if( sscanf( value, "%f", &fps ) )
 
285
        else
245
286
        {
 
287
            float fps = atof(value);
246
288
            p->i_fps_num = (int)(fps * 1000 + .5);
247
289
            p->i_fps_den = 1000;
248
290
        }
249
 
        else
250
 
            b_error = 1;
251
291
    }
252
 
    OPT("ref")
 
292
    OPT2("ref", "frameref")
253
293
        p->i_frame_reference = atoi(value);
254
294
    OPT("keyint")
255
295
    {
257
297
        if( p->i_keyint_min > p->i_keyint_max )
258
298
            p->i_keyint_min = p->i_keyint_max;
259
299
    }
260
 
    OPT("min-keyint")
 
300
    OPT2("min-keyint", "keyint-min")
261
301
    {
262
302
        p->i_keyint_min = atoi(value);
263
303
        if( p->i_keyint_max < p->i_keyint_min )
265
305
    }
266
306
    OPT("scenecut")
267
307
        p->i_scenecut_threshold = atoi(value);
 
308
    OPT("pre-scenecut")
 
309
        p->b_pre_scenecut = atobool(value);
268
310
    OPT("bframes")
269
311
        p->i_bframe = atoi(value);
270
312
    OPT("b-adapt")
274
316
    OPT("b-pyramid")
275
317
        p->b_bframe_pyramid = atobool(value);
276
318
    OPT("nf")
277
 
        p->b_deblocking_filter = 0;
278
 
    OPT("filter")
 
319
        p->b_deblocking_filter = !atobool(value);
 
320
    OPT2("filter", "deblock")
279
321
    {
280
 
        int count;
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 )) )
283
 
        {
284
 
            p->b_deblocking_filter = 1;
285
 
            if( count == 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 ) )
 
324
        {
 
325
            p->b_deblocking_filter = 1;
 
326
        }
 
327
        else if( sscanf( value, "%d", &p->i_deblocking_filter_alphac0 ) )
 
328
        {
 
329
            p->b_deblocking_filter = 1;
 
330
            p->i_deblocking_filter_beta = p->i_deblocking_filter_alphac0;
287
331
        }
288
332
        else
289
333
            p->b_deblocking_filter = atobool(value);
292
336
        p->b_cabac = atobool(value);
293
337
    OPT("cabac-idc")
294
338
        p->i_cabac_init_idc = atoi(value);
 
339
    OPT("interlaced")
 
340
        p->b_interlaced = atobool(value);
295
341
    OPT("cqm")
296
342
    {
297
343
        if( strstr( value, "flat" ) )
299
345
        else if( strstr( value, "jvt" ) )
300
346
            p->i_cqm_preset = X264_CQM_JVT;
301
347
        else
302
 
            b_error = 1;
 
348
            p->psz_cqm_file = strdup(value);
303
349
    }
304
350
    OPT("cqmfile")
305
351
        p->psz_cqm_file = strdup(value);
361
407
    }
362
408
    OPT("log")
363
409
        p->i_log_level = atoi(value);
364
 
    OPT("analyse")
 
410
#ifdef VISUALIZE
 
411
    OPT("visualize")
 
412
        p->b_visualize = atobool(value);
 
413
#endif
 
414
    OPT2("analyse", "partitions")
365
415
    {
366
416
        p->analyse.inter = 0;
367
417
        if( strstr( value, "none" ) )  p->analyse.inter =  0;
375
425
    }
376
426
    OPT("8x8dct")
377
427
        p->analyse.b_transform_8x8 = atobool(value);
378
 
    OPT("weightb")
 
428
    OPT2("weightb", "weight-b")
379
429
        p->analyse.b_weighted_bipred = atobool(value);
380
 
    OPT("direct")
 
430
    OPT2("direct", "direct-pred")
381
431
        b_error |= parse_enum( value, x264_direct_pred_names, &p->analyse.i_direct_mv_pred );
 
432
    OPT("direct-8x8")
 
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);
384
436
    OPT("me")
385
437
        b_error |= parse_enum( value, x264_motion_est_names, &p->analyse.i_me_method );
386
 
    OPT("merange")
 
438
    OPT2("merange", "me-range")
387
439
        p->analyse.i_me_range = atoi(value);
388
 
    OPT("mvrange")
 
440
    OPT2("mvrange", "mv-range")
389
441
        p->analyse.i_mv_range = atoi(value);
390
 
    OPT("subme")
 
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);
392
446
    OPT("bime")
393
447
        p->analyse.b_bidir_me = atobool(value);
394
448
    OPT("chroma-me")
395
449
        p->analyse.b_chroma_me = atobool(value);
396
 
    OPT("b-rdo")
 
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);
406
464
    OPT("nr")
407
465
        p->analyse.i_noise_reduction = atoi(value);
408
466
    OPT("bitrate")
410
468
        p->rc.i_bitrate = atoi(value);
411
469
        p->rc.i_rc_method = X264_RC_ABR;
412
470
    }
413
 
    OPT("qp")
 
471
    OPT2("qp", "qp_constant")
414
472
    {
415
473
        p->rc.i_qp_constant = atoi(value);
416
474
        p->rc.i_rc_method = X264_RC_CQP;
417
475
    }
418
476
    OPT("crf")
419
477
    {
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;
422
480
    }
423
 
    OPT("qpmin")
 
481
    OPT2("qpmin", "qp-min")
424
482
        p->rc.i_qp_min = atoi(value);
425
 
    OPT("qpmax")
 
483
    OPT2("qpmax", "qp-max")
426
484
        p->rc.i_qp_max = atoi(value);
427
 
    OPT("qpstep")
 
485
    OPT2("qpstep", "qp-step")
428
486
        p->rc.i_qp_step = atoi(value);
429
487
    OPT("ratetol")
430
488
        p->rc.f_rate_tolerance = !strncmp("inf", value, 3) ? 1e9 : atof(value);
434
492
        p->rc.i_vbv_buffer_size = atoi(value);
435
493
    OPT("vbv-init")
436
494
        p->rc.f_vbv_buffer_init = atof(value);
437
 
    OPT("ipratio")
 
495
    OPT2("ipratio", "ip-factor")
438
496
        p->rc.f_ip_factor = atof(value);
439
 
    OPT("pbratio")
 
497
    OPT2("pbratio", "pb-factor")
440
498
        p->rc.f_pb_factor = atof(value);
441
499
    OPT("pass")
442
500
    {
455
513
        p->rc.f_qcompress = atof(value);
456
514
    OPT("qblur")
457
515
        p->rc.f_qblur = atof(value);
458
 
    OPT("cplxblur")
 
516
    OPT2("cplxblur", "cplx-blur")
459
517
        p->rc.f_complexity_blur = atof(value);
460
518
    OPT("zones")
461
519
        p->rc.psz_zones = strdup(value);
467
525
        p->b_aud = atobool(value);
468
526
    OPT("sps-id")
469
527
        p->i_sps_id = atoi(value);
 
528
    OPT("global-header")
 
529
        p->b_repeat_headers = !atobool(value);
470
530
    OPT("repeat-headers")
471
531
        p->b_repeat_headers = atobool(value);
472
532
    else
473
533
        return X264_PARAM_BAD_NAME;
474
534
#undef OPT
 
535
#undef OPT2
475
536
#undef atobool
476
 
 
 
537
#undef atoi
 
538
#undef atof
 
539
 
 
540
    if( name_buf )
 
541
        free( name_buf );
 
542
 
 
543
    b_error |= value_was_null && !name_was_bool;
477
544
    return b_error ? X264_PARAM_BAD_VALUE : 0;
478
545
}
479
546
 
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 );
825
894
 
826
895
    s += sprintf( s, " bframes=%d", p->i_bframe );
827
896
    if( p->i_bframe )
832
901
                      p->analyse.b_bidir_me );
833
902
    }
834
903
 
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)" : "" );
837
907
 
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 )
842
912
    {
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 );
845
915
        else
846
916
            s += sprintf( s, " bitrate=%d ratetol=%.1f",
847
917
                          p->rc.i_bitrate, p->rc.f_rate_tolerance );