Index: libmpcodecs/ve_x264.c =================================================================== --- libmpcodecs/ve_x264.c (Revision 31235) +++ libmpcodecs/ve_x264.c (Arbeitskopie) @@ -56,7 +56,6 @@ } h264_module_t; extern char* passtmpfile; -static int turbo = 0; static x264_param_t param; static int parse_error = 0; @@ -65,19 +64,68 @@ void x264enc_set_param(const m_option_t* opt, char* arg) { + char* profile = NULL; + char* tune = NULL; + char* preset = NULL; + void* copy; + char* arg_copy; + int noturbo = 0; static int initted = 0; - if(!initted) { - x264_param_default(¶m); - x264_param_parse(¶m, "psnr", "no"); - x264_param_parse(¶m, "ssim", "no"); + + if(initted) + return; initted = 1; - } if(!arg) { parse_error = 1; + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: no options provided\n"); + return; + } + + /* step 1 - look for and set default presets */ + /* we need a copy, because parsing user options overwrites the list */ + copy = malloc( strlen(arg)+1 ); + if(copy != NULL) + arg_copy = strcpy( copy, arg); + else { + parse_error = 1; return; } + while(*arg_copy) { + char *name = arg_copy; + char *value; + + arg_copy += strcspn(arg_copy, ":"); + if(*arg_copy) { + *arg_copy = 0; + arg_copy++; + } + + value = strchr( name, '=' ); + if(value) { + *value = 0; + value++; + } + + if( strcmp(name, "preset") && strcmp(name, "tune") ) + continue; + + if( !strcmp(name, "preset") ) + preset = value; + + if( !strcmp(name, "tune") ) + tune = value; + } + + // "medium" enables one to supply tune without explicit preset + if( x264_param_default_preset(¶m, preset ? preset : "medium" , tune) ) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: invalid preset or tune value\n"); + parse_error = 1; + } + free(copy); + + /* step 2 - user options */ while(*arg) { char *name = arg; char *value; @@ -95,8 +143,17 @@ value++; } - if(!strcmp(name, "turbo")) { - turbo = value ? atoi(value) : 1; + if(!strcmp(name, "noturbo")) { + noturbo = 1; + continue; + } + + if(!strcmp(name, "profile")) { + profile = value ? value : 0; + continue; + } + + if( !strcmp(name, "preset") || !strcmp(name, "tune") ) { continue; } @@ -112,27 +169,14 @@ parse_error |= ret; } - if(param.rc.b_stat_write && !param.rc.b_stat_read) { - /* Adjust or disable some flags to gain speed in the first pass */ - if(turbo == 1) - { - param.i_frame_reference = ( param.i_frame_reference + 1 ) >> 1; - param.analyse.i_subpel_refine = FFMAX( FFMIN( 3, param.analyse.i_subpel_refine - 1 ), 1 ); - param.analyse.inter &= ( ~X264_ANALYSE_PSUB8x8 ); - param.analyse.inter &= ( ~X264_ANALYSE_BSUB16x16 ); - param.analyse.i_trellis = 0; - } - else if(turbo >= 2) - { - param.i_frame_reference = 1; - param.analyse.i_subpel_refine = 1; - param.analyse.i_me_method = X264_ME_DIA; - param.analyse.inter = 0; - param.analyse.b_transform_8x8 = 0; - param.analyse.b_weighted_bipred = 0; - param.analyse.i_trellis = 0; - } - } + /* step 3 - turbo override*/ + if(!noturbo) + x264_param_apply_fastfirstpass(¶m); + + /* step 4 - profile enforcement */ + if( x264_param_apply_profile(¶m, profile) ) + parse_error=1; + } static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) { Index: DOCS/man/en/mplayer.1 =================================================================== --- DOCS/man/en/mplayer.1 (Revision 31235) +++ DOCS/man/en/mplayer.1 (Arbeitskopie) @@ -10066,7 +10066,7 @@ For example, MPEG at QP=2 is equivalent to H.264 at QP=18. . .TP -.B crf=<1.0\-50.0> +.B crf=<0.0\-51.0> Enables constant quality mode, and selects the quality. The scale is similar to QP. Like the bitrate-based modes, this allows each frame to use a @@ -10111,31 +10111,64 @@ .REss . .TP -.B turbo=<0\-2> -Fast first pass mode. -During the first pass of a two or more pass encode it is possible to gain -speed by disabling some options with negligible or even no impact on the -final pass output quality. +.B preset= +Make use of built-in x264 presets. Possible values and a rough speedup +comparison are: +. .PD 0 .RSs -.IPs 0 -disabled (default) -.IPs 1 -Reduce subq, frameref and disable some inter-macroblock partition analysis -modes. -.IPs 2 -Reduce subq and frameref to 1, use a diamond ME search and disable all -partition analysis modes. -.RE -.RS -Level 1 can increase first pass speed up to 2x with no change in the global -PSNR of the final pass compared to a full quality first pass. +.IPs ultrafast +9x +.IPs superfast +4x +.IPs veryfast +2.5x +.IPs faster +1.5x +.IPs "fast\ " +1.2x +.IPs medium +1.0x [default] +.IPs "slow\ " +0.5x +.IPs slower +0.4x +.IPs veryslow +0.3x +.IPs placebo +0.1x (disables turbo) +.REss +. +.TP +.B tune= +The x264 preset system allows fine tuning depending on characteristics of your video content. +.PD 0 +.RSs +.IPs group1 +film, animation, grain, psy, psnr, ssim, stillimage +.br +(only one tune of this group can be used) +.IPs group2 +fastdecode, zerolatency .br -Level 2 can increase first pass speed up to 4x with about +/\- 0.05dB change -in the global PSNR of the final pass compared to a full quality first pass. +(can be used in conjunction with others) +. .REss . .TP +.B profile= +Enforces parameters to comply to the H.264 profiles. (downgrade options) +. +.TP +.B noturbo +When using multi-pass mode it is no longer necessary to specify the turbo mode +to gain speed by disabling some options with negligible or even no impact on +the final pass output quality. Use this option if you don't want these +enhancements. +.br +This option has no effect when the preset "placebo" is used. +. +.TP .B keyint= Sets maximum interval between IDR-frames (default: 250). Larger values save bits, thus improve quality, at the cost of seeking