Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From a5758310739240e7adba9131467781d49b188ec0 Mon Sep 17 00:00:00 2001
- From: George Stephanos <gaf.stephanos@gmail.com>
- Date: Tue, 14 Dec 2010 21:42:49 +0200
- Subject: [PATCH] --device option added with ~basic functionality.
- ---
- common/common.c | 269 +++++++++++++++++++++++++++++++++++++++++++++++++----
- encoder/encoder.c | 2 +-
- encoder/set.c | 26 +++++-
- encoder/set.h | 1 +
- x264.c | 84 ++++++++--------
- x264.h | 50 ++++++++++-
- 6 files changed, 368 insertions(+), 64 deletions(-)
- diff --git a/common/common.c b/common/common.c
- index 26b62a3..9653b62 100644
- --- a/common/common.c
- +++ b/common/common.c
- @@ -25,14 +25,18 @@
- *****************************************************************************/
- #include "common.h"
- +#include "encoder/set.h"
- #include <stdarg.h>
- #include <ctype.h>
- +#include <math.h>
- #if HAVE_MALLOC_H
- #include <malloc.h>
- #endif
- +#define DELIMETERS ",./-+"
- +
- const int x264_bit_depth = BIT_DEPTH;
- static void x264_log_default( void *, int, const char *, va_list );
- @@ -66,7 +70,7 @@ void x264_param_default( x264_param_t *param )
- param->vui.i_chroma_loc= 0; /* left center */
- param->i_fps_num = 25;
- param->i_fps_den = 1;
- - param->i_level_idc = -1;
- + param->i_level_idc = X264_LEVEL_IDC_AUTO;
- param->i_slice_max_size = 0;
- param->i_slice_max_mbs = 0;
- param->i_slice_count = 0;
- @@ -297,8 +301,8 @@ static int x264_param_apply_tune( x264_param_t *param, const char *tune )
- char *tmp = x264_malloc( strlen( tune ) + 1 );
- if( !tmp )
- return -1;
- - tmp = strcpy( tmp, tune );
- - char *s = strtok( tmp, ",./-+" );
- + strcpy( tmp, tune );
- + char *s = strtok( tmp, DELIMETERS );
- int psy_tuning_used = 0;
- while( s )
- {
- @@ -392,7 +396,7 @@ static int x264_param_apply_tune( x264_param_t *param, const char *tune )
- psy_failure:
- x264_log( NULL, X264_LOG_WARNING, "only 1 psy tuning can be used: ignoring tune %s\n", s );
- }
- - s = strtok( NULL, ",./-+" );
- + s = strtok( NULL, DELIMETERS );
- }
- x264_free( tmp );
- return 0;
- @@ -424,21 +428,49 @@ void x264_param_apply_fastfirstpass( x264_param_t *param )
- }
- }
- -int x264_param_apply_profile( x264_param_t *param, const char *profile )
- +static void x264_calculate_resolution( const x264_level_t *level, int width, int height, double fps,
- + int b_interlaced, x264_param_compat_t *compat )
- {
- - if( !profile )
- - return 0;
- + if( !compat )
- + return;
- + int w = width, h = height;
- + double max_mbs = X264_MIN( level->mbps / fps, level->frame_size );
- + double frac = sqrt( (256 * max_mbs) / (w * h) );
- + double step = 0.01*frac;
- + int mbs_w = (w+15)/16;
- + int mbs_h = (h+15)/16;
- + while( mbs_w * mbs_h > max_mbs )
- + {
- + w = round( width*frac );
- + h = round( height*frac );
- + w &= ~1;
- + h = h&~1&~(2*b_interlaced);
- + mbs_w = (w+15)/16;
- + mbs_h = (h+15)/16;
- + frac -= step;
- + }
- + compat->i_width = w;
- + compat->i_height = h;
- +}
- -#if BIT_DEPTH > 8
- - if( !strcasecmp( profile, "baseline" ) || !strcasecmp( profile, "main" ) ||
- - !strcasecmp( profile, "high" ) )
- - {
- - x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d.\n", profile, BIT_DEPTH );
- - return -1;
- - }
- -#endif
- +static int x264_get_profile( const char *p_profile )
- +{
- + if( !p_profile )
- + return 0;
- + else if( !strcasecmp( p_profile, "baseline" ) )
- + return PROFILE_BASELINE;
- + else if( !strcasecmp( p_profile, "main" ) )
- + return PROFILE_MAIN;
- + else if( !strcasecmp( p_profile, "high" ) )
- + return PROFILE_HIGH;
- + else if( !strcasecmp( p_profile, "high10" ) )
- + return PROFILE_HIGH10;
- + return 0;
- +}
- - if( !strcasecmp( profile, "baseline" ) )
- +static int x264_param_apply_profile_internal( x264_param_t *param, int profile )
- +{
- + if( profile == PROFILE_BASELINE )
- {
- param->analyse.b_transform_8x8 = 0;
- param->b_cabac = 0;
- @@ -456,12 +488,12 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
- return -1;
- }
- }
- - else if( !strcasecmp( profile, "main" ) )
- + else if( profile == PROFILE_MAIN )
- {
- param->analyse.b_transform_8x8 = 0;
- param->i_cqm_preset = X264_CQM_FLAT;
- }
- - else if( !strcasecmp( profile, "high" ) || !strcasecmp( profile, "high10" ) )
- + else if( profile >= PROFILE_HIGH )
- {
- /* Default */
- }
- @@ -479,6 +511,209 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
- return 0;
- }
- +int x264_param_apply_profile( x264_param_t *param, const char *profile )
- +{
- + if( !profile )
- + return 0;
- +
- +#if BIT_DEPTH > 8
- + if( x264_get_profile( profile ) <= PROFILE_HIGH )
- + {
- + x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d.\n", profile, BIT_DEPTH );
- + return -1;
- + }
- +#endif
- +
- + return x264_param_apply_profile_internal( param, x264_get_profile( profile ) );
- +}
- +
- +static int x264_param_apply_level_internal( x264_param_t *param, int profile, x264_param_compat_t *compat )
- +{
- + int level_idc = param->i_level_idc;
- + if( level_idc == X264_LEVEL_IDC_AUTO )
- + return 0;
- +
- + int prof = BIT_DEPTH == 8 ? PROFILE_HIGH : PROFILE_HIGH10;
- +
- + if( profile )
- + {
- +#if BIT_DEPTH > 8
- + if( profile < PROFILE_HIGH10 )
- + {
- + x264_log( NULL, X264_LOG_ERROR, "specified profile too low for high bit depth\n" );
- + return -1;
- + }
- +#endif
- + prof = profile;
- + }
- +
- + const x264_level_t *l = x264_get_level( level_idc );
- + if( !l )
- + {
- + x264_log( NULL, X264_LOG_ERROR, "invalid level_idc: %d\n", level_idc );
- + return -1;
- + }
- + x264_calculate_resolution( l, param->i_width, param->i_height,
- + (double)param->i_fps_num / (double)param->i_fps_den,
- + param->b_interlaced || param->b_fake_interlaced, compat );
- +
- + char level_name[5];
- + snprintf( level_name, sizeof(level_name), "%d.%d", level_idc/10, level_idc%10 );
- + if( level_idc == 9 )
- + strcpy( level_name, "1b" );
- + int cbp_factor = prof == PROFILE_HIGH10 ? 12 :
- + prof == PROFILE_HIGH ? 5 : 4;
- + int mb_size = 384*BIT_DEPTH/8;
- + int mbs;
- + mbs = compat ? ((compat->i_width+15)/16) * ((compat->i_height+15)/16) :
- + ((param->i_width +15)/16) * ((param->i_height +15)/16);
- + while( 1 )
- + {
- + int num_reorder_frames = param->i_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0;
- + int max_dec_frame_buffering = X264_MIN(X264_REF_MAX, X264_MAX4(param->i_frame_reference, 1 + num_reorder_frames,
- + param->i_bframe_pyramid ? 4 : 1, param->i_dpb_size));
- + int dpb = max_dec_frame_buffering * mbs * mb_size;
- +
- + if( dpb <= l->dpb )
- + break;
- +
- + if( max_dec_frame_buffering == 4 && param->i_bframe_pyramid )
- + param->i_bframe_pyramid = 0;
- + else if( max_dec_frame_buffering == 2 && param->i_bframe )
- + param->i_bframe = 0;
- + else if( max_dec_frame_buffering == 1 )
- + {
- + x264_log( NULL, X264_LOG_WARNING, "Impossible DPB size %d required by level %s. Lowest\n", l->dpb, level_name );
- + x264_log( NULL, X264_LOG_WARNING, "possible is %d; try a higher level or lower resolution.\n", dpb );
- + return 0;
- + }
- + else if( param->i_dpb_size > param->i_frame_reference )
- + param->i_dpb_size--;
- + else
- + param->i_frame_reference--;
- + }
- +
- +#define LIMIT( name, limit, val ) \
- + if( (val) > (limit) || (val) <= 0 ) \
- + val = limit;
- +
- + LIMIT( "VBV bitrate", l->bitrate * cbp_factor / 4, param->rc.i_vbv_max_bitrate );
- + LIMIT( "VBV buffer", l->cpb * cbp_factor / 4, param->rc.i_vbv_buffer_size );
- + LIMIT( "MV range", l->mv_range, param->analyse.i_mv_range );
- + return 0;
- +}
- +
- +int x264_param_apply_level( x264_param_t *param, const char *profile, x264_param_compat_t *compat )
- +{
- + return x264_param_apply_level_internal( param, x264_get_profile( profile ), compat );
- +}
- +
- +typedef struct
- +{
- + char *name;
- + int i_screen_width;
- + int i_screen_height;
- + int i_level_idc;
- + int i_profile;
- +} x264_device_t;
- +
- +static const x264_device_t x264_devices[] =
- +{
- + {"ipad", 1024, 768, 31, PROFILE_HIGH },
- + {"iphone", 480, 320, 30, PROFILE_BASELINE},
- + {"iphone4", 960, 640, 31, PROFILE_MAIN },
- + {"ipod", 320, 240, 30, PROFILE_BASELINE},
- + {"n900", 800, 480, 30, PROFILE_BASELINE},
- + {"n8", 640, 360, 31, PROFILE_HIGH },
- + {"ps3", 1920, 1080, 41, PROFILE_HIGH },
- + {"psp", 480, 272, 30, PROFILE_MAIN },
- + {"xbox360", 1920, 1080, 41, PROFILE_HIGH },
- + {"wdtv", 1920, 1080, 41, PROFILE_HIGH },
- + {"test", 128, 96, 10, PROFILE_BASELINE}
- +};
- +
- +static const x264_device_t *x264_get_device( const char *device )
- +{
- + for( int i = 0; i < sizeof(x264_devices) / sizeof(x264_device_t); i++ )
- + if( !strcasecmp( device, x264_devices[i].name ) )
- + return x264_devices+i;
- + return NULL;
- +}
- +
- +/* Returns 0 if successful.
- + * Failure status non-existent as only bluray would generate conflicts. */
- +static int x264_param_apply_device_restrictions( x264_param_t *param, const char *device )
- +{
- + if( !strcasecmp( device, "psp" ) )
- + {
- + if( param->i_frame_reference > 3 )
- + {
- + param->i_frame_reference = 3;
- + x264_log( NULL, X264_LOG_WARNING, "Reference frames set to 3\n" );
- + }
- + if( param->i_bframe_pyramid > 0 )
- + {
- + param->i_bframe_pyramid = 0;
- + x264_log( NULL, X264_LOG_WARNING, "B-Pyramid disabled\n" );
- + }
- + }
- + else if( !strcasecmp( device, "n8" ) )
- + {
- + if( param->i_frame_reference > 6 )
- + {
- + param->i_frame_reference = 6;
- + x264_log( NULL, X264_LOG_WARNING, "Reference frames set to 6\n" );
- + }
- + }
- + return 0;
- +}
- +
- +int x264_param_apply_device( x264_param_t *param, const char *device, x264_param_compat_t *compat )
- +{
- + if( !device )
- + return -1;
- + char *tmp = x264_malloc( strlen( device ) + 1 );
- + if( !tmp )
- + return -1;
- + strcpy( tmp, device );
- + char *s = strtok( tmp, DELIMETERS );
- + int profile = INT_MAX;
- + while( s )
- + {
- + const x264_device_t *device_t = x264_get_device( s );
- + if( !device_t )
- + {
- + x264_log( NULL, X264_LOG_WARNING, "invalid device: %s\n", s );
- + x264_free( tmp );
- + return -1;
- + }
- +#if BIT_DEPTH > 8
- + if( device_t->i_profile < PROFILE_HIGH10 )
- + {
- + x264_log( NULL, X264_LOG_ERROR, "%s does not support high bit depth\n", s );
- + x264_free( tmp );
- + return -1;
- + }
- +#endif
- + if( param->i_level_idc > device_t->i_level_idc || //Won't work right if one
- + param->i_level_idc == X264_LEVEL_IDC_AUTO) //of the devices is a 1b
- + param->i_level_idc = device_t->i_level_idc;
- + if( profile > device_t->i_profile )
- + profile = device_t->i_profile;
- +
- + if( x264_param_apply_device_restrictions( param, device ) < 0 )
- + {
- + x264_log( NULL, X264_LOG_ERROR, "failed to apply extra restrictions of %s\n", s );
- + x264_free( tmp );
- + return -1;
- + }
- + s = strtok( NULL, DELIMETERS );
- + }
- + x264_free( tmp );
- + return -( x264_param_apply_profile_internal( param, profile ) < 0 ||
- + x264_param_apply_level_internal( param, profile, compat ) < 0 );
- +}
- +
- static int parse_enum( const char *arg, const char * const *names, int *dst )
- {
- for( int i = 0; names[i]; i++ )
- diff --git a/encoder/encoder.c b/encoder/encoder.c
- index b5f1d1d..edc58aa 100644
- --- a/encoder/encoder.c
- +++ b/encoder/encoder.c
- @@ -744,7 +744,7 @@ static int x264_validate_parameters( x264_t *h )
- {
- const x264_level_t *l = x264_levels;
- - if( h->param.i_level_idc < 0 )
- + if( h->param.i_level_idc == X264_LEVEL_IDC_AUTO )
- {
- int maxrate_bak = h->param.rc.i_vbv_max_bitrate;
- if( h->param.rc.i_rc_method == X264_RC_ABR && h->param.rc.i_vbv_buffer_size <= 0 )
- diff --git a/encoder/set.c b/encoder/set.c
- index 622d16f..e9f7478 100644
- --- a/encoder/set.c
- +++ b/encoder/set.c
- @@ -115,6 +115,17 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
- else
- sps->i_profile_idc = PROFILE_BASELINE;
- + /* Hack: if the user specifies a High-compatible VBV, but not a Main-compatible one,
- + * switch to High profile. Prevents spurious errors on the first pass. */
- + const x264_level_t *l = x264_get_level( param->i_level_idc );
- + if( l && sps->i_profile_idc <= PROFILE_MAIN &&
- + l->bitrate * 5/4 >= param->rc.i_vbv_max_bitrate &&
- + l->cpb * 5/4 >= param->rc.i_vbv_buffer_size &&
- + (l->bitrate < param->rc.i_vbv_max_bitrate || l->cpb < param->rc.i_vbv_buffer_size) )
- + {
- + sps->i_profile_idc = PROFILE_HIGH;
- + }
- +
- sps->b_constraint_set0 = sps->i_profile_idc == PROFILE_BASELINE;
- /* x264 doesn't support the features that are in Baseline and not in Main,
- * namely arbitrary_slice_order and slice_groups. */
- @@ -711,6 +722,14 @@ const x264_level_t x264_levels[] =
- { 0 }
- };
- +const x264_level_t *x264_get_level( int level_idc )
- +{
- + const x264_level_t *l = x264_levels;
- + while( l->level_idc && l->level_idc != level_idc )
- + l++;
- + return l->level_idc ? l : NULL;
- +}
- +
- #define ERROR(...)\
- {\
- if( verbose )\
- @@ -721,8 +740,9 @@ const x264_level_t x264_levels[] =
- int x264_validate_levels( x264_t *h, int verbose )
- {
- int ret = 0;
- - int mbs = h->sps->i_mb_width * h->sps->i_mb_height;
- - int dpb = mbs * 384 * h->sps->vui.i_max_dec_frame_buffering;
- + float mbs = (float)h->param.i_width * (float)h->param.i_height / 256;
- + int mb_size = 384*BIT_DEPTH/8;
- + int dpb = mbs * mb_size * h->sps->vui.i_max_dec_frame_buffering;
- int cbp_factor = h->sps->i_profile_idc==PROFILE_HIGH10 ? 12 :
- h->sps->i_profile_idc==PROFILE_HIGH ? 5 : 4;
- @@ -737,7 +757,7 @@ int x264_validate_levels( x264_t *h, int verbose )
- h->sps->i_mb_width, h->sps->i_mb_height, l->frame_size );
- if( dpb > l->dpb )
- ERROR( "DPB size (%d frames, %d bytes) > level limit (%d frames, %d bytes)\n",
- - h->sps->vui.i_max_dec_frame_buffering, dpb, (int)(l->dpb / (384*mbs)), l->dpb );
- + h->sps->vui.i_max_dec_frame_buffering, dpb, (int)(l->dpb / (mb_size*mbs)), l->dpb );
- #define CHECK( name, limit, val ) \
- if( (val) > (limit) ) \
- diff --git a/encoder/set.h b/encoder/set.h
- index 83c1bd9..d69b4cb 100644
- --- a/encoder/set.h
- +++ b/encoder/set.h
- @@ -33,6 +33,7 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
- void x264_pps_write( bs_t *s, x264_pps_t *pps );
- void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt );
- int x264_sei_version_write( x264_t *h, bs_t *s );
- +const x264_level_t *x264_get_level( int level_idc );
- int x264_validate_levels( x264_t *h, int verbose );
- void x264_sei_buffering_period_write( x264_t *h, bs_t *s );
- void x264_sei_pic_timing_write( x264_t *h, bs_t *s );
- diff --git a/x264.c b/x264.c
- index 626617b..a4d1b20 100644
- --- a/x264.c
- +++ b/x264.c
- @@ -400,6 +400,11 @@ static void help( x264_param_t *defaults, int longhelp )
- H0( "\n" );
- H0( "Presets:\n" );
- H0( "\n" );
- + H0( " --device Force the limits of an H.264-capable device\n"
- + " Overrides all settings.\n"
- + " Devices currently supported:\n"
- + " ipad, iphone, iphone4, ipod, n8\n"
- + " n900, psp, ps3, xbox360, wdtv\n" );
- H0( " --profile Force the limits of an H.264 profile\n"
- " Overrides all settings.\n" );
- H2( " - baseline:\n"
- @@ -787,7 +792,8 @@ enum
- OPT_INPUT_RES,
- OPT_INPUT_CSP,
- OPT_INPUT_DEPTH,
- - OPT_DTS_COMPRESSION
- + OPT_DTS_COMPRESSION,
- + OPT_DEVICE
- } OptionsOPT;
- static char short_options[] = "8A:B:b:f:hI:i:m:o:p:q:r:t:Vvw";
- @@ -798,6 +804,7 @@ static struct option long_options[] =
- { "fullhelp", no_argument, NULL, OPT_FULLHELP },
- { "version", no_argument, NULL, 'V' },
- { "profile", required_argument, NULL, OPT_PROFILE },
- + { "device", required_argument, NULL, OPT_DEVICE },
- { "preset", required_argument, NULL, OPT_PRESET },
- { "tune", required_argument, NULL, OPT_TUNE },
- { "slow-firstpass", no_argument, NULL, OPT_SLOWFIRSTPASS },
- @@ -1088,29 +1095,6 @@ static int init_vid_filters( char *sequence, hnd_t *handle, video_info_t *info,
- p += X264_MIN( tok_len+1, p_len );
- }
- - /* force end result resolution */
- - if( !param->i_width && !param->i_height )
- - {
- - param->i_height = info->height;
- - param->i_width = info->width;
- - }
- - /* if the current csp is supported by libx264, have libx264 use this csp.
- - * otherwise change the csp to I420 and have libx264 use this.
- - * when more colorspaces are supported, this decision will need to be updated. */
- - int csp = info->csp & X264_CSP_MASK;
- - if( csp > X264_CSP_NONE && csp < X264_CSP_MAX )
- - param->i_csp = info->csp;
- - else
- - param->i_csp = X264_CSP_I420 | ( info->csp & X264_CSP_HIGH_DEPTH );
- - if( x264_init_vid_filter( "resize", handle, &filter, info, param, NULL ) )
- - return -1;
- -
- - char args[20];
- - sprintf( args, "bit_depth=%d", x264_bit_depth );
- -
- - if( x264_init_vid_filter( "depth", handle, &filter, info, param, args ) )
- - return -1;
- -
- return 0;
- }
- @@ -1145,6 +1129,7 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
- char *tcfile_name = NULL;
- x264_param_t defaults;
- char *profile = NULL;
- + char *devices = NULL;
- char *vid_filters = NULL;
- int b_thread_input = 0;
- int b_turbo = 1;
- @@ -1314,6 +1299,9 @@ static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
- case OPT_DTS_COMPRESSION:
- output_opt.use_dts_compress = 1;
- break;
- + case OPT_DEVICE:
- + devices = optarg;
- + break;
- default:
- generic_option:
- {
- @@ -1348,10 +1336,6 @@ generic_option:
- if( b_turbo )
- x264_param_apply_fastfirstpass( param );
- - /* Apply profile restrictions. */
- - if( x264_param_apply_profile( param, profile ) < 0 )
- - return -1;
- -
- /* Get the file name */
- FAIL_IF_ERROR( optind > argc - 1 || !output_filename, "No %s file. Run x264 --help for a list of options.\n",
- optind > argc - 1 ? "input" : "output" )
- @@ -1460,6 +1444,8 @@ generic_option:
- param->i_timebase_den = info.timebase_den;
- param->vui.i_sar_width = info.sar_width;
- param->vui.i_sar_height = info.sar_height;
- + param->i_height = info->height;
- + param->i_width = info->width;
- info.num_frames = X264_MAX( info.num_frames - opt->i_seek, 0 );
- if( (!info.num_frames || param->i_frame_total < info.num_frames)
- @@ -1475,25 +1461,39 @@ generic_option:
- param->b_interlaced = 1;
- param->b_tff = !!info.tff;
- }
- + x264_param_compat_t compat = {0};
- + if( x264_param_apply_profile( param, profile ) < 0 )
- + return -1;
- - /* Automatically reduce reference frame count to match the user's target level
- - * if the user didn't explicitly set a reference frame count. */
- - if( !b_user_ref )
- + if( devices )
- {
- - int mbs = (((param->i_width)+15)>>4) * (((param->i_height)+15)>>4);
- - for( int i = 0; x264_levels[i].level_idc != 0; i++ )
- - if( param->i_level_idc == x264_levels[i].level_idc )
- - {
- - while( mbs * 384 * param->i_frame_reference > x264_levels[i].dpb &&
- - param->i_frame_reference > 1 )
- - {
- - param->i_frame_reference--;
- - }
- - break;
- - }
- + if( x264_param_apply_device( param, devices, &compat ) < 0 )
- + return -1;
- }
- + else if( x264_param_apply_level( param, profile, &compat ) < 0 )
- + return -1;
- + if( compat.i_width != 0 && compat.i_height != 0 )
- + {
- + param->i_width = compat.i_width;
- + param->i_height = compat.i_height;
- + }
- + /* if the current csp is supported by libx264, have libx264 use this csp.
- + * otherwise change the csp to I420 and have libx264 use this.
- + * when more colorspaces are supported, this decision will need to be updated. */
- + int csp = info.csp & X264_CSP_MASK;
- + if( csp > X264_CSP_NONE && csp < X264_CSP_MAX )
- + param->i_csp = info.csp;
- + else
- + param->i_csp = X264_CSP_I420 | ( info.csp & X264_CSP_HIGH_DEPTH );
- + if( x264_init_vid_filter( "resize", &opt->hin, &filter, &info, param, NULL ) )
- + return -1;
- + char args[20];
- + sprintf( args, "bit_depth=%d", x264_bit_depth );
- +
- + if( x264_init_vid_filter( "depth", &opt->hin, &filter, &info, param, args ) )
- + return -1;
- return 0;
- }
- diff --git a/x264.h b/x264.h
- index dbedd7e..31e593e 100644
- --- a/x264.h
- +++ b/x264.h
- @@ -41,7 +41,7 @@
- #include "x264_config.h"
- -#define X264_BUILD 112
- +#define X264_BUILD 113
- /* x264_t:
- * opaque handler for encoder */
- @@ -163,6 +163,7 @@ typedef struct
- #define X264_OPEN_GOP_NONE 0
- #define X264_OPEN_GOP_NORMAL 1
- #define X264_OPEN_GOP_BLURAY 2
- +#define X264_LEVEL_IDC_AUTO (-1)
- static const char * const x264_direct_pred_names[] = { "none", "spatial", "temporal", "auto", 0 };
- static const char * const x264_motion_est_names[] = { "dia", "hex", "umh", "esa", "tesa", 0 };
- @@ -474,6 +475,14 @@ typedef struct x264_param_t
- void x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal );
- +/* defines the parameters that should be changed by the calling application
- + * instead in x264_param_apply_device */
- +typedef struct
- +{
- + int i_width;
- + int i_height;
- +} x264_param_compat_t;
- +
- /****************************************************************************
- * H.264 level restriction information
- ****************************************************************************/
- @@ -529,6 +538,7 @@ int x264_param_parse( x264_param_t *, const char *name, const char *value );
- * 2) Custom user options (via param_parse or directly assigned variables)
- * 3) x264_param_apply_fastfirstpass
- * 4) x264_param_apply_profile
- + * 5) x264_param_apply_level or x264_param_apply_device
- *
- * Additionally, x264CLI does not apply step 3 if the preset chosen is "placebo"
- * or --slow-firstpass is set. */
- @@ -581,6 +591,44 @@ static const char * const x264_profile_names[] = { "baseline", "main", "high", "
- * returns 0 on success, negative on failure (e.g. invalid profile name). */
- int x264_param_apply_profile( x264_param_t *, const char *profile );
- +/* x264_param_apply_level:
- + * Applies the restrictions of the level set in the passed x264_param_t to
- + * the passed x264_param_t, using the passed profile.
- + * Uses the level_idc values from x264_levels[].
- + *
- + * Also calculates resolution returned in a x264_param_compat_t to be adjusted
- + * by the calling application.
- + *
- + * Does nothing (but is considered success) if the level is set to
- + * X264_LEVEL_IDC_AUTO (default).
- + *
- + * x264_param_apply_level does not check or modify parameters related
- + * to properties of the source video that may violate levels, e.g.
- + * resolution, framerate, interlacing. x264_param_apply_level is not
- + * intended as a compatibility check; this is done inside x264 at the
- + * start of encoding.
- + *
- + * i_width and i_height must be initialized for x264_param_apply_level
- + * to work properly.
- + *
- + * returns 0 on success, negative on failure (e.g. invalid level). */
- +int x264_param_apply_level( x264_param_t *, const char *profile, x264_param_compat_t *compat );
- +
- +/* x264_param_apply_devices:
- + * Applies the constraints of device to the passed x264_param_t. Uses the list
- + * of x264_device_t defined in common/common.c.
- + * Currently available devices for x264_param_apply_device are: */
- +static const char * const x264_device_names[] = { "ipad", "iphone", "iphone4", "ipod", "n8", "n900", "psp", "ps3", "xbox360", "wdtv", 0 };
- +
- +/* x264_param_apply_devices does not modify parameters supposed to be adjusted
- + * by the calling application. An x264_param_compat_t is filled by the function
- + * defining what unchangeable parameters need to be changed to.
- + *
- + * i_width and i_height must be initialized for x264_param_apply_devices to
- + * work properly.
- + * Returns 0 if successful or -1 if the device couldnot be found. */
- +int x264_param_apply_device( x264_param_t *param, const char *device, x264_param_compat_t *compat );
- +
- /****************************************************************************
- * Picture structures and functions
- ****************************************************************************/
- --
- 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement