+ char *x264opts, *x264opts_start;
+
+ x264opts = x264opts_start = strdup(job->x264opts);
+
+ while( x264opts_start && *x264opts )
+ {
+ char *name = x264opts;
+ char *value;
+ int ret;
+
+ x264opts += strcspn( x264opts, ":" );
+ if( *x264opts )
+ {
+ *x264opts = 0;
+ x264opts++;
+ }
+
+ value = strchr( name, '=' );
+ if( value )
+ {
+ *value = 0;
+ value++;
+ }
+
+ if( !( strcmp( name, "b-pyramid" ) ) )
+ {
+ if( value == NULL || !strcmp( value, "1" ) )
+ {
+ value = "normal";
+ }
+ else if( !strcmp( value, "0" ) )
+ {
+ value = "none";
+ }
+ }
+
+ /* Here's where the strings are passed to libx264 for parsing. */
+ ret = x264_param_parse( ¶m, name, value );
+
+ /* Let x264 sanity check the options for us*/
+ if( ret == X264_PARAM_BAD_NAME )
+ hb_log( "x264 options: Unknown suboption %s", name );
+ if( ret == X264_PARAM_BAD_VALUE )
+ hb_log( "x264 options: Bad argument %s=%s", name, value ? value : "(null)" );
+ }
+ free(x264opts_start);
+ }
+
+ /* B-frames are on by default.*/
+ job->areBframes = 1;
+
+ if( param.i_bframe && param.i_bframe_pyramid )
+ {
+ /* Note b-pyramid here, so the initial delay can be doubled */
+ job->areBframes = 2;
+ }
+ else if( !param.i_bframe )
+ {
+ /*
+ When B-frames are enabled, the max frame count increments
+ by 1 (regardless of the number of B-frames). If you don't
+ change the duration of the video track when you mux, libmp4
+ barfs. So, check if the x264opts aren't using B-frames, and
+ when they aren't, set the boolean job->areBframes as false.
+ */
+ job->areBframes = 0;
+ }
+
+ if( param.i_keyint_min != X264_KEYINT_MIN_AUTO || param.i_keyint_max != 250 )
+ hb_log("encx264: min-keyint: %i, keyint: %i", param.i_keyint_min == X264_KEYINT_MIN_AUTO ? param.i_keyint_max / 10 : param.i_keyint_min,
+ param.i_keyint_max);
+
+ /* set up the VUI color model & gamma to match what the COLR atom
+ * set in muxmp4.c says. See libhb/muxmp4.c for notes. */
+ if( job->color_matrix == 1 )
+ {
+ // ITU BT.601 DVD or SD TV content
+ param.vui.i_colorprim = 6;
+ param.vui.i_transfer = 1;
+ param.vui.i_colmatrix = 6;
+ }
+ else if( job->color_matrix == 2 )
+ {
+ // ITU BT.709 HD content
+ param.vui.i_colorprim = 1;
+ param.vui.i_transfer = 1;
+ param.vui.i_colmatrix = 1;
+ }
+ else if ( job->title->width >= 1280 || job->title->height >= 720 )
+ {
+ // we guess that 720p or above is ITU BT.709 HD content
+ param.vui.i_colorprim = 1;
+ param.vui.i_transfer = 1;
+ param.vui.i_colmatrix = 1;
+ }
+ else
+ {
+ // ITU BT.601 DVD or SD TV content
+ param.vui.i_colorprim = 6;
+ param.vui.i_transfer = 1;
+ param.vui.i_colmatrix = 6;
+ }
+
+ if( job->anamorphic.mode )
+ {
+ param.vui.i_sar_width = job->anamorphic.par_width;
+ param.vui.i_sar_height = job->anamorphic.par_height;
+
+ hb_log( "encx264: encoding with stored aspect %d/%d",
+ param.vui.i_sar_width, param.vui.i_sar_height );
+ }
+
+
+ if( job->vquality > 0.0 && job->vquality < 1.0 )
+ {
+ /*Constant RF*/
+ param.rc.i_rc_method = X264_RC_CRF;
+ param.rc.f_rf_constant = 51 - job->vquality * 51;
+ hb_log( "encx264: Encoding at constant RF %f", param.rc.f_rf_constant );
+ }
+ else if( job->vquality == 0 || job->vquality >= 1.0 )
+ {
+ /* Use the vquality as a raw RF or QP
+ instead of treating it like a percentage. */
+ /*Constant RF*/
+ param.rc.i_rc_method = X264_RC_CRF;
+ param.rc.f_rf_constant = job->vquality;
+ hb_log( "encx264: Encoding at constant RF %f", param.rc.f_rf_constant );