+ // Translate these standard mlt consumer properties to ffmpeg
+ if ( mlt_properties_get_int( properties, "progressive" ) == 0 &&
+ mlt_properties_get_int( properties, "deinterlace" ) == 0 )
+ {
+ if ( mlt_properties_get_int( properties, "ildct" ) )
+ c->flags |= CODEC_FLAG_INTERLACED_DCT;
+ if ( mlt_properties_get_int( properties, "ilme" ) )
+ c->flags |= CODEC_FLAG_INTERLACED_ME;
+ }
+
+ // parse the ratecontrol override string
+ int i;
+ char *rc_override = mlt_properties_get( properties, "rc_override" );
+ for ( i = 0; rc_override; i++ )
+ {
+ int start, end, q;
+ int e = sscanf( rc_override, "%d,%d,%d", &start, &end, &q );
+ if ( e != 3 )
+ fprintf( stderr, "%s: Error parsing rc_override\n", __FILE__ );
+ c->rc_override = av_realloc( c->rc_override, sizeof( RcOverride ) * ( i + 1 ) );
+ c->rc_override[i].start_frame = start;
+ c->rc_override[i].end_frame = end;
+ if ( q > 0 )
+ {
+ c->rc_override[i].qscale = q;
+ c->rc_override[i].quality_factor = 1.0;
+ }
+ else
+ {
+ c->rc_override[i].qscale = 0;
+ c->rc_override[i].quality_factor = -q / 100.0;
+ }
+ rc_override = strchr( rc_override, '/' );
+ if ( rc_override )
+ rc_override++;
+ }
+ c->rc_override_count = i;
+ if ( !c->rc_initial_buffer_occupancy )
+ c->rc_initial_buffer_occupancy = c->rc_buffer_size * 3/4;
+ c->intra_dc_precision = mlt_properties_get_int( properties, "dc" ) - 8;
+
+ // Setup dual-pass
+ i = mlt_properties_get_int( properties, "pass" );
+ if ( i == 1 )
+ c->flags |= CODEC_FLAG_PASS1;
+ else if ( i == 2 )
+ c->flags |= CODEC_FLAG_PASS2;
+ if ( codec_id != CODEC_ID_H264 && ( c->flags & ( CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2 ) ) )
+ {
+ char logfilename[1024];
+ FILE *f;
+ int size;
+ char *logbuffer;
+
+ snprintf( logfilename, sizeof(logfilename), "%s_2pass.log",
+ mlt_properties_get( properties, "passlogfile" ) ? mlt_properties_get( properties, "passlogfile" ) : mlt_properties_get( properties, "target" ) );
+ if ( c->flags & CODEC_FLAG_PASS1 )
+ {
+ f = fopen( logfilename, "w" );
+ if ( !f )
+ perror( logfilename );
+ else
+ mlt_properties_set_data( properties, "_logfile", f, 0, ( mlt_destructor )fclose, NULL );
+ }
+ else
+ {
+ /* read the log file */
+ f = fopen( logfilename, "r" );
+ if ( !f )
+ {
+ perror(logfilename);
+ }
+ else
+ {
+ mlt_properties_set( properties, "_logfilename", logfilename );
+ fseek( f, 0, SEEK_END );
+ size = ftell( f );
+ fseek( f, 0, SEEK_SET );
+ logbuffer = av_malloc( size + 1 );
+ if ( !logbuffer )
+ fprintf( stderr, "%s: Could not allocate log buffer\n", __FILE__ );
+ else
+ {
+ size = fread( logbuffer, 1, size, f );
+ fclose( f );
+ logbuffer[size] = '\0';
+ c->stats_in = logbuffer;
+ mlt_properties_set_data( properties, "_logbuffer", logbuffer, 0, ( mlt_destructor )av_free, NULL );
+ }
+ }
+ }
+ }
+ }