- if( job->h264_level )
- {
- param.i_threads = 1;
- param.b_cabac = 0;
- param.i_level_idc = job->h264_level;
- hb_log( "encx264: encoding at level %i",
- param.i_level_idc );
- }
-
- /* Slightly faster with minimal quality lost */
- param.analyse.i_subpel_refine = 4;
-
- /* This section passes the string x264opts to libx264 for parsing into parameter names and values.
-
- The string is set up like this:
- option1=value1:option2=value 2
-
- So, you have to iterate through based on the colons, and then put the left side of the equals sign in "name"
- and the right side into "value." Then you hand those strings off to x264 for interpretation.
-
- This is all based on the universal x264 option handling Loren Merritt implemented in the Mplayer/Mencoder project.
- */
-
- char *x264opts = job->x264opts;
- if(x264opts != NULL && *x264opts != '\0')
- {
- while(*x264opts)
- {
- char *name = x264opts;
- char *value;
- int ret;
-
- x264opts += strcspn(x264opts, ":");
- if(*x264opts)
- {
- *x264opts = 0;
- x264opts++;
- }
-
- value = strchr( name, '=' );
- if(value)
- {
- *value = 0;
- value++;
- }
-
- /*
- 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 are using B-frames, and when they are, set the boolean job->areBframes as true.
- */
-
- if (!(strcmp(name, "bframes")))
- {
- if (atoi(value) > 0)
- {
- job->areBframes = 1;
- }
- }
-
- /* 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)
- 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 );
+ if( job->h264_level )
+ {
+ param.b_cabac = 0;
+ param.i_level_idc = job->h264_level;
+ hb_log( "encx264: encoding at level %i",
+ param.i_level_idc );
+ }
+
+ /*
+ This section passes the string x264opts to libx264 for parsing into
+ parameter names and values.
+
+ The string is set up like this:
+ option1=value1:option2=value 2
+
+ So, you have to iterate through based on the colons, and then put
+ the left side of the equals sign in "name" and the right side into
+ "value." Then you hand those strings off to x264 for interpretation.
+
+ This is all based on the universal x264 option handling Loren
+ Merritt implemented in the Mplayer/Mencoder project.
+ */
+
+ if( job->x264opts != NULL && *job->x264opts != '\0' )
+ {
+ 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++;
+ }
+
+ /* 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 );
+ }
+ 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 );