+ param.i_level_idc = job->h264_level;
+ hb_log( "encx264: encoding at level %i",
+ param.i_level_idc );
+ }
+
+ /* B-frames are on by default.*/
+ job->areBframes = 1;
+
+ /*
+ 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++;
+ }
+
+ /*
+ 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.
+ */
+ if( !( strcmp( name, "bframes" ) ) )
+ {
+ if( atoi( value ) == 0 )
+ {
+ job->areBframes = 0;
+ }
+ }
+
+ /* Note b-pyramid here, so the initial delay can be doubled */
+ if( !( strcmp( name, "b-pyramid" ) ) )
+ {
+ if( value != NULL )
+ {
+ if( atoi( value ) > 0 )
+ {
+ job->areBframes = 2;
+ }
+ }
+ else
+ {
+ job->areBframes = 2;
+ }
+ 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);
+ }
+
+ /* 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 );