- ret = x264_param_parse(¶m, name, value);
-
- /* Let x264 sanity check the options for us*/
- if(ret == X264_PARAM_BAD_NAME)
- printf("x264 options: Unknown suboption %s\n", name);
- if(ret == X264_PARAM_BAD_VALUE)
- printf("x264 options: Bad argument %s=%s\n", name, value ? value : "(null)");
- }
- }
-
-
- if( job->pixel_ratio )
- {
- param.vui.i_sar_width = job->pixel_aspect_width;
- param.vui.i_sar_height = job->pixel_aspect_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 )
- {
- switch(job->crf)
- {
- case 1:
- /*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 );
- break;
-
- case 0:
- /*Constant QP*/
- param.rc.i_rc_method = X264_RC_CQP;
- param.rc.i_qp_constant = 51 - job->vquality * 51;
- hb_log( "encx264: encoding at constant QP %d",
- param.rc.i_qp_constant );
- break;
- }
- }
- else
- {
- /* Rate control */
- param.rc.i_rc_method = X264_RC_ABR;
- param.rc.i_bitrate = job->vbitrate;
- switch( job->pass )
- {
- case 1:
- param.rc.b_stat_write = 1;
- param.rc.psz_stat_out = pv->filename;
- break;
- case 2:
- param.rc.b_stat_read = 1;
- param.rc.psz_stat_in = pv->filename;
- break;
- }
- }
-
- hb_log( "encx264: opening libx264 (pass %d)", job->pass );
+ 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);
+ }
+
+ /* 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 )
+ {
+ switch( job->crf )
+ {
+ case 1:
+ /*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 );
+ break;
+
+ case 0:
+ /*Constant QP*/
+ param.rc.i_rc_method = X264_RC_CQP;
+ param.rc.i_qp_constant = 51 - job->vquality * 51;
+ hb_log( "encx264: encoding at constant QP %d",
+ param.rc.i_qp_constant );
+ break;
+ }
+ }
+ 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. */
+ switch( job->crf )
+ {
+ case 1:
+ /*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 );
+ break;
+
+ case 0:
+ /*Constant QP*/
+ param.rc.i_rc_method = X264_RC_CQP;
+ param.rc.i_qp_constant = job->vquality;
+ hb_log( "encx264: encoding at constant QP %d",
+ param.rc.i_qp_constant );
+ break;
+ }
+ }
+ else
+ {
+ /* Rate control */
+ param.rc.i_rc_method = X264_RC_ABR;
+ param.rc.i_bitrate = job->vbitrate;
+ switch( job->pass )
+ {
+ case 1:
+ param.rc.b_stat_write = 1;
+ param.rc.psz_stat_out = pv->filename;
+ break;
+ case 2:
+ param.rc.b_stat_read = 1;
+ param.rc.psz_stat_in = pv->filename;
+ break;
+ }
+ }
+
+ hb_deep_log( 2, "encx264: opening libx264 (pass %d)", job->pass );