From a0fd4604194e63f5219b1da61afcd19d4bdcfc9f Mon Sep 17 00:00:00 2001 From: Rodeo Date: Thu, 29 Mar 2012 13:31:33 +0000 Subject: encx264: add functionality to retrieve the "preferred" option name for options that have multiple names. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4554 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/common.h | 3 +++ libhb/encavcodec.c | 2 +- libhb/encx264.c | 11 ++++++++++- libhb/encx264.h | 27 +++++++++++++++++++++++++++ libhb/hb_dict.c | 5 ++++- libhb/hb_dict.h | 2 +- 6 files changed, 46 insertions(+), 4 deletions(-) (limited to 'libhb') diff --git a/libhb/common.h b/libhb/common.h index 57d44450b..d38f77a0b 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -989,4 +989,7 @@ const char * const * hb_x264_tunes(); const char * const * hb_x264_profiles(); const char * const * hb_h264_levels(); +// x264 option name/synonym helper +const char * hb_x264_encopt_name( const char * name ); + #endif diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 5a77ceb4b..4a44d4343 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -161,7 +161,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job ) hb_dict_t * lavc_opts = NULL; if( job->advanced_opts != NULL && *job->advanced_opts != '\0' ) { - lavc_opts = hb_encopts_to_dict( job->advanced_opts ); + lavc_opts = hb_encopts_to_dict( job->advanced_opts, job->vcodec ); } /* iterate through lavc_opts and have avutil parse the options for us */ int ret; diff --git a/libhb/encx264.c b/libhb/encx264.c index 7345ab20e..4316ea427 100644 --- a/libhb/encx264.c +++ b/libhb/encx264.c @@ -179,7 +179,7 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job ) hb_dict_t * x264_opts = NULL; if( job->advanced_opts != NULL && *job->advanced_opts != '\0' ) { - x264_opts = hb_encopts_to_dict( job->advanced_opts ); + x264_opts = hb_encopts_to_dict( job->advanced_opts, job->vcodec ); } /* iterate through x264_opts and have libx264 parse the options for us */ int ret; @@ -835,3 +835,12 @@ const char * const * hb_h264_levels() { return h264_level_names; } + +const char * hb_x264_encopt_name( const char * name ) +{ + int i; + for( i = 0; x264_encopt_synonyms[i] && x264_encopt_synonyms[i+1]; i += 2 ) + if( !strcmp( name, x264_encopt_synonyms[i+1] ) ) + return x264_encopt_synonyms[i]; + return name; +} diff --git a/libhb/encx264.h b/libhb/encx264.h index 263e18890..aacce0788 100644 --- a/libhb/encx264.h +++ b/libhb/encx264.h @@ -7,4 +7,31 @@ static const char * const h264_level_names[] = { "1.0", "1b", "1.1", "1.2", "1.3", "2.0", "2.1", "2.2", "3.0", "3.1", "3.2", "4.0", "4.1", "4.2", "5.0", "5.1", 0 }; static const int const h264_level_values[] = { 10, 9, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 0 }; +/* x264 preferred option names (left) and synonyms (right). + * The "preferred" names match names used in x264's param2string function more + * closely than their corresponding synonyms, or are just shorter. */ +static const char * const x264_encopt_synonyms[] = +{ + "deterministic", "n-deterministic", + "level", "level-idc", + "ref", "frameref", + "keyint-min", "min-keyint", + "deblock", "filter", + "analyse", "partitions", + "weightb", "weight-b", + "direct", "direct-pred", + "merange", "me-range", + "mvrange", "mv-range", + "mvrange-thread", "mv-range-thread", + "subme", "subq", + "qp", "qp_constant", + "qpmin", "qp-min", + "qpmax", "qp-max", + "qpstep", "qp-step", + "ipratio", "ip-factor", + "pbratio", "pb-factor", + "cplxblur", "cplx-blur", + 0 +}; + void hb_apply_h264_level( x264_param_t * param, const char * level, const char * x264_profile ); diff --git a/libhb/hb_dict.c b/libhb/hb_dict.c index 11206920c..1592f7e50 100644 --- a/libhb/hb_dict.c +++ b/libhb/hb_dict.c @@ -132,7 +132,7 @@ hb_dict_entry_t * hb_dict_next( hb_dict_t * dict, hb_dict_entry_t * previous ) return NULL; } -hb_dict_t * hb_encopts_to_dict( const char * encopts ) +hb_dict_t * hb_encopts_to_dict( const char * encopts, int encoder ) { hb_dict_t * dict = NULL; if( encopts && *encopts ) @@ -159,6 +159,9 @@ hb_dict_t * hb_encopts_to_dict( const char * encopts ) *value = 0; value++; } + // x264 has multiple names for some options + if( encoder == HB_VCODEC_X264 ) + name = hb_x264_encopt_name( name ); hb_dict_set( &dict, name, value ); } } diff --git a/libhb/hb_dict.h b/libhb/hb_dict.h index b8ca4c562..46be946ce 100644 --- a/libhb/hb_dict.h +++ b/libhb/hb_dict.h @@ -27,7 +27,7 @@ void hb_dict_set( hb_dict_t ** dict_ptr, const char * key, const char * value ) hb_dict_entry_t * hb_dict_get( hb_dict_t * dict, const char * key ); hb_dict_entry_t * hb_dict_next( hb_dict_t * dict, hb_dict_entry_t * previous ); -hb_dict_t * hb_encopts_to_dict( const char * encopts ); +hb_dict_t * hb_encopts_to_dict( const char * encopts, int encoder ); struct hb_dict_entry_s { -- cgit v1.2.3