diff options
author | Rodeo <[email protected]> | 2012-11-12 19:18:29 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2012-11-12 19:18:29 +0000 |
commit | a107cc86c1b9b89863aae4ecab6089279d03e641 (patch) | |
tree | da484f42ebd8b4fed4eb658d64515ddfc869aa83 | |
parent | c3bcb2f455584087613e07f67d1e340aabb73aad (diff) |
hb_x264_param_unparse: miscellaneous cosmetics.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5060 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/common.h | 9 | ||||
-rw-r--r-- | libhb/encx264.c | 627 |
2 files changed, 329 insertions, 307 deletions
diff --git a/libhb/common.h b/libhb/common.h index 713715a34..796c3df38 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -1021,12 +1021,9 @@ int hb_rgb2yuv(int rgb); const char * hb_subsource_name( int source ); // unparse a set of x264 settings to an HB encopts string -char * hb_x264_param_unparse( const char * x264_preset, - const char * x264_tune, - const char * x264_encopts, - const char * x264_profile, - const char * h264_level, - int width, int height ); +char * hb_x264_param_unparse(const char *x264_preset, const char *x264_tune, + const char *x264_encopts, const char *x264_profile, + const char *h264_level, int width, int height); // x264 preset/tune/profile & h264 level helpers const char * const * hb_x264_presets(); diff --git a/libhb/encx264.c b/libhb/encx264.c index 7a3aed270..e6c1eaaa5 100644 --- a/libhb/encx264.c +++ b/libhb/encx264.c @@ -882,78 +882,90 @@ int hb_apply_h264_level(x264_param_t *param, const char *h264_level, return ret; } -char * hb_x264_param_unparse( const char * x264_preset, - const char * x264_tune, - const char * x264_encopts, - const char * x264_profile, - const char * h264_level, - int width, int height ) +char * hb_x264_param_unparse(const char *x264_preset, const char *x264_tune, + const char *x264_encopts, const char *x264_profile, + const char *h264_level, int width, int height) { int i; char buf[32]; - char * unparsed_opts; - hb_dict_t * x264_opts; - hb_dict_entry_t * entry; + char *unparsed_opts; + hb_dict_t *x264_opts; + hb_dict_entry_t *entry; x264_param_t defaults, param; - /* get the global x264 defaults (what we compare against) */ - x264_param_default( &defaults ); + /* + * get the global x264 defaults (what we compare against) + */ + x264_param_default(&defaults); - /* apply the defaults, preset and tune */ - if( x264_param_default_preset( ¶m, x264_preset, x264_tune ) < 0 ) + /* + * apply the defaults, preset and tune + */ + if (x264_param_default_preset(¶m, x264_preset, x264_tune) < 0) { - // Note: GUIs should be able to always specifiy valid preset/tunes, so - // this code will hopefully never be reached - return strdup( "hb_x264_param_unparse: invalid x264 preset/tune" ); + /* + * Note: GUIs should be able to always specifiy valid preset/tunes, so + * this code will hopefully never be reached + */ + return strdup("hb_x264_param_unparse: invalid x264 preset/tune"); } - /* apply the additional advanced x264 options */ - entry = NULL; - x264_opts = hb_encopts_to_dict( x264_encopts, HB_VCODEC_X264 ); - while( ( entry = hb_dict_next( x264_opts, entry ) ) ) + /* + * apply the additional advanced x264 options + */ + entry = NULL; + x264_opts = hb_encopts_to_dict(x264_encopts, HB_VCODEC_X264); + while ((entry = hb_dict_next(x264_opts, entry))) { - // no need to pollute the log with x264_param_parse return codes - x264_param_parse( ¶m, entry->key, entry->value ); + // let's not pollute GUI logs with x264_param_parse return codes + x264_param_parse(¶m, entry->key, entry->value); } - /* apply the x264 profile */ - if( x264_profile && *x264_profile ) + /* + * apply the x264 profile, if specified + */ + if (x264_profile != NULL && *x264_profile) { - if( x264_param_apply_profile( ¶m, x264_profile ) < 0 ) + if (x264_param_apply_profile(¶m, x264_profile) < 0) { - /* Note: x264_param_apply_profile can bail even when the specified - * profile is valid, for example when: - * 1) profile is baseline and interlaced is set - * 2) profile is not high444 and lossless is set - * so this can happen even when calling hb_x264_param_unparse from a + /* + * Note: x264_param_apply_profile can bail even when the specified + * profile is valid; examples: + * + * 1) when profile is baseline and interlaced is set + * 2) when profile is not high444 and lossless is set + * + * So this can happen even when calling hb_x264_param_unparse from a * GUI - maybe we should sanitize settings before calling - * x264_param_apply_profile? */ - hb_dict_free( &x264_opts ); - return strdup( "hb_x264_param_unparse: could not apply x264 profile" ); + * x264_param_apply_profile()? + */ + hb_dict_free(&x264_opts); + return strdup("hb_x264_param_unparse: could not apply x264 profile"); } } - if (h264_level != NULL && h264_level[0]) + /* + * apply the h264 level, if specified + */ + if (h264_level != NULL && *h264_level) { - /* apply the h264 level */ - // set width & height to avoid issues in hb_apply_h264_level + // set width/height to avoid issues in hb_apply_h264_level param.i_width = width; param.i_height = height; - hb_apply_h264_level( ¶m, h264_level, x264_profile, 0 ); + // be quiet so at to not pollute GUI logs + hb_apply_h264_level(¶m, h264_level, x264_profile, 1); } - /* if x264_encopts is NULL, x264_opts wasn't initialized */ - if( !x264_opts ) + /* + * if x264_encopts is NULL, x264_opts wasn't initialized + */ + if (x264_opts == NULL && (x264_opts = hb_dict_init(20)) == NULL) { - // we may have to unparse quite a few options - x264_opts = hb_dict_init( 20 ); - if( !x264_opts ) - { - return strdup( "hb_x264_param_unparse: could not initialize hb_dict_t" ); - } + return strdup("hb_x264_param_unparse: could not initialize hb_dict_t"); } - /* x264 lets you specify some options in multiple ways. For options that we + /* + * x264 lets you specify some options in multiple ways. For options that we * do unparse, clear the forms that don't match how we unparse said option * from the x264_opts dictionary. * @@ -962,539 +974,552 @@ char * hb_x264_param_unparse( const char * x264_preset, * "no-deblock" is a special case as it can't be unparsed to "deblock=0" * * also, don't bother with forms that aren't allowed by the x264 CLI, such - * as "no-bframes" - there are too many. */ - hb_dict_unset( &x264_opts, "no-sliced-threads" ); - hb_dict_unset( &x264_opts, "no-scenecut" ); - hb_dict_unset( &x264_opts, "no-b-adapt" ); - hb_dict_unset( &x264_opts, "no-weightb" ); - hb_dict_unset( &x264_opts, "no-cabac" ); - hb_dict_unset( &x264_opts, "interlaced" ); // we unparse to tff/bff - hb_dict_unset( &x264_opts, "no-interlaced" ); - hb_dict_unset( &x264_opts, "no-8x8dct" ); - hb_dict_unset( &x264_opts, "no-mixed-refs" ); - hb_dict_unset( &x264_opts, "no-fast-pskip" ); - hb_dict_unset( &x264_opts, "no-dct-decimate" ); - hb_dict_unset( &x264_opts, "no-psy" ); - hb_dict_unset( &x264_opts, "no-mbtree" ); - - /* compare defaults to param and unparse to the x264_opts dictionary */ - if( !param.b_sliced_threads != !defaults.b_sliced_threads ) + * as "no-bframes" - there are too many. + */ + hb_dict_unset(&x264_opts, "no-sliced-threads"); + hb_dict_unset(&x264_opts, "no-scenecut"); + hb_dict_unset(&x264_opts, "no-b-adapt"); + hb_dict_unset(&x264_opts, "no-weightb"); + hb_dict_unset(&x264_opts, "no-cabac"); + hb_dict_unset(&x264_opts, "interlaced"); // we unparse to tff/bff + hb_dict_unset(&x264_opts, "no-interlaced"); + hb_dict_unset(&x264_opts, "no-8x8dct"); + hb_dict_unset(&x264_opts, "no-mixed-refs"); + hb_dict_unset(&x264_opts, "no-fast-pskip"); + hb_dict_unset(&x264_opts, "no-dct-decimate"); + hb_dict_unset(&x264_opts, "no-psy"); + hb_dict_unset(&x264_opts, "no-mbtree"); + + /* + * compare defaults to param and unparse to the x264_opts dictionary + */ + if (!param.b_sliced_threads != !defaults.b_sliced_threads) { // can be modified by: tune zerolatency - sprintf( buf, "%d", !!param.b_sliced_threads ); - hb_dict_set( &x264_opts, "sliced-threads", buf ); + sprintf(buf, "%d", !!param.b_sliced_threads); + hb_dict_set(&x264_opts, "sliced-threads", buf); } else { - hb_dict_unset( &x264_opts, "sliced-threads" ); + hb_dict_unset(&x264_opts, "sliced-threads"); } - if( param.i_sync_lookahead != defaults.i_sync_lookahead ) + if (param.i_sync_lookahead != defaults.i_sync_lookahead) { // can be modified by: tune zerolatency - sprintf( buf, "%d", param.i_sync_lookahead ); - hb_dict_set( &x264_opts, "sync-lookahead", buf ); + sprintf(buf, "%d", param.i_sync_lookahead); + hb_dict_set(&x264_opts, "sync-lookahead", buf); } else { - hb_dict_unset( &x264_opts, "sync-lookahead" ); + hb_dict_unset(&x264_opts, "sync-lookahead"); } - if( param.i_level_idc != defaults.i_level_idc ) + if (param.i_level_idc != defaults.i_level_idc) { // can be modified by: level - for( i = 0; hb_h264_level_values[i]; i++ ) - if( param.i_level_idc == hb_h264_level_values[i] ) - hb_dict_set( &x264_opts, "level", hb_h264_level_names[i] ); + for (i = 0; hb_h264_level_values[i]; i++) + if (param.i_level_idc == hb_h264_level_values[i]) + hb_dict_set(&x264_opts, "level", hb_h264_level_names[i]); } else { - hb_dict_unset( &x264_opts, "level" ); + hb_dict_unset(&x264_opts, "level"); } - if( param.i_frame_reference != defaults.i_frame_reference ) + if (param.i_frame_reference != defaults.i_frame_reference) { // can be modified by: presets, tunes, level - sprintf( buf, "%d", param.i_frame_reference ); - hb_dict_set( &x264_opts, "ref", buf ); + sprintf(buf, "%d", param.i_frame_reference); + hb_dict_set(&x264_opts, "ref", buf); } else { - hb_dict_unset( &x264_opts, "ref" ); + hb_dict_unset(&x264_opts, "ref"); } - if( param.i_scenecut_threshold != defaults.i_scenecut_threshold ) + if (param.i_scenecut_threshold != defaults.i_scenecut_threshold) { // can be modified by: preset ultrafast - sprintf( buf, "%d", param.i_scenecut_threshold ); - hb_dict_set( &x264_opts, "scenecut", buf ); + sprintf(buf, "%d", param.i_scenecut_threshold); + hb_dict_set(&x264_opts, "scenecut", buf); } else { - hb_dict_unset( &x264_opts, "scenecut" ); + hb_dict_unset(&x264_opts, "scenecut"); } - if( param.i_bframe != defaults.i_bframe ) + if (param.i_bframe != defaults.i_bframe) { // can be modified by: presets, tunes, profile, level - sprintf( buf, "%d", param.i_bframe ); - hb_dict_set( &x264_opts, "bframes", buf ); + sprintf(buf, "%d", param.i_bframe); + hb_dict_set(&x264_opts, "bframes", buf); } else { - hb_dict_unset( &x264_opts, "bframes" ); + hb_dict_unset(&x264_opts, "bframes"); } - if( param.i_bframe > 0 ) + if (param.i_bframe > 0) { - if( param.i_bframe_adaptive != defaults.i_bframe_adaptive ) + if (param.i_bframe_adaptive != defaults.i_bframe_adaptive) { // can be modified by: presets - sprintf( buf, "%d", param.i_bframe_adaptive ); - hb_dict_set( &x264_opts, "b-adapt", buf ); + sprintf(buf, "%d", param.i_bframe_adaptive); + hb_dict_set(&x264_opts, "b-adapt", buf); } else { - hb_dict_unset( &x264_opts, "b-adapt" ); + hb_dict_unset(&x264_opts, "b-adapt"); } - if( param.i_bframe > 1 && - param.i_bframe_pyramid != defaults.i_bframe_pyramid ) + if (param.i_bframe > 1 && + param.i_bframe_pyramid != defaults.i_bframe_pyramid) { // can be modified by: level - if( param.i_bframe_pyramid < X264_B_PYRAMID_NONE ) + if (param.i_bframe_pyramid < X264_B_PYRAMID_NONE) param.i_bframe_pyramid = X264_B_PYRAMID_NONE; - if( param.i_bframe_pyramid > X264_B_PYRAMID_NORMAL ) + if (param.i_bframe_pyramid > X264_B_PYRAMID_NORMAL) param.i_bframe_pyramid = X264_B_PYRAMID_NORMAL; - for( i = 0; x264_b_pyramid_names[i]; i++ ) - if( param.i_bframe_pyramid == i ) - hb_dict_set( &x264_opts, "b-pyramid", x264_b_pyramid_names[i] ); + for (i = 0; x264_b_pyramid_names[i] != NULL; i++) + if (param.i_bframe_pyramid == i) + hb_dict_set(&x264_opts, "b-pyramid", + x264_b_pyramid_names[i]); } else { - hb_dict_unset( &x264_opts, "b-pyramid" ); + hb_dict_unset(&x264_opts, "b-pyramid"); } - if( param.analyse.i_direct_mv_pred != defaults.analyse.i_direct_mv_pred ) + if (param.analyse.i_direct_mv_pred != defaults.analyse.i_direct_mv_pred) { // can be modified by: presets - if( param.analyse.i_direct_mv_pred < X264_DIRECT_PRED_NONE ) + if (param.analyse.i_direct_mv_pred < X264_DIRECT_PRED_NONE) param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_NONE; - if( param.analyse.i_direct_mv_pred > X264_DIRECT_PRED_AUTO ) + if (param.analyse.i_direct_mv_pred > X264_DIRECT_PRED_AUTO) param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_AUTO; - for( i = 0; x264_direct_pred_names[i]; i++ ) - if( param.analyse.i_direct_mv_pred == i ) - hb_dict_set( &x264_opts, "direct", x264_direct_pred_names[i] ); + for (i = 0; x264_direct_pred_names[i] != NULL; i++) + if (param.analyse.i_direct_mv_pred == i) + hb_dict_set(&x264_opts, "direct", + x264_direct_pred_names[i]); } else { - hb_dict_unset( &x264_opts, "direct" ); + hb_dict_unset(&x264_opts, "direct"); } - if( !param.analyse.b_weighted_bipred != !defaults.analyse.b_weighted_bipred ) + if (!param.analyse.b_weighted_bipred != + !defaults.analyse.b_weighted_bipred) { // can be modified by: preset ultrafast, tune fastdecode - sprintf( buf, "%d", !!param.analyse.b_weighted_bipred ); - hb_dict_set( &x264_opts, "weightb", buf ); + sprintf(buf, "%d", !!param.analyse.b_weighted_bipred); + hb_dict_set(&x264_opts, "weightb", buf); } else { - hb_dict_unset( &x264_opts, "weightb" ); + hb_dict_unset(&x264_opts, "weightb"); } } else { // no bframes, these options have no effect - hb_dict_unset( &x264_opts, "b-adapt" ); - hb_dict_unset( &x264_opts, "b-pyramid" ); - hb_dict_unset( &x264_opts, "direct" ); - hb_dict_unset( &x264_opts, "weightb" ); - hb_dict_unset( &x264_opts, "b-bias" ); - hb_dict_unset( &x264_opts, "open-gop" ); + hb_dict_unset(&x264_opts, "b-adapt"); + hb_dict_unset(&x264_opts, "b-pyramid"); + hb_dict_unset(&x264_opts, "direct"); + hb_dict_unset(&x264_opts, "weightb"); + hb_dict_unset(&x264_opts, "b-bias"); + hb_dict_unset(&x264_opts, "open-gop"); } - if( !param.b_deblocking_filter != !defaults.b_deblocking_filter ) + if (!param.b_deblocking_filter != !defaults.b_deblocking_filter) { // can be modified by: preset ultrafast, tune fastdecode - sprintf( buf, "%d", !param.b_deblocking_filter ); - hb_dict_set( &x264_opts, "no-deblock", buf ); + sprintf(buf, "%d", !param.b_deblocking_filter); + hb_dict_set(&x264_opts, "no-deblock", buf); } else { - hb_dict_unset( &x264_opts, "no-deblock" ); + hb_dict_unset(&x264_opts, "no-deblock"); } - if( param.b_deblocking_filter && - ( param.i_deblocking_filter_alphac0 != defaults.i_deblocking_filter_alphac0 || - param.i_deblocking_filter_beta != defaults.i_deblocking_filter_beta ) ) + if (param.b_deblocking_filter && + (param.i_deblocking_filter_alphac0 != defaults.i_deblocking_filter_alphac0 || + param.i_deblocking_filter_beta != defaults.i_deblocking_filter_beta)) { // can be modified by: tunes - sprintf( buf, "%d,%d", param.i_deblocking_filter_alphac0, param.i_deblocking_filter_beta ); - hb_dict_set( &x264_opts, "deblock", buf ); + sprintf(buf, "%d,%d", param.i_deblocking_filter_alphac0, + param.i_deblocking_filter_beta); + hb_dict_set(&x264_opts, "deblock", buf); } else { - hb_dict_unset( &x264_opts, "deblock" ); + hb_dict_unset(&x264_opts, "deblock"); } - if( !param.b_cabac != !defaults.b_cabac ) + if (!param.b_cabac != !defaults.b_cabac) { // can be modified by: preset ultrafast, tune fastdecode, profile - sprintf( buf, "%d", !!param.b_cabac ); - hb_dict_set( &x264_opts, "cabac", buf ); + sprintf(buf, "%d", !!param.b_cabac); + hb_dict_set(&x264_opts, "cabac", buf); } else { - hb_dict_unset( &x264_opts, "cabac" ); + hb_dict_unset(&x264_opts, "cabac"); } - if( param.b_interlaced != defaults.b_interlaced ) + if (param.b_interlaced != defaults.b_interlaced) { - if( param.b_tff ) + if (param.b_tff) { - hb_dict_set( &x264_opts, "tff", "1" ); - hb_dict_unset( &x264_opts, "bff" ); + hb_dict_set(&x264_opts, "tff", "1"); + hb_dict_unset(&x264_opts, "bff"); } else { - hb_dict_set( &x264_opts, "bff", "1" ); - hb_dict_unset( &x264_opts, "tff" ); + hb_dict_set(&x264_opts, "bff", "1"); + hb_dict_unset(&x264_opts, "tff"); } - hb_dict_unset( &x264_opts, "fake-interlaced" ); + hb_dict_unset(&x264_opts, "fake-interlaced"); } - else if( param.b_fake_interlaced != defaults.b_fake_interlaced ) + else if (param.b_fake_interlaced != defaults.b_fake_interlaced) { - hb_dict_set( &x264_opts, "fake-interlaced", "1" ); - hb_dict_unset( &x264_opts, "tff" ); - hb_dict_unset( &x264_opts, "bff" ); + hb_dict_set(&x264_opts, "fake-interlaced", "1"); + hb_dict_unset(&x264_opts, "tff"); + hb_dict_unset(&x264_opts, "bff"); } else { - hb_dict_unset( &x264_opts, "tff" ); - hb_dict_unset( &x264_opts, "bff" ); - hb_dict_unset( &x264_opts, "fake-interlaced" ); + hb_dict_unset(&x264_opts, "tff"); + hb_dict_unset(&x264_opts, "bff"); + hb_dict_unset(&x264_opts, "fake-interlaced"); } - if( param.i_cqm_preset == defaults.i_cqm_preset && - param.psz_cqm_file == defaults.psz_cqm_file ) + if (param.i_cqm_preset == defaults.i_cqm_preset && + param.psz_cqm_file == defaults.psz_cqm_file) { // can be reset to default by: profile - hb_dict_unset( &x264_opts, "cqm" ); - hb_dict_unset( &x264_opts, "cqm4" ); - hb_dict_unset( &x264_opts, "cqm8" ); - hb_dict_unset( &x264_opts, "cqm4i" ); - hb_dict_unset( &x264_opts, "cqm4p" ); - hb_dict_unset( &x264_opts, "cqm8i" ); - hb_dict_unset( &x264_opts, "cqm8p" ); - hb_dict_unset( &x264_opts, "cqm4iy" ); - hb_dict_unset( &x264_opts, "cqm4ic" ); - hb_dict_unset( &x264_opts, "cqm4py" ); - hb_dict_unset( &x264_opts, "cqm4pc" ); - } - if( param.analyse.inter != defaults.analyse.inter ) + hb_dict_unset(&x264_opts, "cqm"); + hb_dict_unset(&x264_opts, "cqm4"); + hb_dict_unset(&x264_opts, "cqm8"); + hb_dict_unset(&x264_opts, "cqm4i"); + hb_dict_unset(&x264_opts, "cqm4p"); + hb_dict_unset(&x264_opts, "cqm8i"); + hb_dict_unset(&x264_opts, "cqm8p"); + hb_dict_unset(&x264_opts, "cqm4iy"); + hb_dict_unset(&x264_opts, "cqm4ic"); + hb_dict_unset(&x264_opts, "cqm4py"); + hb_dict_unset(&x264_opts, "cqm4pc"); + } + /* + * Note: param.analyse.intra can only be modified directly or by using + * x264 --preset ultrafast, but not via the "analyse" option + */ + if (param.analyse.inter != defaults.analyse.inter) { // can be modified by: presets, tune touhou - if( !param.analyse.inter ) + if (!param.analyse.inter) { - hb_dict_set( &x264_opts, "analyse", "none" ); + hb_dict_set(&x264_opts, "analyse", "none"); } - else if( ( param.analyse.inter & X264_ANALYSE_I4x4 ) && - ( param.analyse.inter & X264_ANALYSE_I8x8 ) && - ( param.analyse.inter & X264_ANALYSE_PSUB16x16 ) && - ( param.analyse.inter & X264_ANALYSE_PSUB8x8 ) && - ( param.analyse.inter & X264_ANALYSE_BSUB16x16 ) ) + else if ((param.analyse.inter & X264_ANALYSE_I4x4) && + (param.analyse.inter & X264_ANALYSE_I8x8) && + (param.analyse.inter & X264_ANALYSE_PSUB16x16) && + (param.analyse.inter & X264_ANALYSE_PSUB8x8) && + (param.analyse.inter & X264_ANALYSE_BSUB16x16)) { - hb_dict_set( &x264_opts, "analyse", "all" ); + hb_dict_set(&x264_opts, "analyse", "all"); } else { - sprintf( buf, "%s", "" ); - if( param.analyse.inter & X264_ANALYSE_I4x4 ) + sprintf(buf, "%s", ""); + if (param.analyse.inter & X264_ANALYSE_I4x4) { - strcat( buf, "i4x4" ); + strcat(buf, "i4x4"); } - if( param.analyse.inter & X264_ANALYSE_I8x8 ) + if (param.analyse.inter & X264_ANALYSE_I8x8) { - if( strlen( buf ) ) - strcat( buf, "," ); - strcat( buf, "i8x8" ); + if (*buf) + strcat(buf, ","); + strcat(buf, "i8x8"); } - if( param.analyse.inter & X264_ANALYSE_PSUB16x16 ) + if (param.analyse.inter & X264_ANALYSE_PSUB16x16) { - if( strlen( buf ) ) - strcat( buf, "," ); - strcat( buf, "p8x8" ); + if (*buf) + strcat(buf, ","); + strcat(buf, "p8x8"); } - if( param.analyse.inter & X264_ANALYSE_PSUB8x8 ) + if (param.analyse.inter & X264_ANALYSE_PSUB8x8) { - if( strlen( buf ) ) - strcat( buf, "," ); - strcat( buf, "p4x4" ); + if (*buf) + strcat(buf, ","); + strcat(buf, "p4x4"); } - if( param.analyse.inter & X264_ANALYSE_BSUB16x16 ) + if (param.analyse.inter & X264_ANALYSE_BSUB16x16) { - if( strlen( buf ) ) - strcat( buf, "," ); - strcat( buf, "b8x8" ); + if (*buf) + strcat(buf, ","); + strcat(buf, "b8x8"); } - hb_dict_set( &x264_opts, "analyse", buf ); + hb_dict_set(&x264_opts, "analyse", buf); } - // note: param.analyse.intra can only be modified directly or by using - // x264 --preset ultrafast, but not via the "analyse" option } else { - hb_dict_unset( &x264_opts, "analyse" ); + hb_dict_unset(&x264_opts, "analyse"); } - if( !param.analyse.b_transform_8x8 != !defaults.analyse.b_transform_8x8 ) + if (!param.analyse.b_transform_8x8 != !defaults.analyse.b_transform_8x8) { // can be modified by: preset ultrafast, profile - sprintf( buf, "%d", !!param.analyse.b_transform_8x8 ); - hb_dict_set( &x264_opts, "8x8dct", buf ); + sprintf(buf, "%d", !!param.analyse.b_transform_8x8); + hb_dict_set(&x264_opts, "8x8dct", buf); } else { - hb_dict_unset( &x264_opts, "8x8dct" ); + hb_dict_unset(&x264_opts, "8x8dct"); } - if( param.analyse.i_weighted_pred != defaults.analyse.i_weighted_pred ) + if (param.analyse.i_weighted_pred != defaults.analyse.i_weighted_pred) { // can be modified by: presets, tune fastdecode, profile - sprintf( buf, "%d", param.analyse.i_weighted_pred ); - hb_dict_set( &x264_opts, "weightp", buf ); + sprintf(buf, "%d", param.analyse.i_weighted_pred); + hb_dict_set(&x264_opts, "weightp", buf); } else { - hb_dict_unset( &x264_opts, "weightp" ); + hb_dict_unset(&x264_opts, "weightp"); } - if( param.analyse.i_me_method != defaults.analyse.i_me_method ) + if (param.analyse.i_me_method != defaults.analyse.i_me_method) { // can be modified by: presets - if( param.analyse.i_me_method < X264_ME_DIA ) + if (param.analyse.i_me_method < X264_ME_DIA) param.analyse.i_me_method = X264_ME_DIA; - if( param.analyse.i_me_method > X264_ME_TESA ) + if (param.analyse.i_me_method > X264_ME_TESA) param.analyse.i_me_method = X264_ME_TESA; - for( i = 0; x264_motion_est_names[i]; i++ ) - if( param.analyse.i_me_method == i ) - hb_dict_set( &x264_opts, "me", x264_motion_est_names[i] ); + for (i = 0; x264_motion_est_names[i] != NULL; i++) + if (param.analyse.i_me_method == i) + hb_dict_set(&x264_opts, "me", x264_motion_est_names[i]); } else { - hb_dict_unset( &x264_opts, "me" ); + hb_dict_unset(&x264_opts, "me"); } - if( param.analyse.i_me_range != defaults.analyse.i_me_range ) + if (param.analyse.i_me_range != defaults.analyse.i_me_range) { // can be modified by: presets - sprintf( buf, "%d", param.analyse.i_me_range ); - hb_dict_set( &x264_opts, "merange", buf ); + sprintf(buf, "%d", param.analyse.i_me_range); + hb_dict_set(&x264_opts, "merange", buf); } else { - hb_dict_unset( &x264_opts, "merange" ); + hb_dict_unset(&x264_opts, "merange"); } - if( param.analyse.i_mv_range != defaults.analyse.i_mv_range ) + if (param.analyse.i_mv_range != defaults.analyse.i_mv_range) { // can be modified by: level - sprintf( buf, "%d", param.analyse.i_mv_range ); - hb_dict_set( &x264_opts, "mvrange", buf ); + sprintf(buf, "%d", param.analyse.i_mv_range); + hb_dict_set(&x264_opts, "mvrange", buf); } else { - hb_dict_unset( &x264_opts, "mvrange" ); + hb_dict_unset(&x264_opts, "mvrange"); } - if( param.analyse.i_subpel_refine > 9 && - ( param.analyse.i_trellis < 2 || !param.rc.i_aq_mode ) ) + if (param.analyse.i_subpel_refine > 9 && (param.rc.i_aq_mode == 0 || + param.analyse.i_trellis < 2)) { // subme 10 & 11 require AQ and trellis 2 param.analyse.i_subpel_refine = 9; } - if( param.analyse.i_subpel_refine != defaults.analyse.i_subpel_refine ) + if (param.analyse.i_subpel_refine != defaults.analyse.i_subpel_refine) { // can be modified by: presets - sprintf( buf, "%d", param.analyse.i_subpel_refine ); - hb_dict_set( &x264_opts, "subme", buf ); + sprintf(buf, "%d", param.analyse.i_subpel_refine); + hb_dict_set(&x264_opts, "subme", buf); } else { - hb_dict_unset( &x264_opts, "subme" ); + hb_dict_unset(&x264_opts, "subme"); } - if( !param.analyse.b_mixed_references != !defaults.analyse.b_mixed_references ) + if (!param.analyse.b_mixed_references != + !defaults.analyse.b_mixed_references) { // can be modified by: presets - sprintf( buf, "%d", !!param.analyse.b_mixed_references ); - hb_dict_set( &x264_opts, "mixed-refs", buf ); + sprintf(buf, "%d", !!param.analyse.b_mixed_references); + hb_dict_set(&x264_opts, "mixed-refs", buf); } else { - hb_dict_unset( &x264_opts, "mixed-refs" ); + hb_dict_unset(&x264_opts, "mixed-refs"); } - if( param.analyse.i_trellis != defaults.analyse.i_trellis ) + if (param.analyse.i_trellis != defaults.analyse.i_trellis) { // can be modified by: presets - sprintf( buf, "%d", param.analyse.i_trellis ); - hb_dict_set( &x264_opts, "trellis", buf ); + sprintf(buf, "%d", param.analyse.i_trellis); + hb_dict_set(&x264_opts, "trellis", buf); } else { - hb_dict_unset( &x264_opts, "trellis" ); + hb_dict_unset(&x264_opts, "trellis"); } - if( !param.analyse.b_fast_pskip != !defaults.analyse.b_fast_pskip ) + if (!param.analyse.b_fast_pskip != !defaults.analyse.b_fast_pskip) { // can be modified by: preset placebo - sprintf( buf, "%d", !!param.analyse.b_fast_pskip ); - hb_dict_set( &x264_opts, "fast-pskip", buf ); + sprintf(buf, "%d", !!param.analyse.b_fast_pskip); + hb_dict_set(&x264_opts, "fast-pskip", buf); } else { - hb_dict_unset( &x264_opts, "fast-pskip" ); + hb_dict_unset(&x264_opts, "fast-pskip"); } - if( !param.analyse.b_dct_decimate != !defaults.analyse.b_dct_decimate ) + if (!param.analyse.b_dct_decimate != !defaults.analyse.b_dct_decimate) { // can be modified by: tune grain - sprintf( buf, "%d", !!param.analyse.b_dct_decimate ); - hb_dict_set( &x264_opts, "dct-decimate", buf ); + sprintf(buf, "%d", !!param.analyse.b_dct_decimate); + hb_dict_set(&x264_opts, "dct-decimate", buf); } else { - hb_dict_unset( &x264_opts, "dct-decimate" ); + hb_dict_unset(&x264_opts, "dct-decimate"); } - if( !param.analyse.b_psy != !defaults.analyse.b_psy ) + if (!param.analyse.b_psy != !defaults.analyse.b_psy) { // can be modified by: tunes - sprintf( buf, "%d", !!param.analyse.b_psy ); - hb_dict_set( &x264_opts, "psy", buf ); + sprintf(buf, "%d", !!param.analyse.b_psy); + hb_dict_set(&x264_opts, "psy", buf); } else { - hb_dict_unset( &x264_opts, "psy" ); + hb_dict_unset(&x264_opts, "psy"); } - if( param.analyse.b_psy && - ( param.analyse.f_psy_rd != defaults.analyse.f_psy_rd || - param.analyse.f_psy_trellis != defaults.analyse.f_psy_trellis ) ) + if (param.analyse.b_psy && + (param.analyse.f_psy_rd != defaults.analyse.f_psy_rd || + param.analyse.f_psy_trellis != defaults.analyse.f_psy_trellis)) { // can be modified by: tunes - sprintf( buf, "%.2f,%.2f", param.analyse.f_psy_rd, param.analyse.f_psy_trellis ); - hb_dict_set( &x264_opts, "psy-rd", buf ); + sprintf(buf, "%.2f,%.2f", param.analyse.f_psy_rd, + param.analyse.f_psy_trellis); + hb_dict_set(&x264_opts, "psy-rd", buf); } else { - hb_dict_unset( &x264_opts, "psy-rd" ); + hb_dict_unset(&x264_opts, "psy-rd"); } - // note: while deadzone is incompatible with trellis, it still has a slight - // effect on the output even when trellis is on, so always unparse it. - if( param.analyse.i_luma_deadzone[0] != defaults.analyse.i_luma_deadzone[0] ) + /* + * Note: while deadzone is incompatible with trellis, it still has a slight + * effect on the output even when trellis is on, so always unparse it. + */ + if (param.analyse.i_luma_deadzone[0] != defaults.analyse.i_luma_deadzone[0]) { // can be modified by: tune grain - sprintf( buf, "%d", param.analyse.i_luma_deadzone[0] ); - hb_dict_set( &x264_opts, "deadzone-inter", buf ); + sprintf(buf, "%d", param.analyse.i_luma_deadzone[0]); + hb_dict_set(&x264_opts, "deadzone-inter", buf); } else { - hb_dict_unset( &x264_opts, "deadzone-inter" ); + hb_dict_unset(&x264_opts, "deadzone-inter"); } - if( param.analyse.i_luma_deadzone[1] != defaults.analyse.i_luma_deadzone[1] ) + if (param.analyse.i_luma_deadzone[1] != defaults.analyse.i_luma_deadzone[1]) { // can be modified by: tune grain - sprintf( buf, "%d", param.analyse.i_luma_deadzone[1] ); - hb_dict_set( &x264_opts, "deadzone-intra", buf ); + sprintf(buf, "%d", param.analyse.i_luma_deadzone[1]); + hb_dict_set(&x264_opts, "deadzone-intra", buf); } else { - hb_dict_unset( &x264_opts, "deadzone-intra" ); + hb_dict_unset(&x264_opts, "deadzone-intra"); } - if( param.rc.i_vbv_buffer_size != defaults.rc.i_vbv_buffer_size ) + if (param.rc.i_vbv_buffer_size != defaults.rc.i_vbv_buffer_size) { // can be modified by: level - sprintf( buf, "%d", param.rc.i_vbv_buffer_size ); - hb_dict_set( &x264_opts, "vbv-bufsize", buf ); - if( param.rc.i_vbv_max_bitrate != defaults.rc.i_vbv_max_bitrate ) + sprintf(buf, "%d", param.rc.i_vbv_buffer_size); + hb_dict_set(&x264_opts, "vbv-bufsize", buf); + if (param.rc.i_vbv_max_bitrate != defaults.rc.i_vbv_max_bitrate) { // can be modified by: level - sprintf( buf, "%d", param.rc.i_vbv_max_bitrate ); - hb_dict_set( &x264_opts, "vbv-bitrate", buf ); + sprintf(buf, "%d", param.rc.i_vbv_max_bitrate); + hb_dict_set(&x264_opts, "vbv-bitrate", buf); } else { - hb_dict_unset( &x264_opts, "vbv-maxrate" ); + hb_dict_unset(&x264_opts, "vbv-maxrate"); } } else { - hb_dict_unset( &x264_opts, "vbv-bufsize" ); - hb_dict_unset( &x264_opts, "vbv-maxrate" ); + hb_dict_unset(&x264_opts, "vbv-bufsize"); + hb_dict_unset(&x264_opts, "vbv-maxrate"); } - if( param.rc.f_ip_factor != defaults.rc.f_ip_factor ) + if (param.rc.f_ip_factor != defaults.rc.f_ip_factor) { // can be modified by: tune grain - sprintf( buf, "%.2f", param.rc.f_ip_factor ); - hb_dict_set( &x264_opts, "ipratio", buf ); + sprintf(buf, "%.2f", param.rc.f_ip_factor); + hb_dict_set(&x264_opts, "ipratio", buf); } else { - hb_dict_unset( &x264_opts, "ipratio" ); + hb_dict_unset(&x264_opts, "ipratio"); } - if( param.i_bframe > 0 && !param.rc.b_mb_tree && - param.rc.f_pb_factor != defaults.rc.f_pb_factor ) + if (param.i_bframe > 0 && !param.rc.b_mb_tree && + param.rc.f_pb_factor != defaults.rc.f_pb_factor) { // can be modified by: tune grain - sprintf( buf, "%.2f", param.rc.f_pb_factor ); - hb_dict_set( &x264_opts, "pbratio", buf ); + sprintf(buf, "%.2f", param.rc.f_pb_factor); + hb_dict_set(&x264_opts, "pbratio", buf); } else { // pbratio requires bframes and is incomaptible with mbtree - hb_dict_unset( &x264_opts, "pbratio" ); + hb_dict_unset(&x264_opts, "pbratio"); } - if( param.rc.f_qcompress != defaults.rc.f_qcompress ) + if (param.rc.f_qcompress != defaults.rc.f_qcompress) { // can be modified by: tune grain - sprintf( buf, "%.2f", param.rc.f_qcompress ); - hb_dict_set( &x264_opts, "qcomp", buf ); + sprintf(buf, "%.2f", param.rc.f_qcompress); + hb_dict_set(&x264_opts, "qcomp", buf); } else { - hb_dict_unset( &x264_opts, "qcomp" ); + hb_dict_unset(&x264_opts, "qcomp"); } - if( param.rc.i_aq_mode != defaults.rc.i_aq_mode ) + if (param.rc.i_aq_mode != defaults.rc.i_aq_mode) { // can be modified by: preset ultrafast, tune psnr - sprintf( buf, "%d", param.rc.i_aq_mode ); - hb_dict_set( &x264_opts, "aq-mode", buf ); + sprintf(buf, "%d", param.rc.i_aq_mode); + hb_dict_set(&x264_opts, "aq-mode", buf); } else { - hb_dict_unset( &x264_opts, "aq-mode" ); + hb_dict_unset(&x264_opts, "aq-mode"); } - if( param.rc.i_aq_mode > 0 && - param.rc.f_aq_strength != defaults.rc.f_aq_strength ) + if (param.rc.i_aq_mode > 0 && + param.rc.f_aq_strength != defaults.rc.f_aq_strength) { // can be modified by: tunes - sprintf( buf, "%.2f", param.rc.f_aq_strength ); - hb_dict_set( &x264_opts, "aq-strength", buf ); + sprintf(buf, "%.2f", param.rc.f_aq_strength); + hb_dict_set(&x264_opts, "aq-strength", buf); } else { - hb_dict_unset( &x264_opts, "aq-strength" ); + hb_dict_unset(&x264_opts, "aq-strength"); } - if( !param.rc.b_mb_tree != !defaults.rc.b_mb_tree ) + if (!param.rc.b_mb_tree != !defaults.rc.b_mb_tree) { // can be modified by: presets, tune zerolatency - sprintf( buf, "%d", !!param.rc.b_mb_tree ); - hb_dict_set( &x264_opts, "mbtree", buf ); + sprintf(buf, "%d", !!param.rc.b_mb_tree); + hb_dict_set(&x264_opts, "mbtree", buf); } else { - hb_dict_unset( &x264_opts, "mbtree" ); + hb_dict_unset(&x264_opts, "mbtree"); } - if( param.rc.i_lookahead != defaults.rc.i_lookahead ) + if (param.rc.i_lookahead != defaults.rc.i_lookahead) { // can be modified by: presets, tune zerolatency - sprintf( buf, "%d", param.rc.i_lookahead ); - hb_dict_set( &x264_opts, "rc-lookahead", buf ); + sprintf(buf, "%d", param.rc.i_lookahead); + hb_dict_set(&x264_opts, "rc-lookahead", buf); } else { - hb_dict_unset( &x264_opts, "rc-lookahead" ); + hb_dict_unset(&x264_opts, "rc-lookahead"); } - if( !param.b_vfr_input != !defaults.b_vfr_input ) + if (!param.b_vfr_input != !defaults.b_vfr_input) { // can be modified by: tune zerolatency - sprintf( buf, "%d", !param.b_vfr_input ); - hb_dict_set( &x264_opts, "force-cfr", buf ); + sprintf(buf, "%d", !param.b_vfr_input); + hb_dict_set(&x264_opts, "force-cfr", buf); } else { - hb_dict_unset( &x264_opts, "force-cfr" ); + hb_dict_unset(&x264_opts, "force-cfr"); } /* convert the x264_opts dictionary to an encopts string */ - unparsed_opts = hb_dict_to_encopts( x264_opts ); - hb_dict_free( &x264_opts ); + unparsed_opts = hb_dict_to_encopts(x264_opts); + hb_dict_free(&x264_opts); /* we're done */ return unparsed_opts; |